public async Task <IActionResult> AppointmentDate(AppointmentDateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } if (model.EndOfWork < model.StartOfWork) { ViewBag.Message = "Дата окончания рабочего дня не может быть меньше начала"; return(View(model)); } var user = await _userManager.GetUserAsync(HttpContext.User); var employee = this._unitOfWork.Employees.Find(e => e.UserID == user.Id).FirstOrDefault(); var doctor = this._unitOfWork.Doctors.Find(d => d.EmployeeID == employee.EmployeeID).FirstOrDefault(); if (model.AppointmentDateId == 0) { var existDate = this._unitOfWork.DatesOfAppointments .Find(d => d.DoctorID == doctor.ID && DateTime.Compare(d.Date, model.Date) == 0) .SingleOrDefault(); if (existDate == null) { DateOfAppointment date = new DateOfAppointment { DoctorID = doctor.ID, Date = model.Date, PeriodOfWorking = string.Format("{0}-{1}", model.StartOfWork, model.EndOfWork) }; ViewBag.Message = "Дата приема создана"; this._unitOfWork.DatesOfAppointments.Add(date); } else { ViewBag.Message = "В этот день уже есть прием"; } } else { DateOfAppointment date = this._unitOfWork.DatesOfAppointments.Get(model.AppointmentDateId); date.Date = model.Date; date.PeriodOfWorking = string.Format("{0}-{1}", model.StartOfWork, model.EndOfWork); ViewBag.Message = "Дата приема успешно изменена"; } this._unitOfWork.Save(); return(View("Info")); }
public async Task <IActionResult> AppointmentDate(int appointmentDateId) { AppointmentDateViewModel model = new AppointmentDateViewModel(); ViewBag.Message = "Создание даты приема"; if (appointmentDateId != 0) { DateOfAppointment date = this._unitOfWork.DatesOfAppointments.Get(appointmentDateId); string[] values = date.PeriodOfWorking.Split('-'); model = new AppointmentDateViewModel { AppointmentDateId = date.DateOfAppointmentID, DoctorId = date.DoctorID, Date = date.Date.Date, PeriodOfWorking = date.PeriodOfWorking, StartOfWork = int.Parse(values[0]), EndOfWork = int.Parse(values[1]) }; ViewBag.Message = "Изменение даты приема"; } return(View(model)); }