Esempio n. 1
0
        // GET: Books
        public async Task <IActionResult> Index(string bookcategory, string searchstr)
        {
            IQueryable <string> categoryquery = from b in _context.Books
                                                orderby b.Category
                                                select b.Category;
            var books = from b in _context.Books
                        select b;

            if (!String.IsNullOrEmpty(searchstr))
            {
                books = books.Where(b => b.Btitle.Contains(searchstr));
            }
            if (!String.IsNullOrEmpty(bookcategory))
            {
                books = books.Where(x => x.Category == bookcategory);
            }
            var bookCategoryVM = new BookCategoryViewModel
            {
                Categories = new SelectList(await categoryquery.Distinct().ToListAsync()),
                Books      = await books.ToListAsync()
            };

            return(View(bookCategoryVM));
            //return View(await _context.Books.ToListAsync());
        }
Esempio n. 2
0
        // GET: Books

        // GET: Movies
        public async Task <IActionResult> Index(string bookCategory, string searchString)
        {
            // Use LINQ to get list of book categories.
            IQueryable <string> categoryQuery = from m in _context.Book
                                                orderby m.Category
                                                select m.Category;

            var books = from m in _context.Book
                        select m;

            if (!string.IsNullOrEmpty(searchString))
            {
                books = books.Where(s => s.Title.Contains(searchString));
            }

            if (!string.IsNullOrEmpty(bookCategory))
            {
                books = books.Where(x => x.Category == bookCategory);
            }

            var bookCategoryVM = new BookCategoryViewModel
            {
                Category = new SelectList(await categoryQuery.Distinct().ToListAsync()),
                Books    = await books.ToListAsync()
            };

            return(View(bookCategoryVM));
        }
        // GET: Book
        public async Task <IActionResult> Index(string bookCate, string searchString)
        {
            // Use LINQ to get list of genres.
            IQueryable <string> catteQuery = from b in _context.Books
                                             join c in _context.Categories on b.CategoryId equals c.CategoryId
                                             select b.Name;

            var books = from b in _context.Books
                        select b;


            if (!string.IsNullOrEmpty(searchString))
            {
                books = books.Where(b => b.Name.Contains(searchString));
            }

            if (!string.IsNullOrEmpty(bookCate))
            {
                books = books.Where(b => b.Name == bookCate);
            }
            var bcVM = new BookCategoryViewModel
            {
                Cate  = new SelectList(await catteQuery.Distinct().ToListAsync()),
                Books = await books.ToListAsync()
            };

            ViewBag.books = _context.Books.Include(b => b.Category);

            return(View(bcVM));
        }
 public ActionResult Create(BookCategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         var check = db.BookCategories.Where(x => x.Name == model.Name).FirstOrDefault();
         if (check == null)
         {
             BookCategory bookCategory = new BookCategory()
             {
                 Name      = model.Name,
                 Slug      = Slugify.GenerateSlug(model.Name),
                 CreatedAt = DateTime.Now,
                 UpdatedAt = DateTime.Now
             };
             db.BookCategories.Add(bookCategory);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ViewBag.statusCheck = "Name already exists";
         }
     }
     return(View());
 }
Esempio n. 5
0
        private List <string> GetAllPropertyNameOfBookCategoryViewModel()
        {
            var bookCategoryViewModel = new BookCategoryViewModel();

            var type = bookCategoryViewModel.GetType();

            return(ReflectionUtilities.GetAllPropertyNamesOfType(type));
        }
        public BookCategoryViewModel Add(BookCategoryViewModel BookCategoryViewModel)
        {
            var bookCategory = Mapper.Map <BookCategoryViewModel, BookCategory>(BookCategoryViewModel);

            _bookCategoryRepository.Add(bookCategory);
            _unitOfWork.Commit();
            return(BookCategoryViewModel);
        }
        public void Update(BookCategoryViewModel BookCategoryViewModel)
        {
            var temp = _bookCategoryRepository.FindById(BookCategoryViewModel.KeyId);

            if (temp != null)
            {
                temp.BookCategoryName = BookCategoryViewModel.BookCategoryName;
            }
        }
 public ActionResult Update(BookCategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         var bookCategory = new BookCategory();
         bookCategory.UpdateBookCategory(model);
         _bookCategoryService.Update(bookCategory);
         _context.SaveChanges();
         ViewData["successMsg"] = "Sua thành công";
     }
     return(View(model));
 }
Esempio n. 9
0
        // GET: Books/Create
        public async Task <IActionResult> CreateAsync()
        {
            SelectList selectLists    = new SelectList(await _context.Categories.OrderBy(c => c.Name).ToListAsync(), "Id", "Name");
            var        BookCategoryVM = new BookCategoryViewModel
            {
                Categorys = selectLists,
                Book      = new Book()
            };

            ViewData["CategoryId"] = new SelectList(_context.Categories.OrderBy(c => c.Name), "Id", "Name");
            return(View(BookCategoryVM));
        }
Esempio n. 10
0
 public static void UpdateBookCategory(this BookCategory bookCategory, BookCategoryViewModel bookCategoryViewModel)
 {
     bookCategory.ID          = bookCategoryViewModel.ID;
     bookCategory.Name        = bookCategoryViewModel.Name;
     bookCategory.Image       = bookCategoryViewModel.Image;
     bookCategory.Description = bookCategoryViewModel.Description;
     bookCategory.HomeFlag    = bookCategoryViewModel.HomeFlag;
     bookCategory.CreateDate  = bookCategoryViewModel.CreateDate;
     bookCategory.CreateBy    = bookCategoryViewModel.CreateBy;
     bookCategory.UpdateDate  = bookCategoryViewModel.UpdateDate;
     bookCategory.UpdateBy    = bookCategoryViewModel.UpdateBy;
     bookCategory.Status      = bookCategoryViewModel.Status;
 }
Esempio n. 11
0
 public PublishBookViewModel(PublishBook publishBook) : this()
 {
     if (publishBook != null)
     {
         Id   = publishBook.Id;
         Name = publishBook.Name;
         Time = publishBook.Time;
         PlaceOfPublication = publishBook.PlaceOfPublication;
         BookCategory       = new BookCategoryViewModel(publishBook.BookCategory);
         Lecturers          = GetLecturer(publishBook);
         //User = new UserViewModel(publishBook.User);
         //Lecturer = new LecturerViewModel;
     }
 }
        // GET: Books
        public async Task <IActionResult> Index(string bookcategory, string searchstr, string Publisherdet)
        {
            IQueryable <string> categoryquery = from b in _context.Books
                                                orderby b.Category
                                                select b.Category;
            IQueryable <string> Publisherquery = from b in _context.Books
                                                 orderby b.Publisher
                                                 select b.Publisher;
            //above LINQ query to get Categerirs from book                                select b.Category;
            var books = from b in _context.Books
                        select b;

            if (!string.IsNullOrEmpty(searchstr))
            {
                books = books.Where(b => b.BTitle.Contains(searchstr));
            }
            if (!string.IsNullOrEmpty(bookcategory))
            {
                books = books.Where(x => x.Category == bookcategory);
            }
            if (!string.IsNullOrEmpty(Publisherdet))
            {
                books = books.Where(x => x.Publisher == Publisherdet);
            }
            var bookcategoryVM = new BookCategoryViewModel
            {
                Categories = new SelectList(await categoryquery.Distinct().ToListAsync()),
                Publishers = new SelectList(await Publisherquery.Distinct().ToListAsync()),
                Books      = await books.ToListAsync()
                             //  Books = await books.ToListAsync()
            };

            /*  var publisgVm = new BookCategoryViewModel
             * {
             *    Publishers = new SelectList(await Publisherquery.Distinct().ToListAsync()),
             *
             * };*/
            return(View(bookcategoryVM));



            // return View(await _context.Books.ToListAsync());
        }
Esempio n. 13
0
        public async Task <IActionResult> Create([Bind("Title,Description,Author,Year,CategoryId,PublishingCompany,Rented,Id,DateCriation,DateUpdate,Excluded")] Book book)
        {
            if (ModelState.IsValid)
            {
                book.Id = Guid.NewGuid();
                _context.Books.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            SelectList selectLists    = new SelectList(await _context.Categories.OrderBy(c => c.Name).ToListAsync(), "Id", "Name");
            var        BookCategoryVM = new BookCategoryViewModel
            {
                Categorys = selectLists,
                Book      = new Book()
            };

            ViewData["CategoryId"] = new SelectList(_context.Categories.OrderBy(c => c.Name), "Id", "Name");
            return(View(book));
        }
Esempio n. 14
0
        public BookCategoryViewModel GetBookCategory(int id)
        {
            var bookCategory = this.DbContext
                               .BookCategories
                               .Include(x => x.Books)
                               .FirstOrDefault(x => x.Id == id);

            if (bookCategory == null)
            {
                return(null);
            }

            var bookCategoryModel = new BookCategoryViewModel()
            {
                BookCategoryName = bookCategory.BookCategoryName,
                Books            = this.Mapper.Map <ICollection <BookConciseViewModel> >(bookCategory.Books)
            };

            return(bookCategoryModel);
        }
 public IActionResult SaveEntity(BookCategoryViewModel bookCategoryVm)
 {
     if (!ModelState.IsValid)
     {
         IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
         return(new BadRequestObjectResult(allErrors));
     }
     else
     {
         if (bookCategoryVm.KeyId == 0)
         {
             _bookCategoryService.Add(bookCategoryVm);
         }
         else
         {
             _bookCategoryService.Update(bookCategoryVm);
         }
         _bookCategoryService.Save();
         return(new OkObjectResult(bookCategoryVm));
     }
 }
 public ActionResult Edit(BookCategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         var check = db.BookCategories.Where(x => x.Name == model.Name).FirstOrDefault();
         if (check == null)
         {
             var category = db.BookCategories.Where(x => x.Id == model.Id).FirstOrDefault();
             category.Name            = model.Name;
             category.Slug            = Slugify.GenerateSlug(model.Name);
             category.UpdatedAt       = DateTime.Now;
             db.Entry(category).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ViewBag.statusCheck = "Name already exists";
         }
     }
     return(View());
 }