public async Task <IActionResult> UserRegion(int?id) { try { if (User != null) { await _accountService.SetUserRegion(User, id); TempData[Constants.Common.ModalMessage] = Constants.Message.RecordSuccessUpdate; return(RedirectToAction(nameof(UserRegion))); } ModelState.AddModelError(string.Empty, "User not found"); await _accountService.SignOut(); return(RedirectToAction(nameof(UserRegion))); } catch (Exception ex) { var exceptionMessage = await Helpers.GetErrors(ex, _emailService); ModelState.AddModelError(new ValidationResult(exceptionMessage)); } ModelState.AddModelError(string.Empty, "Invalid user update."); TempData[Constants.Common.ModalTitle] = Constants.Message.Error; TempData[Constants.Common.ModalMessage] = Helpers.CreateValidationSummary(ModelState); return(RedirectToAction(nameof(UserRegion))); }
public async Task <IActionResult> Delete(int id, RegionSearchViewModel searchViewModel) { try { var validationResult = await new RegionHandler(_regionService).CanDelete(id); if (validationResult == null) { // if no validation error, delete the record await _regionService.DeleteById(id); // set TempData for Success Modal TempData[Constants.Common.ModalMessage] = Constants.Message.RecordSuccessDelete; return(RedirectToAction(nameof(List), searchViewModel)); } ModelState.AddModelError(validationResult); } catch (Exception ex) { var exceptionMessage = await Helpers.GetErrors(ex, _emailService); ModelState.AddModelError(new ValidationResult(exceptionMessage)); } ModelState.AddModelError(string.Empty, "Invalid delete attempt."); // set TempData for Error Modal TempData[Constants.Common.ModalTitle] = Constants.Message.Error; TempData[Constants.Common.ModalMessage] = Helpers.CreateValidationSummary(ModelState); return(RedirectToAction(nameof(List), searchViewModel)); }
public async Task <IActionResult> UserRegion() { if (User == null) { ModelState.AddModelError(string.Empty, Constants.Message.ErrorProcessing); TempData[Constants.Common.ModalTitle] = Constants.Message.Error; TempData[Constants.Common.ModalMessage] = Helpers.CreateValidationSummary(ModelState); return(RedirectToAction(nameof(HomeController.Index), "Home")); } var ddl = await _regionService.GetRegionDropdown(); var user = await _accountService.FindUserByClaims(User); ViewBag.RegionDropdown = new SelectList(ddl, "Value", "Text", user.RegionId); return(View()); }