我需要从我的 mvc webapi 获取 from 和 to date 以检索这些日期之间的项目。这是我尝试过但没有奏效的最喜欢的事情(我尝试了几件事)。
我有一个项目之间共享的对象:
public class SchedulerDateSpan
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
这是我的控制器类:
public IEnumerable<Appointment> GetAppointments(SchedulerDateSpan dates)
{
IEnumerable<Appointment> appointments =
db.Appointments.Where(
a =>
(a.StartDate <= dates.StartDate && a.EndDate >= dates.StartDate) || (a.StartDate <= dates.EndDate && a.EndDate >= dates.EndDate) ||
(a.StartDate > dates.StartDate && a.EndDate < dates.EndDate)).AsEnumerable();
return appointments;
}
这是我来自客户的电话,其中日期类型为 SchedulerDateSpan:
var client = new HttpClient { BaseAddress = new Uri(Properties.Settings.Default.SchedulerWebApi) };
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage resp = client.GetAsync(String.Format("api/Appointments/{0}",dates)).Result;
if (resp.IsSuccessStatusCode)
{
var appointments = resp.Content.ReadAsAsync<IEnumerable<Appointment>>().Result;
......
}
我还尝试将其更改为似乎可行的 put 但后来我无法解析结果Content.ReadAsAsync
任何建议表示赞赏