public GetChangeHospitalRegistrationsPageInformationCommandAnswer GetChangeHospitalRegistrationsPageInformation( GetChangeHospitalRegistrationsPageInformationCommand command) { const int days = 30; var now = DateTime.Now; var deadLine = now + new TimeSpan(days, 0, 0, 0); var startMonday = GetPreviousMonday(now); var endMonday = GetPreviousMonday(deadLine); var weeks = (endMonday - startMonday).Days/7 + 1; var user = _tokenManager.GetUserByToken(command.Token); var hospitalId = GetHospitalIdByUserId(user.Id); var completeCount = this.GetHospitalProfileCount(hospitalId, user.Id); var statisticList = this.GetStatisticList(now, deadLine, hospitalId, user.Id); var startSchedule = Enumerable.Range(0, weeks) .Select(week => new ScheduleTableItem { Cells = Enumerable.Range(0, 7) .ToDictionary(day => (DayOfWeek) day, day => new ScheduleTableCell { IsBlocked = startMonday.AddDays(7*week + day).Date < now.Date || startMonday.AddDays(7*week + day).Date > deadLine.Date, Day = startMonday.AddDays(7*week + day).Day, IsCompleted = statisticList.Count(model => model.Date.Date == startMonday.AddDays(7*week + day).Date) == completeCount, IsStarted = statisticList.Any(model => model.Date.Date == startMonday.AddDays(7*week + day).Date), IsThisMonth = startMonday.AddDays(7*week + day).Month == now.Month, IsThisDate = startMonday.AddDays(7*week + day).Date == now.Date, Date = startMonday.AddDays(7*week + day).Date }) }) .ToList(); return new GetChangeHospitalRegistrationsPageInformationCommandAnswer { Token = (Guid) command.Token, Schedule = startSchedule }; }
public ActionResult Index(GetChangeHospitalRegistrationsPageInformationCommand command) { var answer = _hospitalRegistrationsService.GetChangeHospitalRegistrationsPageInformation(command); return View(answer); }