从 asp.net 中的列表中提取特定数据
Extract particular data from list in asp.net
在我的医生中 table 我有 3 列,分别命名为开始时间、结束时间和持续时间。
我的计划是,当用户输入城市名称并选择医生专业并单击搜索按钮时,将显示 table 符合该条件的医生。包括开始时间、结束时间和一个时间段。
如果医生的开始时间为上午 8 点,结束时间为晚上 8 点,每位患者的平均持续时间为 30 分钟,则将创建 24 个槽位。
除了我不知道如何将所有内容与时间段下拉菜单结合起来(当然不会显示特定日期的已预订时间)外,我的大部分工作都在进行中。
现在我已经在 var details 中有了医生的详细信息(包括开始和结束时间)所以我应该能够从那里提取开始时间和结束时间?
并将这两条数据发送到slots.cs class用于创建插槽?
这是我的操作方法:
public ActionResult Dashboard(string city, string specialization)
{
// ?City=Dhaka&specialization=Medicine&date=2020-11-29&btn_find=Find ---> example query string
string city_local = Request.Params["city"];
string specialization_local = Request.Params["specialization"];
var details = db.doctors
.Where(x => x.city.Equals(city_local) &&
x.specialization.Equals(specialization_local)).ToList(); -->this guy right here
return View(details);
}
这是我的观点:
<table class="table table table-borderless table-hover text-center">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Start Time</th>
<th>End Time</th>
<th>Available Slot</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@if(Model.Count() == 0)
{
<tr>
<td>No Records Found. Try Again</td>
</tr>
}
else
{
foreach(var data in Model)
{
<tr>
<td>@data.doctor_id</td>
<td>@data.doctor_fname</td>
<td>@data.start_time</td>
<td>@data.end_time</td>
<td>A dropdown of slots needed</td>
<td><a href="#">Book</a></td>
</tr>
}
}
</tbody>
</table>
最后是我的 slots.cs,它应该可以用于创建时隙:
public class slot
{
public TimeSpan StartTime { get; set; }
public TimeSpan Duration { get; set; }
public string DisplayString
{
get
{
return StartTime.ToString(@"hh\:mm") + " - " + (StartTime + Duration).ToString(@"hh\:mm");
}
}
public slot(TimeSpan StartTime, TimeSpan Duration)
{
this.StartTime = StartTime;
this.Duration = Duration;
}
public List<slot> TimeSlots(TimeSpan start, TimeSpan end, TimeSpan duration)
{
List<slot> slots = new List<slot>();
while (start < end)
{
slots.Add(new slot(start, duration));
start = start + duration;
}
return slots;
}
}
谁能帮忙解决这个问题?
所以希望我正确理解了你的问题,如果没有,请澄清。我相信您可能需要这样的东西:
@Html.DropDownListFor(d=>d.AvailableSlots, new SelectList(d.AvailableSlots),"Select Slot");
这会出现在您的视图中,上面写着“需要插槽的下拉列表”。您没有 post 您的模型(“医生”?),但我的代码从我要添加的医生模型中提取了一个“AvailableSlots”属性。 属性 包含医生的所有可用位置。
“现在我已经在 var 详细信息中有了医生的详细信息(包括开始和结束时间),所以我应该能够从那里提取开始时间和结束时间,对吗?并将这两个数据发送到 slots.cs class 用于创建插槽??"
--Short answer, yes.
我假设这些成员是列表中对象的一部分。
再深入一点:
我可能在这里展示了显而易见的东西......
我在代码周围添加了更多细节。您拥有的 LINQ 查询工作正常。
*抱歉丑陋的列表初始化(向右滚动不好,但紧凑的代码很好)。
void Main()
{
var doctors = new List<Doctor>{
new Doctor{Name = "Doc1", City = "Memphis", Specialization ="surgery", StartTime = TimeSpan.Parse("06:00:00"), EndTime = TimeSpan.Parse("15:00:00")},
new Doctor{Name = "Doc2", City = "Memphis", Specialization ="surgery", StartTime = TimeSpan.Parse("08:00"), EndTime = TimeSpan.Parse("17:00")},
new Doctor{Name = "Doc3", City = "Nashville", Specialization ="surgery", StartTime = TimeSpan.Parse("10:00"), EndTime = TimeSpan.Parse("14:00")},
new Doctor{Name = "Doc4", City = "Houston", Specialization ="surgery", StartTime = TimeSpan.Parse("09:00"), EndTime = TimeSpan.Parse("15:00")},
new Doctor{Name = "Doc5", City = "Memphis", Specialization ="Quack", StartTime = TimeSpan.Parse("08:30"), EndTime = TimeSpan.Parse("15:00")},
};
// ?City=Dhaka&specialization=Medicine&date=2020-11-29&btn_find=Find ---> example query string
string city_local = "Memphis";
string specialization_local = "surgery";
List<Doctor> details = doctors.Where(x => x.City.Equals(city_local) &&
x.Specialization.Equals(specialization_local)).ToList();
;
//for breakpoint :)
//Do something with the list of Doctor (use start times and end times as needed).
}
public class Doctor
{
public string Name {get; set;}
public string City {get; set;}
public string Specialization {get; set;}
public TimeSpan StartTime {get; set;}
public TimeSpan EndTime {get; set;}
}
在我的医生中 table 我有 3 列,分别命名为开始时间、结束时间和持续时间。
我的计划是,当用户输入城市名称并选择医生专业并单击搜索按钮时,将显示 table 符合该条件的医生。包括开始时间、结束时间和一个时间段。
如果医生的开始时间为上午 8 点,结束时间为晚上 8 点,每位患者的平均持续时间为 30 分钟,则将创建 24 个槽位。
除了我不知道如何将所有内容与时间段下拉菜单结合起来(当然不会显示特定日期的已预订时间)外,我的大部分工作都在进行中。
现在我已经在 var details 中有了医生的详细信息(包括开始和结束时间)所以我应该能够从那里提取开始时间和结束时间?
并将这两条数据发送到slots.cs class用于创建插槽?
这是我的操作方法:
public ActionResult Dashboard(string city, string specialization)
{
// ?City=Dhaka&specialization=Medicine&date=2020-11-29&btn_find=Find ---> example query string
string city_local = Request.Params["city"];
string specialization_local = Request.Params["specialization"];
var details = db.doctors
.Where(x => x.city.Equals(city_local) &&
x.specialization.Equals(specialization_local)).ToList(); -->this guy right here
return View(details);
}
这是我的观点:
<table class="table table table-borderless table-hover text-center">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Start Time</th>
<th>End Time</th>
<th>Available Slot</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@if(Model.Count() == 0)
{
<tr>
<td>No Records Found. Try Again</td>
</tr>
}
else
{
foreach(var data in Model)
{
<tr>
<td>@data.doctor_id</td>
<td>@data.doctor_fname</td>
<td>@data.start_time</td>
<td>@data.end_time</td>
<td>A dropdown of slots needed</td>
<td><a href="#">Book</a></td>
</tr>
}
}
</tbody>
</table>
最后是我的 slots.cs,它应该可以用于创建时隙:
public class slot
{
public TimeSpan StartTime { get; set; }
public TimeSpan Duration { get; set; }
public string DisplayString
{
get
{
return StartTime.ToString(@"hh\:mm") + " - " + (StartTime + Duration).ToString(@"hh\:mm");
}
}
public slot(TimeSpan StartTime, TimeSpan Duration)
{
this.StartTime = StartTime;
this.Duration = Duration;
}
public List<slot> TimeSlots(TimeSpan start, TimeSpan end, TimeSpan duration)
{
List<slot> slots = new List<slot>();
while (start < end)
{
slots.Add(new slot(start, duration));
start = start + duration;
}
return slots;
}
}
谁能帮忙解决这个问题?
所以希望我正确理解了你的问题,如果没有,请澄清。我相信您可能需要这样的东西:
@Html.DropDownListFor(d=>d.AvailableSlots, new SelectList(d.AvailableSlots),"Select Slot");
这会出现在您的视图中,上面写着“需要插槽的下拉列表”。您没有 post 您的模型(“医生”?),但我的代码从我要添加的医生模型中提取了一个“AvailableSlots”属性。 属性 包含医生的所有可用位置。
“现在我已经在 var 详细信息中有了医生的详细信息(包括开始和结束时间),所以我应该能够从那里提取开始时间和结束时间,对吗?并将这两个数据发送到 slots.cs class 用于创建插槽??"
--Short answer, yes.
我假设这些成员是列表中对象的一部分。
再深入一点: 我可能在这里展示了显而易见的东西......
我在代码周围添加了更多细节。您拥有的 LINQ 查询工作正常。
*抱歉丑陋的列表初始化(向右滚动不好,但紧凑的代码很好)。
void Main()
{
var doctors = new List<Doctor>{
new Doctor{Name = "Doc1", City = "Memphis", Specialization ="surgery", StartTime = TimeSpan.Parse("06:00:00"), EndTime = TimeSpan.Parse("15:00:00")},
new Doctor{Name = "Doc2", City = "Memphis", Specialization ="surgery", StartTime = TimeSpan.Parse("08:00"), EndTime = TimeSpan.Parse("17:00")},
new Doctor{Name = "Doc3", City = "Nashville", Specialization ="surgery", StartTime = TimeSpan.Parse("10:00"), EndTime = TimeSpan.Parse("14:00")},
new Doctor{Name = "Doc4", City = "Houston", Specialization ="surgery", StartTime = TimeSpan.Parse("09:00"), EndTime = TimeSpan.Parse("15:00")},
new Doctor{Name = "Doc5", City = "Memphis", Specialization ="Quack", StartTime = TimeSpan.Parse("08:30"), EndTime = TimeSpan.Parse("15:00")},
};
// ?City=Dhaka&specialization=Medicine&date=2020-11-29&btn_find=Find ---> example query string
string city_local = "Memphis";
string specialization_local = "surgery";
List<Doctor> details = doctors.Where(x => x.City.Equals(city_local) &&
x.Specialization.Equals(specialization_local)).ToList();
;
//for breakpoint :)
//Do something with the list of Doctor (use start times and end times as needed).
}
public class Doctor
{
public string Name {get; set;}
public string City {get; set;}
public string Specialization {get; set;}
public TimeSpan StartTime {get; set;}
public TimeSpan EndTime {get; set;}
}