public ActionResult BookUpdate(BookAppointmentViewModel viewModel) { if (viewModel.Updating) { var updateBookingRequest = new UpdateAppointmentRequest { Id = viewModel.AppointmentId.Value, Date = viewModel.Date, StartTime = viewModel.StartTime, EndTime = viewModel.EndTime, LeadName = viewModel.LeadName, Address = viewModel.Address }; var validationResult = _appointmentService.ValidateUpdate(updateBookingRequest); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) ModelState.AddModelError(error.Field ?? "", error.Text); return View("BookUpdate", viewModel); } _appointmentService.Update(updateBookingRequest); } else { Guid id = Guid.NewGuid(); var makeBookingRequest = new BookAppointmentRequest { Id = id, ConsultantId = viewModel.ConsultantId.Value, Date = viewModel.Date, StartTime = viewModel.StartTime, EndTime = viewModel.EndTime, LeadName = viewModel.LeadName, Address = viewModel.Address }; var validationResult = _appointmentService.ValidateBook(makeBookingRequest); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) ModelState.AddModelError(error.Field ?? "", error.Text); return View("BookUpdate", viewModel); } _appointmentService.Book(makeBookingRequest); } return RedirectToAction("Index", "Consultant", new { consultantId = viewModel.ConsultantId }); }
public void Update(UpdateAppointmentRequest request) { var session = _sessionFactory.OpenSession(); CurrentSessionContext.Bind(session); try { using (var transactionScope = new TransactionScope()) { var appointment = _appointmentRepository.GetById(request.Id); DomainEvents.Register<AppointmentUpdatedEvent>(AppointmentUpdated); appointment.Update( request.Date, request.StartTime, request.EndTime, request.LeadName, request.Address); session.Flush(); transactionScope.Complete(); } } finally { CurrentSessionContext.Unbind(_sessionFactory); session.Dispose(); } }
public ValidationMessageCollection ValidateUpdate(UpdateAppointmentRequest request) { var session = _sessionFactory.OpenSession(); CurrentSessionContext.Bind(session); try { Appointment appointment; using (var transaction = session.BeginTransaction()) { appointment = _appointmentRepository.GetById(request.Id); transaction.Commit(); } return appointment.ValidateUpdate( request.Date, request.StartTime, request.EndTime, request.LeadName, request.Address); } finally { CurrentSessionContext.Unbind(_sessionFactory); session.Dispose(); } }