public async Task <JsonResult> AutoSave(int id, ApprenticeshipApplicationViewModel model) { return(await Task.Run(() => { var response = _apprenticeshipApplicationMediator.AutoSave(UserContext.CandidateId, id, model); switch (response.Code) { case ApprenticeshipApplicationMediatorCodes.AutoSave.VacancyNotFound: return new JsonResult { Data = response.ViewModel }; case ApprenticeshipApplicationMediatorCodes.AutoSave.HasError: ModelState.Clear(); return new JsonResult { Data = response.ViewModel }; case ApprenticeshipApplicationMediatorCodes.AutoSave.ValidationError: ModelState.Clear(); return new JsonResult { Data = response.ViewModel }; case ApprenticeshipApplicationMediatorCodes.AutoSave.Ok: ModelState.Clear(); return new JsonResult { Data = response.ViewModel }; } throw new InvalidMediatorCodeException(response.Code); })); }
public async Task <JsonResult> AutoSave(int id, ApprenticeshipApplicationViewModel model) { return(await Task.Run(() => { MediatorResponse <AutoSaveResultViewModel> response; try { response = _apprenticeshipApplicationMediator.AutoSave(UserContext.CandidateId, id, model); } catch (Exception) { //TODO: Remove once the cause of the null candidate objects is fixed var requestDebugString = Request.ToDebugString(); _logService.Error("Error when auto saving apprenticeship application. Request: {0}", requestDebugString); throw; } switch (response.Code) { case ApprenticeshipApplicationMediatorCodes.AutoSave.VacancyNotFound: return new JsonResult { Data = response.ViewModel }; case ApprenticeshipApplicationMediatorCodes.AutoSave.HasError: ModelState.Clear(); return new JsonResult { Data = response.ViewModel }; case ApprenticeshipApplicationMediatorCodes.AutoSave.ValidationError: ModelState.Clear(); return new JsonResult { Data = response.ViewModel }; case ApprenticeshipApplicationMediatorCodes.AutoSave.IncorrectState: ModelState.Clear(); return new JsonResult { Data = response.ViewModel }; case ApprenticeshipApplicationMediatorCodes.AutoSave.Ok: ModelState.Clear(); return new JsonResult { Data = response.ViewModel }; } throw new InvalidMediatorCodeException(response.Code); })); }