public IActionResult Update(EditWriterViewModel model) { if (ModelState.IsValid) { var dtoPhoto = new FileManager().Save(model.File, shouldImage: true); var result = _commandDispatcher.Dispatch(new UpdateWriterCommand() { WriterId = model.Id, Photo = dtoPhoto, Name = model.Name }); if (result.IsSuccess) { return(RedirectToAction(nameof(List))); } if (!string.IsNullOrEmpty(result.Message)) { ModelState.AddModelError("", result.Message); } foreach (var item in result.Errors) { ModelState.AddModelError("", item); } } return(RedirectToAction(nameof(Update), model.Id)); }
public IActionResult Update(long id) { var writer = _queryDispatcher.Dispatch <DtoUpdateWriter>(new WriterUpdateQuery() { Id = id }); if (writer == null) { ModelState.AddModelError("", "نویسنده یافت نشد"); return(View()); } var editWriterNameViewModel = new EditWriterViewModel() { Id = id, Name = writer.Name, PhotoUrl = writer.PhotoUrl, PhotoId = writer.PhotoId }; return(View(editWriterNameViewModel)); }