コード例 #1
0
 public ActionResult Add()
 {
     var model = new BookStoreModel
                     {
                         IsEditMode = false
                     };
     model = Mapper.Map(_bookRepository.GetAll(), model);
     return View("Edit", model);
 }
コード例 #2
0
 public ActionResult Add(BookStoreModel model)
 {
     if (ModelState.IsValid)
     {
         var bookStore = Mapper.Map<BookStoreModel, BookStore>(model);
         if (model.BooksIds != null && model.BooksIds.Any())
             bookStore.Books = _bookRepository.GetAll().Where(book => model.BooksIds.Contains(book.Id)).ToList();
         _bookStoreRepository.Insert(bookStore);
         return RedirectToAction("Index", new { message = (int)BookStoresListSuccessMessage.BookStoreAddedSuccesfully });
     }
     return Add();
 }
コード例 #3
0
 public ActionResult Edit(BookStoreModel model)
 {
     if (ModelState.IsValid)
     {
         var bookStore = _bookStoreRepository.Get(model.Id);
         if (bookStore == null)
             return RedirectToAction("Index");
         bookStore = Mapper.Map(model, bookStore);
         bookStore.Books.Clear();
         if (model.BooksIds != null && model.BooksIds.Any())
             bookStore.Books = _bookRepository.GetAll().Where(book => model.BooksIds.Contains(book.Id)).ToList();
         _bookStoreRepository.Save(bookStore);
         return RedirectToAction("Index", new { message = (int)BookStoresListSuccessMessage.BookStoreEditedSuccesfully });
     }
     return Edit(model.Id);
 }