【问题标题】:Extract particular data from list in asp.net从asp.net中的列表中提取特定数据
【发布时间】:2021-03-08 21:06:07
【问题描述】:

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

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

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

除了我不知道如何将所有内容与时间段下拉列表结合起来(当然不会显示特定日期已预订的时间)之外,我的大多数事情都在工作。

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

并将这两条数据发送到 slot.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>

最后是我的 slot.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;
    }
}

谁能帮忙解决这个问题?

【问题讨论】:

    标签: c# asp.net asp.net-mvc-5


    【解决方案1】:

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

    @Html.DropDownListFor(d=>d.AvailableSlots, new SelectList(d.AvailableSlots),"Select Slot");
    

    在您看来,它会显示“需要插槽的下拉列表”。您没有发布您的模型(“医生”?),但我的代码从我要添加的医生模型中提取了一个“AvailableSlots”属性。此属性包含医生的所有可用插槽。

    【讨论】:

      【解决方案2】:

      “现在我已经在 var details 中获得了医生的详细信息(包括开始和结束时间),所以我应该能够从那里提取开始时间和结束时间,对吧?然后将这两个数据发送到 slot.cs 类用于创建插槽??”

      --简答,是的。

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

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

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

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

      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;}
      }
      
      

      【讨论】:

        猜你喜欢
        • 2013-10-24
        • 1970-01-01
        • 1970-01-01
        • 2012-04-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多