帮助我,我已经坚持了2天了,我无法弄清楚为什么代码无效。我的 API 代码用于获得考勤似乎正在运行但是当我在我的服务上调用它时它不起作用
我在这里要做的是过滤facschedList,如果已经存在并且出勤记录将被从教师时间表列表中删除。
以下是我的api上获取教师计划的代码:
List<FacultySchedule> facsched = db.FacultySchedules.Where(q => q.Day.Contains(day)).ToList(); // GET ALL SCHED DEPENDING ON CURRENT DAY OF THE WEEK
foreach (var sched in facsched)
{
DateTime startTime = Convert.ToDateTime(sched.Time_from);
DateTime dismissalTime = Convert.ToDateTime(sched.Time_to);
if (dt >= startTime && dt <= dismissalTime)
{
facschedlist.Add(sched);
}
}
return Ok(facschedlist);
以下是我的服务:
public async Task<List<FacultySchedule>> GetFacultySched()
{
RestClient<FacultySchedule> restClient = new RestClient<FacultySchedule>();
List<FacultySchedule> facschedList = await restClient.GetFacSchedulebyTimeAsync();
foreach (var f in facschedList)
{
var time = DateTime.Now.ToString("HH:mm");
DateTime dt = DateTime.ParseExact(time.Replace("UTC", "+08:00"), "HH:mm", null);
Attendance existingAttendance = await GetAttendance(f.SchedID);
if (existingAttendance != null)
{
facschedList.Remove(f);
}
}
return facschedList;
}
以下是获取出席情况的api中的代码:
DateTime dt = DateTime.Today.Date;
Attendance attendance = await db.Attendances.FirstAsync(q => q.SchedID.Equals(schedid)
&& q.DateChecked.Year == dt.Year
&& q.DateChecked.Month == dt.Month
&& q.DateChecked.Day == dt.Day);