コード例 #1
0
        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();
        }
コード例 #2
0
 public ActionResult Create()
 {
     ViewBag.publishers = publishers.GetAll();
     ViewBag.authors    = authors.GetAll();
     ViewBag.page       = "Create";
     return(View("Edit", new Book()));
 }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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"));
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 public ActionResult List()
 {
     return(View(publishers.GetAll()));
 }
コード例 #9
0
 public IEnumerable <Publishers> GetAll()
 {
     return(_PublishersRepository.GetAll());
 }
コード例 #10
0
 private void RefreshPublishersAndAuthorsList()
 {
     _authorsRepository.GetAll().ForEach(author => authorsListBox.Items.Add(author));
     _publishersRepository.GetAll().ForEach(publisher => publishersListBox.Items.Add(publisher));
 }
コード例 #11
0
        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);
        }