C# 从asp.net中的列表中提取特定数据

C# 从asp.net中的列表中提取特定数据,c#,asp.net,asp.net-mvc-5,C#,Asp.net,Asp.net Mvc 5,在我的医生表中,我有3列,分别命名为开始时间、结束时间和持续时间 我的计划是,当用户键入城市名称并选择医生的专业并单击搜索按钮时,将显示符合该标准的医生表。包括开始时间、结束时间和时隙 如果医生的开始时间为上午8点,结束时间为晚上8点,每位患者的平均持续时间为30分钟,则将创建24个时段 我有很多工作要做,只是我不知道如何把所有的事情和下拉的时间段结合起来(当然不会显示某一天已经预定的时间) 现在我已经在var details中有了医生的详细信息(包括开始和结束时间),所以我应该能够从那里提取开

在我的医生表中,我有3列,分别命名为开始时间、结束时间和持续时间

我的计划是,当用户键入城市名称并选择医生的专业并单击搜索按钮时,将显示符合该标准的医生表。包括开始时间、结束时间和时隙

如果医生的开始时间为上午8点,结束时间为晚上8点,每位患者的平均持续时间为30分钟,则将创建24个时段

我有很多工作要做,只是我不知道如何把所有的事情和下拉的时间段结合起来(当然不会显示某一天已经预定的时间)

现在我已经在var details中有了医生的详细信息(包括开始和结束时间),所以我应该能够从那里提取开始时间和结束时间,对吗

然后将这两条数据发送到slots.cs类以创建插槽

这是我的行动方法:

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>

身份证件
名称
开始时间
结束时间
可用插槽
行动
@if(Model.Count()==0)
{
未找到任何记录。请重试
}
其他的
{
foreach(模型中的var数据)
{
@data.doctor\u id
@data.doctor\u fname
@data.start\u时间
@数据结束时间
所需插槽的下拉列表
}
}
最后是my 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;
    }
}
公共类插槽
{
公共时间跨度开始时间{get;set;}
公共时间跨度持续时间{get;set;}
公共字符串显示字符串
{
得到
{
返回StartTime.ToString(@“hh \:mm”)+“-”+(StartTime+持续时间).ToString(@“hh \:mm”);
}
}
公共插槽(时间跨度开始时间、时间跨度持续时间)
{
this.StartTime=StartTime;
这个。持续时间=持续时间;
}
公共列表时隙(时间跨度开始、时间跨度结束、时间跨度持续时间)
{
列表插槽=新列表();
while(开始<结束)
{
添加(新插槽(开始,持续时间));
开始=开始+持续时间;
}
返回槽;
}
}

有人能帮我解决这个问题吗?

希望我能正确理解你的问题,如果没有,请澄清。我相信你可能需要这样的东西:

@Html.DropDownListFor(d=>d.AvailableSlots, new SelectList(d.AvailableSlots),"Select Slot");
在你看来,这就是“所需插槽的下拉列表”。您没有发布您的模型(“医生”?),但我的代码从医生模型中提取了一个“AvailableSlots”属性,我将添加该属性。此属性包含医生的所有可用插槽

“现在我已经在var详细信息中有了医生的详细信息(包括开始和结束时间),所以我应该能够从那里提取开始时间和结束时间,对吗?并将这两个数据发送到slots.cs类以创建slots??”

--简短的回答,是的

我假设这些成员是列表中对象的一部分

再深入一点: 我可能在这里展示显而易见的东西

我在代码中添加了更多细节。您的LINQ查询工作正常

*对于丑陋的列表初始化(向右滚动是不好的,但紧凑的代码是好的)感到抱歉

void Main()
{   
var医生=新名单{
新医生{Name=“Doc1”,City=“孟菲斯”,Specialization=“外科”,StartTime=TimeSpan.Parse(“06:00:00”),EndTime=TimeSpan.Parse(“15:00:00”),
新医生{Name=“Doc2”,City=“孟菲斯”,Specialization=“外科”,StartTime=TimeSpan.Parse(“08:00”),EndTime=TimeSpan.Parse(“17:00”),
新医生{Name=“Doc3”,City=“Nashville”,Specialization=“surgery”,StartTime=TimeSpan.Parse(“10:00”),EndTime=TimeSpan.Parse(“14:00”),
新医生{Name=“Doc4”,City=“Houston”,Specialization=“surgery”,StartTime=TimeSpan.Parse(“09:00”),EndTime=TimeSpan.Parse(“15:00”),
新医生{Name=“Doc5”,City=“孟菲斯”,Specialization=“嘎嘎”,StartTime=TimeSpan.Parse(“08:30”),EndTime=TimeSpan.Parse(“15:00”),
};
//?城市=达卡&专业化=医学&日期=2020-11-29&btn_find=查找--->示例查询字符串
字符串city_local=“孟菲斯”;
字符串特化\u local=“外科”;
列表详细信息=医生。其中(x=>x.City.Equals(City\u local)和
x、 特化.Equals(特化_local)).ToList();
;
//对于断点:)
//根据医生名单做些什么(根据需要使用开始时间和结束时间)。
}
公立医生
{
公共字符串名称{get;set;}
公共字符串City{get;set;}
公共字符串专门化{get;set;}
公共时间跨度开始时间{get;set;}
公共时间跨度结束时间{get;set;}
}
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;}
}