Example #1
0
        public ActionResult Edit(AddEditBookModel model)
        {
            if (ModelState.IsValid)
            {
                var book = Mapper.Map <BookFullModel, Book>(model.Book);

                var newFile = _fileService.SaveImage(model.Book.Image, model.OldImageFile, model.IsImageChanged);

                book.ImageFile = newFile.HasValue
                    ? newFile
                    : string.IsNullOrEmpty(model.Book.ImageFile)
                        ? (Guid?)null : new Guid(model.Book.ImageFile);

                Service.Update(book);

                return(RedirectToAction("Index", new
                {
                    id = model.Book.GenreId
                }));
            }
            else
            {
                FillDicts();

                ModelState.AddModelError("", "There Are errors");

                return(View("CreateEdit", model));
            }
        }
Example #2
0
        public ActionResult Create(AddEditBookModel model)
        {
            if (ModelState.IsValid)
            {
                var book = Mapper.Map <BookFullModel, Book>(model.Book);

                book.ImageFile = _fileService.SaveImage(model.Book.Image, null, model.IsImageChanged);

                Service.Add(book);

                return(RedirectToAction("Index", new
                {
                    id = model.Book.GenreId
                }));
            }
            else
            {
                FillDicts();

                return(View("CreateEdit", model));
            }
        }