public ActionResult Edit(ArtistEditViewModel viewModel) { var model = viewModel.EditedArtist; // Note: name is allowed to be whitespace, but not empty. if (model.Names.All(n => string.IsNullOrEmpty(n.Value))) { ModelState.AddModelError("Names", Model.Resources.ArtistValidationErrors.UnspecifiedNames); } var coverPicUpload = Request.Files["pictureUpload"]; var pictureData = ParsePicture(coverPicUpload, "Picture"); ParseAdditionalPictures(coverPicUpload, model.Pictures); try { viewModel.CheckModel(); } catch (InvalidFormException x) { AddFormSubmissionError(x.Message); } if (!ModelState.IsValid) { return(View("Edit", new ArtistEditViewModel(Service.GetArtist(model.Id), PermissionContext, model))); } queries.Update(model, pictureData, LoginManager); return(RedirectToAction("Details", new { id = model.Id })); }
public async Task <ActionResult> Edit(ArtistEditViewModel viewModel) { // Unable to continue if viewmodel is null because we need the ID at least if (viewModel == null || viewModel.EditedArtist == null) { log.Warn("Viewmodel was null"); return(HttpStatusCodeResult(HttpStatusCode.BadRequest, "Viewmodel was null - probably JavaScript is disabled")); } try { viewModel.CheckModel(); } catch (InvalidFormException x) { AddFormSubmissionError(x.Message); } var model = viewModel.EditedArtist; // Note: name is allowed to be whitespace, but not empty. if (model.Names.All(n => n == null || string.IsNullOrEmpty(n.Value))) { ModelState.AddModelError("Names", Model.Resources.ArtistValidationErrors.UnspecifiedNames); } var coverPicUpload = Request.Files["pictureUpload"]; var pictureData = ParsePicture(coverPicUpload, "Picture", ImagePurpose.Main); ParseAdditionalPictures(coverPicUpload, model.Pictures); if (!ModelState.IsValid) { return(View("Edit", CreateArtistEditViewModel(model.Id, model))); } try { await queries.Update(model, pictureData, PermissionContext); } catch (InvalidPictureException) { ModelState.AddModelError("ImageError", "The uploaded image could not processed, it might be broken. Please check the file and try again."); return(View("Edit", CreateArtistEditViewModel(model.Id, model))); } return(RedirectToAction("Details", new { id = model.Id })); }
private ArtistForEditContract CallUpdate(ArtistForEditContract contract) { contract.Id = queries.Update(contract, null, permissionContext); return(contract); }
private async Task <ArtistForEditContract> CallUpdate(ArtistForEditContract contract) { contract.Id = await _queries.Update(contract, null, _permissionContext); return(contract); }