public async Task <IActionResult> StartRepair(StartRepairViewModel model) { var scheduleDetail = await _scheduleDetailRepository.GetScheduleDetailByActiveSchedule(model.ActiveScheduleId); if (scheduleDetail == null) { return(NotFound()); } var activeSchedule = await _activeScheduleRepository.GetByIdAsync(model.ActiveScheduleId); if (activeSchedule == null) { return(NotFound()); } var repair = await _converterHelper.ToRepairAsync(model); var repairSchedule = _converterHelper.ToRepairSchedule(scheduleDetail, repair); try { repair.CreationDate = DateTime.Now; await _repairScheduleRepository.CreateAsync(repairSchedule); scheduleDetail.IsActive = false; activeSchedule.IsActive = false; await _scheduleDetailRepository.UpdateAsync(scheduleDetail); await _activeScheduleRepository.UpdateAsync(activeSchedule); return(RedirectToAction("ShowScheduleForDealership", "ScheduleDetails")); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.InnerException.Message); var scheduleDetailsEx = await _scheduleDetailRepository.GetScheduleDetailAsync(model.Schedule.Id); var departmentsEx = _dealershipDepartmentRepository.GetDealershipDepartments(scheduleDetailsEx.Dealership.Id); var returnModelEx = _converterHelper.ToStartRepairViewModel(scheduleDetailsEx, departmentsEx); return(View(returnModelEx)); } }
public async Task <IActionResult> EditSchedule(EditScheduleViewModel model) { if (ModelState.IsValid) { var activeSchedule = await _converterHelper.ToActiveScheduleFromEditAsync(model); try { await _activeScheduleRepository.UpdateAsync(activeSchedule); return(RedirectToAction("Index")); } catch { return(View(model)); } } return(View(model)); }