Exemplo n.º 1
0
        public async Task <ActionResult> AddBooks(RegisterBookVM model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("BooksCategory"));
            }

            var bookModel = _mapper.Map <BookModel>(model);

            bookModel.BookCategory = new BooksCategoryModel
            {
                Name       = model.SelectedCategoryText,
                CategoryId = model.SelectedCategory
            };
            bookModel.MainImageFileName = model.MainImageFileName.FileName;

            var cachedBooks = await GetBooks();

            cachedBooks.Add(bookModel);

            await SaveBookImage(model.MainImageFileName);

            _cacheManager.Set("LibraryBooks", cachedBooks);

            return(RedirectToAction("RegisterBook"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> RegisterBook()
        {
            if (string.IsNullOrEmpty(LoggedInName()) || !IsAllowed(UserLevel.AccessArea.LibraryAdmin))
            {
                return(RedirectToAction("Login", "User"));
            }

            _booksCategories = await GetBooksCategories();

            var model = new RegisterBookVM
            {
                Categories = _booksCategories.Select(g => new SelectListItem {
                    Text = g.Name, Value = g.CategoryId
                }).ToList(),
                NewsBooks = await GetBooks()
            };

            return(View(model));
        }