public void BookAsync(BookHolidayViewModel viewModel) { AsyncManager.Parameters["viewModel"] = viewModel; var humanResourcesValidationMessages = _holidayValidator.ValidateBook( viewModel.EmployeeId, viewModel.Start, viewModel.End, viewModel.Description); if (humanResourcesValidationMessages.Any()) { humanResourcesValidationMessages.ForEach(message => ModelState.AddModelError("", message.Text)); return; } var calendarValidationMessages = _appointmentService.ValidateBook(new ValidateBookRequest { EmployeeId = viewModel.EmployeeId, DepartmentId = Constants.HumanResourcessDepartmentId, Start = viewModel.Start, End = viewModel.End, Description = viewModel.Description }).ToList(); if (calendarValidationMessages.Any()) { calendarValidationMessages.ForEach(message => ModelState.AddModelError("", message.Text)); return; } var bookHolidayCommand = new BookHoliday { Id = viewModel.Id, AppointmentId = viewModel.AppointmentId, EmployeeId = viewModel.EmployeeId, Start = viewModel.Start, End = viewModel.End, Description = viewModel.Description }; var bookAppointmentCommand = new BookAppointment { Id = viewModel.AppointmentId, EmployeeId = viewModel.EmployeeId, DepartmentId = Constants.HumanResourcessDepartmentId, Start = viewModel.Start, End = viewModel.End, }; _bus.Send(bookHolidayCommand).Register<HumanResourcesReplies.ReturnCode>(returnCode => AsyncManager.Parameters["bookHolidayReturnCode"] = returnCode); _bus.Send(bookAppointmentCommand).Register<CalendarReplies.ReturnCode>(returnCode => AsyncManager.Parameters["calendarReturnCode"] = returnCode); }
public ActionResult BookUpdate(bool updating, Guid? employeeId, Guid? holidayId, DateTime? start, DateTime? end) { var viewModel = new BookHolidayViewModel { Updating = updating, EmployeeId = employeeId, HolidayId = holidayId, Start = start.HasValue ? start.Value : new DateTime(2012, 08, 1), End = end.HasValue ? end.Value : new DateTime(2012, 08, 1), }; return View(viewModel); }
public ActionResult BookUpdate(BookHolidayViewModel viewModel) { if (viewModel.Updating) { var updateHolidayRequest = new UpdateHolidayRequest { Id = viewModel.HolidayId.Value, Start = viewModel.Start, End = viewModel.End }; var validationResult = _holidayService.ValidateUpdate(updateHolidayRequest); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) ModelState.AddModelError(error.Field ?? "", error.Text); return View("BookUpdate", viewModel); } _holidayService.Update(updateHolidayRequest); } else { Guid id = Guid.NewGuid(); var bookHolidayRequest = new BookHolidayRequest { Id = id, EmployeeId = viewModel.EmployeeId.Value, Start = viewModel.Start, End = viewModel.End }; var validationResult = _holidayService.ValidateBook(bookHolidayRequest); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) ModelState.AddModelError(error.Field ?? "", error.Text); return View("BookUpdate", viewModel); } _holidayService.Book(bookHolidayRequest); } return RedirectToAction("Index", "Employee", new { employeeId = viewModel.EmployeeId }); }
public ActionResult Book(Guid employeeId) { Employee employee; using (var transactionScope = new TransactionScope()) { employee = _employeeRepository.GetById(employeeId); transactionScope.Complete(); } var viewModel = new BookHolidayViewModel { Id = Guid.NewGuid(), AppointmentId = Guid.NewGuid(), EmployeeId = employeeId, EmployeeFullName = employee.FullName }; return View(viewModel); }
public ActionResult BookCompleted( BookHolidayViewModel viewModel, HumanResourcesReplies.ReturnCode bookHolidayReturnCode, CalendarReplies.ReturnCode calendarReturnCode) { if (!ModelState.IsValid) { return View(viewModel); } return RedirectToAction("Index", new { viewModel.EmployeeId }); }