private void RefreshList() { entitiesListBox.Items.Clear(); switch (_option) { case 1: _authorsRepository.GetAll().ForEach(author => entitiesListBox.Items.Add(author)); break; case 2: _publishersRepository.GetAll().ForEach(publisher => entitiesListBox.Items.Add(publisher)); break; case 3: _studentsRepository.GetAll().ForEach(student => entitiesListBox.Items.Add(student)); break; case 4: _booksRepository.GetAll().ForEach(book => entitiesListBox.Items.Add(book)); break; case 5: _loansRepository.GetAll().ForEach(loan => entitiesListBox.Items.Add(loan)); break; default: CommonErrorMessage(); break; } SearchAutoComplete(); }
public ActionResult Create() { ViewBag.publishers = publishers.GetAll(); ViewBag.authors = authors.GetAll(); ViewBag.page = "Create"; return(View("Edit", new Book())); }
public ActionResult Index(string sortOrder) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); PublishersIndexVM model = new PublishersIndexVM(); this.TryUpdateModel(model); model.PublishersPager = model.PublishersPager ?? new GenericPagerVM(); model.PublishersPager.CurrentPage = model.PublishersPager.CurrentPage == 0 ? 1 : model.PublishersPager.CurrentPage; model.PublishersPager.Action = "Index"; model.PublishersPager.Controller = "Publishers"; model.PublishersPager.Prefix = "PublishersPager"; model.PublishersPager.CurrentParameters = new Dictionary <string, object>() { { "PublisherName", model.PublisherName }, { "PublisherAddress", model.PublisherAddress }, { "PublishersPager.CurrentPage", model.PublishersPager.CurrentPage } }; #region Sorting and Filtering Expression <Func <Publisher, bool> > filter = p => (string.IsNullOrEmpty(model.PublisherName) || p.Name.Contains(model.PublisherName)) && (string.IsNullOrEmpty(model.PublisherAddress) || p.Address.Contains(model.PublisherAddress)); model.PublishersPager.PagesCount = GetPagesCount(filter); ViewBag.PublisherSortParam = string.IsNullOrEmpty(sortOrder) ? "publisher_desc" : ""; ViewBag.AddressSortParam = sortOrder == "Address" ? "address_desc" : "Address"; switch (sortOrder) { case "publisher_desc": model.PublishersList = publishersRepository .GetAll(model.PublishersPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderByDescending(p => p.Name)) .ToList(); break; case "Address": model.PublishersList = publishersRepository .GetAll(model.PublishersPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderBy(p => p.Address)) .ToList(); break; case "address_desc": model.PublishersList = publishersRepository .GetAll(model.PublishersPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderByDescending(p => p.Address)) .ToList(); break; default: model.PublishersList = publishersRepository .GetAll(model.PublishersPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderBy(p => p.Name)) .ToList(); break; } #endregion return(View(model)); }
public ActionResult EditBook(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); BooksRepository booksRepository = new BooksRepository(context); PublishersRepository publishersRepository = new PublishersRepository(context); BooksEditBookVM model = new BooksEditBookVM(); Book book = booksRepository.GetByID(id); if (id > 0) { if (book == null) { return(RedirectToAction("Index", "Books")); } model.ID = book.ID; model.Title = book.Title; model.PublisherID = book.Publisher.ID; model.StockCount = book.StockCount; model.DeliveryPrice = book.DeliveryPrice; model.DateReceived = book.DateReceived; model.DatePublished = book.DatePublished; } else { book = new Book(); } model.Publishers = model.Publishers ?? new List <SelectListItem>(); model.Publishers = SelectListHandler.Create <Publisher>( publishersRepository.GetAll(), p => p.Name, p => p.ID.ToString(), model.PublisherID.ToString()); return(View(model)); }
public ActionResult EditBook(BooksEditBookVM model) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); BooksRepository booksRepository = new BooksRepository(context); PublishersRepository publishersRepository = new PublishersRepository(context); Book book = null; if (!ModelState.IsValid) { model.Publishers = model.Publishers ?? new List <SelectListItem>(); model.Publishers = SelectListHandler.Create <Publisher>( publishersRepository.GetAll(), p => p.Name, p => p.ID.ToString(), model.PublisherID.ToString()); return(View(model)); } else { if (model.ID > 0) { book = booksRepository.GetByID(model.ID); } else { book = new Book(); } book.ID = model.ID; book.Title = model.Title; book.PublisherID = model.PublisherID; book.StockCount = model.StockCount; book.DeliveryPrice = model.DeliveryPrice; book.DateReceived = model.DateReceived; book.DatePublished = model.DatePublished; booksRepository.Save(book); } return(RedirectToAction("Index", "Books")); }
public ActionResult EditBook(BooksEditBookVM model) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); BooksRepository booksRepository = new BooksRepository(context); PublishersRepository publishersRepository = new PublishersRepository(context); Book book = null; if (!ModelState.IsValid) { model.Publishers = model.Publishers ?? new List<SelectListItem>(); model.Publishers = SelectListHandler.Create<Publisher>( publishersRepository.GetAll(), p => p.Name, p => p.ID.ToString(), model.PublisherID.ToString()); return View(model); } else { if (model.ID > 0) { book = booksRepository.GetByID(model.ID); } else { book = new Book(); } book.ID = model.ID; book.Title = model.Title; book.PublisherID = model.PublisherID; book.StockCount = model.StockCount; book.DeliveryPrice = model.DeliveryPrice; book.DateReceived = model.DateReceived; book.DatePublished = model.DatePublished; booksRepository.Save(book); } return RedirectToAction("Index", "Books"); }
public ActionResult EditBook(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); BooksRepository booksRepository = new BooksRepository(context); PublishersRepository publishersRepository = new PublishersRepository(context); BooksEditBookVM model = new BooksEditBookVM(); Book book = booksRepository.GetByID(id); if (id > 0) { if (book == null) { return RedirectToAction("Index", "Books"); } model.ID = book.ID; model.Title = book.Title; model.PublisherID = book.Publisher.ID; model.StockCount = book.StockCount; model.DeliveryPrice = book.DeliveryPrice; model.DateReceived = book.DateReceived; model.DatePublished = book.DatePublished; } else { book = new Book(); } model.Publishers = model.Publishers ?? new List<SelectListItem>(); model.Publishers = SelectListHandler.Create<Publisher>( publishersRepository.GetAll(), p => p.Name, p => p.ID.ToString(), model.PublisherID.ToString()); return View(model); }
public ActionResult List() { return(View(publishers.GetAll())); }
public IEnumerable <Publishers> GetAll() { return(_PublishersRepository.GetAll()); }
private void RefreshPublishersAndAuthorsList() { _authorsRepository.GetAll().ForEach(author => authorsListBox.Items.Add(author)); _publishersRepository.GetAll().ForEach(publisher => publishersListBox.Items.Add(publisher)); }
public ActionResult Index(string sortOrder) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); PublishersIndexVM model = new PublishersIndexVM(); this.TryUpdateModel(model); model.PublishersPager = model.PublishersPager ?? new GenericPagerVM(); model.PublishersPager.CurrentPage = model.PublishersPager.CurrentPage == 0 ? 1 : model.PublishersPager.CurrentPage; model.PublishersPager.Action = "Index"; model.PublishersPager.Controller = "Publishers"; model.PublishersPager.Prefix = "PublishersPager"; model.PublishersPager.CurrentParameters = new Dictionary<string, object>() { { "PublisherName", model.PublisherName }, { "PublisherAddress", model.PublisherAddress }, { "PublishersPager.CurrentPage", model.PublishersPager.CurrentPage } }; #region Sorting and Filtering Expression<Func<Publisher, bool>> filter = p => (string.IsNullOrEmpty(model.PublisherName) || p.Name.Contains(model.PublisherName)) && (string.IsNullOrEmpty(model.PublisherAddress) || p.Address.Contains(model.PublisherAddress)); model.PublishersPager.PagesCount = GetPagesCount(filter); ViewBag.PublisherSortParam = string.IsNullOrEmpty(sortOrder) ? "publisher_desc" : ""; ViewBag.AddressSortParam = sortOrder == "Address" ? "address_desc" : "Address"; switch (sortOrder) { case "publisher_desc": model.PublishersList = publishersRepository .GetAll(model.PublishersPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderByDescending(p => p.Name)) .ToList(); break; case "Address": model.PublishersList = publishersRepository .GetAll(model.PublishersPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderBy(p => p.Address)) .ToList(); break; case "address_desc": model.PublishersList = publishersRepository .GetAll(model.PublishersPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderByDescending(p => p.Address)) .ToList(); break; default: model.PublishersList = publishersRepository .GetAll(model.PublishersPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, x => x.OrderBy(p => p.Name)) .ToList(); break; } #endregion return View(model); }