Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
 private async Task <AddUserModel> GetAddUserModel()
 {
     return(new AddUserModel
     {
         UserSelectListItems =
             SelectListHandler.CreateFromUsers(_identity.GetUsers().ToList(), _currentUserService.UserId),
         CurrentUserName = await _identity.GetUserNameAsync(_currentUserService.UserId),
         CurrentUserId = _currentUserService.UserId
     });
 }
Exemplo n.º 3
0
        private async Task <CreateReceiptItemVm> CreateReceiptItemVm(IList <UserDto> users)
        {
            var itemGroupQuery = new GetItemGroupQuery();

            var itemGroups = await Mediator.Send(itemGroupQuery);

            return(new CreateReceiptItemVm
            {
                AddUserModel = new AddUserModel
                {
                    UserSelectListItems = SelectListHandler.CreateFromUsers(users),
                },
                TypesSelectListItems = SelectListHandler.CreateFromItemGroup(itemGroups),
            });
        }
Exemplo n.º 4
0
        public ActionResult AddBookAuthor(int id)
        {
            LibraryManagementSystemContext context = new LibraryManagementSystemContext();
            BooksRepository      booksRepository   = new BooksRepository(context);
            AuthorsRepository    authorsRepository = new AuthorsRepository(context);
            BooksAddBookAuthorVM model             = new BooksAddBookAuthorVM();

            Book book = booksRepository.GetByID(id);

            model.ID      = book.ID;
            model.Title   = book.Title;
            model.Authors = model.Authors ?? new List <SelectListItem>();
            model.Authors = SelectListHandler.Create <Author>(
                authorsRepository.GetAll(), a => (a.FirstName + " " + a.LastName), a => a.ID.ToString(), model.AuthorID.ToString());

            return(View(model));
        }
Exemplo n.º 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"));
        }