示例#1
0
        public ActionResult EditBarcode(BarcodesEditBarcodeVM model)
        {
            LibraryManagementSystemContext context            = new LibraryManagementSystemContext();
            BarcodesRepository             barcodesRepository = new BarcodesRepository(context);

            Barcode barcode = null;

            if (barcodesRepository.GetAll().Any(b => b.BarcodeNumber == model.BarcodeNumber) &&
                model.ID != barcodesRepository.GetAll(filter: b => b.BarcodeNumber == model.BarcodeNumber).FirstOrDefault().ID)
            {
                ModelState.AddModelError("BarcodeNumber", "* barcode already exists");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                if (model.ID > 0)
                {
                    barcode = barcodesRepository.GetByID(model.ID);
                }
                else
                {
                    barcode = new Barcode();
                }

                barcode.ID            = model.ID;
                barcode.BookID        = model.BookID;
                barcode.BarcodeNumber = model.BarcodeNumber;

                barcodesRepository.Save(barcode);
            }

            return(RedirectToAction("ListBookBarcodes/" + barcode.BookID, "Books"));
        }
示例#2
0
        public ActionResult ListBookBarcodes(int id)
        {
            LibraryManagementSystemContext context     = new LibraryManagementSystemContext();
            BooksRepository         booksRepository    = new BooksRepository(context);
            BarcodesRepository      barcodesRepository = new BarcodesRepository(context);
            BooksListBookBarcodesVM model = new BooksListBookBarcodesVM();

            this.TryUpdateModel(model);

            var book = booksRepository.GetByID(id);

            if (book != null)
            {
                model.BookID                    = book.ID;
                model.BookTitle                 = book.Title;
                model.BarcodesPager             = model.BarcodesPager ?? new GenericPagerVM();
                model.BarcodesPager.PagesCount  = GetPagesCount();
                model.BarcodesPager.CurrentPage =
                    model.BarcodesPager.CurrentPage == 0 ? 1 : model.BarcodesPager.CurrentPage;
                model.Barcodes = barcodesRepository
                                 .GetAll(model.BarcodesPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, b => b.BookID == id)
                                 .ToList();
                model.BarcodesPager.Action            = "Index";
                model.BarcodesPager.Controller        = "Books";
                model.BarcodesPager.Prefix            = "BarcodesPager";
                model.BarcodesPager.CurrentParameters = new Dictionary <string, object>()
                {
                    { "BarcodesPager.CurrentPage", model.BarcodesPager.CurrentPage }
                };

                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index", "Books"));
            }
        }
        public ActionResult EditBarcode(BarcodesEditBarcodeVM model)
        {
            LibraryManagementSystemContext context = new LibraryManagementSystemContext();
            BarcodesRepository barcodesRepository = new BarcodesRepository(context);

            Barcode barcode = null;
            if (barcodesRepository.GetAll().Any(b => b.BarcodeNumber == model.BarcodeNumber) &&
                model.ID != barcodesRepository.GetAll(filter: b => b.BarcodeNumber == model.BarcodeNumber).FirstOrDefault().ID)
            {
                ModelState.AddModelError("BarcodeNumber", "* barcode already exists");
            }
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            else
            {
                if (model.ID > 0)
                {
                    barcode = barcodesRepository.GetByID(model.ID);
                }
                else
                {
                    barcode = new Barcode();
                }

                barcode.ID = model.ID;
                barcode.BookID = model.BookID;
                barcode.BarcodeNumber = model.BarcodeNumber;

                barcodesRepository.Save(barcode);
            }

            return RedirectToAction("ListBookBarcodes/" + barcode.BookID, "Books");
        }
        public ActionResult ListBookBarcodes(int id)
        {
            LibraryManagementSystemContext context = new LibraryManagementSystemContext();
            BooksRepository booksRepository = new BooksRepository(context);
            BarcodesRepository barcodesRepository = new BarcodesRepository(context);
            BooksListBookBarcodesVM model = new BooksListBookBarcodesVM();
            this.TryUpdateModel(model);

            var book = booksRepository.GetByID(id);
            if (book != null)
            {
                model.BookID = book.ID;
                model.BookTitle = book.Title;
                model.BarcodesPager = model.BarcodesPager ?? new GenericPagerVM();
                model.BarcodesPager.PagesCount = GetPagesCount();
                model.BarcodesPager.CurrentPage =
                    model.BarcodesPager.CurrentPage == 0 ? 1 : model.BarcodesPager.CurrentPage;
                model.Barcodes = barcodesRepository
                    .GetAll(model.BarcodesPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, b => b.BookID == id)
                    .ToList();
                model.BarcodesPager.Action = "Index";
                model.BarcodesPager.Controller = "Books";
                model.BarcodesPager.Prefix = "BarcodesPager";
                model.BarcodesPager.CurrentParameters = new Dictionary<string, object>()
                {
                    { "BarcodesPager.CurrentPage", model.BarcodesPager.CurrentPage }
                };

                return View(model);
            }
            else
            {
                return RedirectToAction("Index", "Books");
            }
        }