Пример #1
0
        public ActionResult Create(Auther auther)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    autherRepository.add(auther);

                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View());
                }
            }


            return(View());
        }
Пример #2
0
        public ActionResult Create(BookAutherViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string filename = UploadFile(model.File) ?? String.Empty;

                    if (model.autherID == -1)
                    {
                        ViewBag.Message = "please select an auther from the list";

                        return(View(fillList()));
                    }
                    Book book = new Book
                    {
                        Title       = model.Title,
                        description = model.Description,
                        Auther      = AutherRepository.Find(model.autherID),
                        ImageURL    = model.File.FileName
                    };
                    bookRepository.add(book);


                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View());
                }
            }

            ModelState.AddModelError("", "You have to fill all the required fields");

            return(View(fillList()));
        }