public ActionResult Create(Auther auther) { try { // TODO: Add insert logic here autherReposetory.Add(auther); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Create(BookAutherViewModel model) { if (ModelState.IsValid) { try { if (model.AutherID == -1) { ViewBag.Message = "Please Select an Auther"; return(View(GetAllAuthers())); } DeleteFile(model.imgUrl); string fileName = UploadFile(model.File); var auther = autherRepository.Find(model.AutherID); // TODO: Add insert logic here Book book = new Book { Title = model.Title, Description = model.Description, _auther = auther, imgURL = fileName }; bookRepository.Add(book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } } ModelState.AddModelError("", "You have to fill all the required fields!"); return(View(GetAllAuthers())); }