Ejemplo n.º 1
0
        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()));
        }
Ejemplo n.º 2
0
        // GET: Book/Details/5
        public ActionResult Details(int id)
        {
            var book = bookRepository.Find(id);

            return(View(book));
        }
Ejemplo n.º 3
0
        // GET: Auther/Details/5
        public ActionResult Details(int id)
        {
            var auther = autherReposetory.Find(id);

            return(View(auther));
        }