Пример #1
0
        public ActionResult Create(BookViewModel bookViewModel)
        {
            if (ModelState.IsValid)
            {
                var config = new MapperConfiguration(mapping =>
                {
                    mapping.CreateMap <BookViewModel, Book>();
                });
                IMapper mapper    = config.CreateMapper();
                var     book      = mapper.Map <BookViewModel, Book>(bookViewModel);
                var     Categorys = bookBL.BindCategory();
                ViewBag.Mycategory = new SelectList(Categorys, "CategoryId", "CategoryName");
                bookBL.AddMethod(book);

                return(RedirectToAction("BookDetails"));
            }
            else
            {
                ModelState.AddModelError("", "Some error occured");
            }
            return(View());
        }