public ActionResult EditPublisher(PublishersEditPublisherVM model) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); Publisher publisher = null; if (!ModelState.IsValid) { return(View(model)); } else { if (model.ID > 0) { publisher = publishersRepository.GetByID(model.ID); } else { publisher = new Publisher(); } publisher.ID = model.ID; publisher.Name = model.Name; publisher.Address = model.Address; publishersRepository.Save(publisher); } return(RedirectToAction("Index", "Publishers")); }
public ActionResult Details(int id, string sortOrder) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); BooksRepository booksRepository = new BooksRepository(context); PublishersDetailsVM model = new PublishersDetailsVM(); this.TryUpdateModel(model); var publisher = publishersRepository.GetByID(id); if (publisher != null) { model.ID = publisher.ID; model.PublisherName = publisher.Name; model.Address = publisher.Address; model.BooksPager = model.BooksPager ?? new GenericPagerVM(); model.BooksPager.CurrentPage = model.BooksPager.CurrentPage == 0 ? 1 : model.BooksPager.CurrentPage; model.BooksPager.Action = "Details"; model.BooksPager.Controller = "Publishers"; model.BooksPager.Prefix = "BooksPager"; model.BooksPager.CurrentParameters = new Dictionary <string, object>() { { "BookTitle", model.BookTitle }, { "BooksPager.CurrentPage", model.BooksPager.CurrentPage } }; #region Sorting and Filtering Expression <Func <Book, bool> > filter = b => (string.IsNullOrEmpty(model.BookTitle) || b.Title.Contains(model.BookTitle)); model.BooksPager.PagesCount = GetPagesCount(filter); ViewBag.BookSortParam = string.IsNullOrEmpty(sortOrder) ? "book_desc" : ""; switch (sortOrder) { case "book_desc": model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderByDescending(b => b.Title)) .Where(b => b.PublisherID == id) .ToList(); break; default: model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderBy(b => b.Title)) .Where(b => b.PublisherID == id) .ToList(); break; } #endregion return(View(model)); } else { return(RedirectToAction("Index", "Publishers")); } }
public ActionResult Details(int id, string sortOrder) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); BooksRepository booksRepository = new BooksRepository(context); PublishersDetailsVM model = new PublishersDetailsVM(); this.TryUpdateModel(model); var publisher = publishersRepository.GetByID(id); if (publisher != null) { model.ID = publisher.ID; model.PublisherName = publisher.Name; model.Address = publisher.Address; model.BooksPager = model.BooksPager ?? new GenericPagerVM(); model.BooksPager.CurrentPage = model.BooksPager.CurrentPage == 0 ? 1 : model.BooksPager.CurrentPage; model.BooksPager.Action = "Details"; model.BooksPager.Controller = "Publishers"; model.BooksPager.Prefix = "BooksPager"; model.BooksPager.CurrentParameters = new Dictionary<string, object>() { { "BookTitle", model.BookTitle }, { "BooksPager.CurrentPage", model.BooksPager.CurrentPage } }; #region Sorting and Filtering Expression<Func<Book, bool>> filter = b => (string.IsNullOrEmpty(model.BookTitle) || b.Title.Contains(model.BookTitle)); model.BooksPager.PagesCount = GetPagesCount(filter); ViewBag.BookSortParam = string.IsNullOrEmpty(sortOrder) ? "book_desc" : ""; switch (sortOrder) { case "book_desc": model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderByDescending(b => b.Title)) .Where(b => b.PublisherID == id) .ToList(); break; default: model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderBy(b => b.Title)) .Where(b => b.PublisherID == id) .ToList(); break; } #endregion return View(model); } else { return RedirectToAction("Index", "Publishers"); } }
public ActionResult EditPublisher(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); PublishersEditPublisherVM model = new PublishersEditPublisherVM(); Publisher publisher = publishersRepository.GetByID(id); if (id > 0) { if (publisher == null) { return(RedirectToAction("Index", "Publishers")); } model.ID = publisher.ID; model.Name = publisher.Name; model.Address = publisher.Address; } return(View(model)); }
public ActionResult EditPublisher(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); PublishersEditPublisherVM model = new PublishersEditPublisherVM(); Publisher publisher = publishersRepository.GetByID(id); if (id > 0) { if (publisher == null) { return RedirectToAction("Index", "Publishers"); } model.ID = publisher.ID; model.Name = publisher.Name; model.Address = publisher.Address; } return View(model); }
public ActionResult EditPublisher(PublishersEditPublisherVM model) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); Publisher publisher = null; if (!ModelState.IsValid) { return View(model); } else { if (model.ID > 0) { publisher = publishersRepository.GetByID(model.ID); } else { publisher = new Publisher(); } publisher.ID = model.ID; publisher.Name = model.Name; publisher.Address = model.Address; publishersRepository.Save(publisher); } return RedirectToAction("Index", "Publishers"); }