//--------------------------------------------------------EDIT-------------------------------------------------------- public ActionResult Edit(int id) { if (Session["user"] == null) { return(RedirectToAction("Index")); } EditAuthorModel obj = new EditAuthorModel(); obj.Author = Author.getAuthor(id); obj.Books = Book.getBookList(); return(View(obj)); }
public IActionResult Edit(EditAuthorModel model) { string imgUrl = null; string path = null; var ifNeedToCreateImg = false; if (model.Image != null) { if (!this.IfImgIsValid(model.Image)) { return(View(model)); } var fileName = model.Image.FileName; var extention = this.imgService.ReturnExtension(fileName); var currentNumberOnFolder = this.bookService.CountOfAllBooks() % GlobalConstants.NumberOnFolder; var currentFoledName = GlobalConstants.FolderNameImg + currentNumberOnFolder; path = this.imgService.ReturnPath(environment, currentFoledName); imgUrl = this.imgService.ReturnUrl(environment, currentFoledName, extention); ifNeedToCreateImg = true; } if (!this.authorService.Edit(model.Id, model.Name, model.Details, imgUrl)) { this.TempData[GlobalConstants.TempDateErrorKey] = EditErrorMessage; return(RedirectToAction(nameof(Edit))); } if (ifNeedToCreateImg) { this.imgService.CreateImg(model.Image, path, imgUrl); } return(Redirect(GlobalConstants.IndexPath)); }