public SeckillListModel(DateTime dt, string schedule, List <ScheduleModel> scheduleModels) { var week = dt.DayOfWeek.ToString(); ShortDate = dt.ToShortDateString(); Week = week; switch (week) { case "Monday": break; case "Tuesday": dt = dt.AddDays(-1); break; case "Wednesday": dt = dt.AddDays(-2); break; case "Thursday": dt = dt.AddDays(-3); break; case "Friday": dt = dt.AddDays(-4); break; case "Saturday": dt = dt.AddDays(-5); break; case "Sunday": dt = dt.AddDays(-6); break; default: break; } Schedule = schedule; var scheduleDetail = new ScheduleDetail(); Day1 = scheduleDetail.GenerateScheduleDetail(0, dt, schedule, scheduleModels, scheduleDetail); Day2 = scheduleDetail.GenerateScheduleDetail(1, dt, schedule, scheduleModels, scheduleDetail); Day3 = scheduleDetail.GenerateScheduleDetail(2, dt, schedule, scheduleModels, scheduleDetail); Day4 = scheduleDetail.GenerateScheduleDetail(3, dt, schedule, scheduleModels, scheduleDetail); Day5 = scheduleDetail.GenerateScheduleDetail(4, dt, schedule, scheduleModels, scheduleDetail); Day6 = scheduleDetail.GenerateScheduleDetail(5, dt, schedule, scheduleModels, scheduleDetail); Day7 = scheduleDetail.GenerateScheduleDetail(6, dt, schedule, scheduleModels, scheduleDetail); Default = scheduleDetail.DefaultGenerateDefaultActivity(schedule, Schedule); }
public ScheduleDetail GenerateScheduleDetail(int addDays, DateTime dt, string schedule, List <ScheduleModel> scheduleModels, ScheduleDetail scheduleDetail) { return(scheduleModels.Where(r => r.ShortDate == dt.AddDays(addDays).ToString("yyyy-MM-dd")) ?.Select(r => r.Schedule.FirstOrDefault(s => s.Schedule == schedule)).FirstOrDefault() ?? scheduleDetail.GenerateDefaultActivity(dt.AddDays(addDays), schedule, dt.AddDays(addDays).ToShortDateString())); }