public async Task <IActionResult> Edit(Guid id, DiveLocationEditModel locationModel) { try { if (!this.ModelState.IsValid) { await this.PopulateSelectLists(); return(View(locationModel)); } if (locationModel.Photo != null) { using (var stream = new MemoryStream()) { await locationModel.Photo.CopyToAsync(stream); locationModel.DiveLocation.ImageData = stream.ToArray(); // TODO: This is pretty resource intensive way to store/access images. Prefer to use file system or CDN with cache. } } var cmd = await _diveService.UpdateDiveLocationAsync(locationModel.DiveLocation); if (this.CheckResult(cmd)) // Success { return(RedirectToAction(nameof(Index))); } // If we make it to here then we failed await this.PopulateSelectLists(); } catch (FriendlyApplicationException ex) // It is possible to recover. { // This will allow us to format a "friendly error" which we may be able to recover from locationModel.DisplayMessage = ex.Message; _exceptionManager.HandleException(ex, DefaultExceptionPolicies.PresentationReplacePolicy); } catch (ApplicationException ex) // It is not possbile to recover. { // This will rethrow the exception and it will get handled by the global error handler _exceptionManager.HandleException(ex, DefaultExceptionPolicies.ApplicationWrapPolicy); } return(View(locationModel)); }
public async Task <IActionResult> Edit(Guid id) { var locationModel = new DiveLocationEditModel(); try { var cmd = await _diveService.GetDiveLocationByIdAsync(id); await this.PopulateSelectLists(); locationModel.DiveLocation = cmd.DataResult; } catch (FriendlyApplicationException ex) // It is possible to recover. { _exceptionManager.HandleException(ex, DefaultExceptionPolicies.PresentationReplacePolicy); } catch (ApplicationException ex) // It is not possbile to recover. { _exceptionManager.HandleException(ex, DefaultExceptionPolicies.ApplicationWrapPolicy); } return(View(locationModel)); }