public IActionResult DetailedMProcurement(string SearchTitle, string SearchAuthor, string SearchUniqueID, int SearchGenre, DisplayBooks SelectedStock, SortOrderOpt SortButton)
        {
            List <Book> SelectedBooks = new List <Book>();

            var query = from r in _db.Books select r;

            //title
            if (!string.IsNullOrEmpty(SearchTitle))
            {
                query = query.Where(r => r.Title.Contains(SearchTitle));
            }

            //author
            if (!string.IsNullOrEmpty(SearchAuthor))
            {
                query = query.Where(r => r.Author.Contains(SearchAuthor));
            }

            //unique number
            if (!string.IsNullOrEmpty(SearchUniqueID))
            {
                int intUniqueNumber;
                try
                {
                    intUniqueNumber = Convert.ToInt32(SearchUniqueID);
                }
                catch
                {
                    //Add a message for the viewbag
                    ViewBag.Message = "You must enter a valid unique ID";

                    //re-populate drop down
                    //ViewBag.AllGenres .....

                    //Send user back to home page
                    return(View("DetailedSearch")); //may need to change what goes in ""
                }

                query = query.Where(r => r.UniqueID == intUniqueNumber);
            }



            //genre
            if (SearchGenre != 0) // 0 = they chose "all genres" from the drop-down
            {
                Genre GenreToDisplay = _db.Genres.Find(SearchGenre);
                query = query.Where(r => r.Genre == GenreToDisplay);
            }


            //selected books - all or in stock only
            switch (SelectedStock)
            {
            case DisplayBooks.AllBooks:
                break;

            case DisplayBooks.InStock:
                query = query.Where(r => r.Inventory > 0);
                break;

            default:
                break;
            }

            SelectedBooks = query.ToList();
            ViewBag.SelectedBooksCount = SelectedBooks.Count();
            ViewBag.TotalBooks         = _db.Books.Count();

            switch (SortButton)
            {
            case SortOrderOpt.DontSort: break;

            case SortOrderOpt.Title:
                return(View("Index", SelectedBooks.OrderBy(r => r.Title)));

            case SortOrderOpt.Author:
                return(View("Index", SelectedBooks.OrderBy(r => r.Author)));

            case SortOrderOpt.MostPopular:
                return(View("Index", SelectedBooks.OrderBy(r => r.BookID)));

            case SortOrderOpt.Newest:
                return(View("Index", SelectedBooks.OrderByDescending(r => r.PublishDate)));

            case SortOrderOpt.Oldest:
                return(View("Index", SelectedBooks.OrderBy(r => r.PublishDate)));

            case SortOrderOpt.HighestRating:
                return(View("Index", SelectedBooks.OrderByDescending(r => r.AvgRating)));
            }


            SelectedBooks = query.Include(r => r.Reviews).Include(r => r.Genre).ToList();
            ViewBag.SelectedBooksCount = SelectedBooks.Count();
            ViewBag.TotalBooks         = _db.Books.Count();


            List <Procurement> allprocs = new List <Procurement>();
            var procquery = from p in _db.Procurements select p;

            procquery = procquery.Include(p => p.Book).Include(p => p.Employee);
            allprocs  = procquery.ToList();

            String  strUserId = User.Identity.Name;
            AppUser apvmuser  = _db.Users.FirstOrDefault(u => u.UserName == strUserId);

            List <AddProcurementVM> BooksToOrder = new List <AddProcurementVM>();

            foreach (Book book in SelectedBooks)
            {
                AddProcurementVM apvm = new AddProcurementVM();
                apvm.Title                = book.Title;
                apvm.ProcurementDate      = System.DateTime.Today;
                apvm.BookID               = book.BookID;
                apvm.Author               = book.Author;
                apvm.AvgRatingProc        = (decimal)book.AvgRating;
                apvm.PublishDate          = book.PublishDate;
                apvm.Cost                 = book.BookCost;
                apvm.userID               = User.Identity.Name;
                apvm.Inventory            = book.Inventory;
                apvm.InventoryMinimum     = book.ReplenishMinimum;
                apvm.SellingPrice         = book.SalesPrice;
                apvm.ProfitMargin         = ((Decimal)book.AvgSalesPrice - (Decimal)book.AvgBookCost);
                apvm.IncludeInProcurement = false;
                apvm.QuantityToOrder      = 5;
                BooksToOrder.Add(apvm);

                foreach (Procurement proc in allprocs)
                {
                    if (proc.ProcurementStatus == false)
                    {
                        if (book.BookID == proc.Book.BookID)
                        {
                            BooksToOrder.Remove(apvm);
                        }
                    }
                }
            }
            if (BooksToOrder.Count == 0)
            {
                ViewBag.SelectedBooksCount = 0;
            }
            ViewBag.DetailedMError = "";
            return(View(BooksToOrder));
        }
Example #2
0
        public IActionResult SearchResults(string SearchTitle, string SearchAuthor, string SearchUniqueID, int SearchGenre, DisplayBooks SelectedStock, SortOrderOpt SortButton)
        {
            List <OrderDetail> OrderDetailList = new List <OrderDetail>();
            var odquery = _db.OrderDetails.Include(o => o.Book).ThenInclude(o => o.Reviews).Include(o => o.Order).ThenInclude(o => o.Customer);

            OrderDetailList = odquery.ToList();


            List <Book> SelectedBooks = new List <Book>();

            var query = from r in _db.Books select r;

            //title
            if (!string.IsNullOrEmpty(SearchTitle))
            {
                query = query.Where(r => r.Title.Contains(SearchTitle));
            }

            //author
            if (!string.IsNullOrEmpty(SearchAuthor))
            {
                query = query.Where(r => r.Author.Contains(SearchAuthor));
            }

            //unique number
            if (!string.IsNullOrEmpty(SearchUniqueID))
            {
                int intUniqueNumber;
                try
                {
                    intUniqueNumber = Convert.ToInt32(SearchUniqueID);
                }
                catch
                {
                    //Add a message for the viewbag
                    ViewBag.Message = "You must enter a valid unique ID";

                    //re-populate drop down
                    //ViewBag.AllGenres .....

                    //Send user back to home page
                    return(View("DetailedSearch")); //may need to change what goes in ""
                }

                query = query.Where(r => r.UniqueID == intUniqueNumber);
            }



            //genre
            if (SearchGenre != 0) // 0 = they chose "all genres" from the drop-down
            {
                Genre GenreToDisplay = _db.Genres.Find(SearchGenre);
                query = query.Where(r => r.Genre == GenreToDisplay);
            }


            //selected books - all or in stock only
            switch (SelectedStock)
            {
            case DisplayBooks.AllBooks:
                break;

            case DisplayBooks.InStock:
                query = query.Where(r => r.Inventory > 0);
                break;

            default:
                break;
            }

            query         = query.Include(r => r.Reviews);
            SelectedBooks = query.ToList();

            List <SearchVM> searchVms = new List <SearchVM>();

            //MAKING THE ORDER DETAIL and checking which is most popular
            foreach (Book book in SelectedBooks)
            {
                List <Review> reviewslist = new List <Review>();

                var revquery = from r in _db.Reviews select r;
                revquery    = revquery.Where(r => r.ApprovalStatus == true);
                revquery    = revquery.Include(r => r.Book);
                reviewslist = revquery.ToList();

                SearchVM svm = new SearchVM();
                svm.BookID     = book.BookID;
                svm.Title      = book.Title;
                svm.Author     = book.Author;
                svm.AvgRating  = (decimal)book.AvgRating;
                svm.SalesPrice = book.SalesPrice;
                if (book.Inventory > 0)
                {
                    svm.InStock = true;
                }
                if (book.Inventory <= 0)
                {
                    svm.InStock = false;
                }
                svm.IsDiscontinued = book.IsDiscontinued;
                svm.UniqueNumber   = book.UniqueID;
                svm.BookDetail     = book.BookDetail;
                svm.AvgRating      = (decimal)book.AvgRating;

                Int32 intCountOrdered = 0;
                foreach (OrderDetail od in OrderDetailList)
                {
                    if (od.Book.BookID == book.BookID)
                    {
                        intCountOrdered += od.Quantity;
                    }
                }
                svm.QuantityOrdered = intCountOrdered;
                svm.PublishDate     = book.PublishDate;
                searchVms.Add(svm);
            }

            //populate viewbags
            ViewBag.SelectedBooksCount = searchVms.Count();
            ViewBag.TotalBooks         = _db.Books.Count();
            ViewBag.OutofStock         = "Out of Stock. Check Back Soon!";
            ViewBag.InStock            = "In Stock";

            switch (SortButton)
            {
            case SortOrderOpt.DontSort: break;

            case SortOrderOpt.Title:
                return(View("ViewModelIndex", searchVms.OrderBy(r => r.Title)));

            case SortOrderOpt.Author:
                return(View("ViewModelIndex", searchVms.OrderBy(r => r.Author)));

            case SortOrderOpt.MostPopular:
                return(View("ViewModelIndex", searchVms.OrderByDescending(r => r.QuantityOrdered)));

            case SortOrderOpt.Newest:
                return(View("ViewModelIndex", searchVms.OrderByDescending(r => r.PublishDate)));

            case SortOrderOpt.Oldest:
                return(View("ViewModelIndex", searchVms.OrderBy(r => r.PublishDate)));

            case SortOrderOpt.HighestRating:
                return(View("ViewModelIndex", searchVms.OrderByDescending(r => r.AvgRating)));
            }

            ViewBag.OutofStock         = "Out of Stock. Check Back Soon!";
            ViewBag.InStock            = "In Stock";
            SelectedBooks              = query.ToList();
            ViewBag.SelectedBooksCount = searchVms.Count();
            ViewBag.TotalBooks         = _db.Books.Count();
            //ViewBag.SelectedBooksSearch = SelectedBooksSearch.Count();


            //want to see if this book is already in their cart



            return(View("ViewModelIndex", searchVms));
        }
Example #3
0
        public IActionResult SearchResults(string SearchTitle, string SearchAuthor, string SearchUniqueID, int SearchGenre, DisplayBooks SelectedStock, SortOrderOpt SortButton)
        {
            List <Book> SelectedBooks = new List <Book>();

            var query = from r in _db.Books select r;

            //title
            if (!string.IsNullOrEmpty(SearchTitle))
            {
                query = query.Where(r => r.Title.Contains(SearchTitle));
            }

            //author
            if (!string.IsNullOrEmpty(SearchAuthor))
            {
                query = query.Where(r => r.Author.Contains(SearchAuthor));
            }

            //unique number
            if (!string.IsNullOrEmpty(SearchUniqueID))
            {
                int intUniqueNumber;
                try
                {
                    intUniqueNumber = Convert.ToInt32(SearchUniqueID);
                }
                catch
                {
                    //Add a message for the viewbag
                    ViewBag.Message = "You must enter a valid unique ID";

                    //re-populate drop down
                    //ViewBag.AllGenres .....

                    //Send user back to home page
                    return(View("DetailedSearch")); //may need to change what goes in ""
                }

                query = query.Where(r => r.UniqueID == intUniqueNumber);
            }



            //genre
            if (SearchGenre != 0) // 0 = they chose "all genres" from the drop-down
            {
                Genre GenreToDisplay = _db.Genres.Find(SearchGenre);
                query = query.Where(r => r.Genre == GenreToDisplay);
            }


            //selected books - all or in stock only
            switch (SelectedStock)
            {
            case DisplayBooks.AllBooks:
                break;

            case DisplayBooks.InStock:
                query = query.Where(r => r.Inventory > 0);
                break;

            default:
                break;
            }

            SelectedBooks = query.ToList();
            ViewBag.SelectedBooksCount = SelectedBooks.Count();
            ViewBag.TotalBooks         = _db.Books.Count();

            switch (SortButton)
            {
            case SortOrderOpt.DontSort: break;

            case SortOrderOpt.Title:
                return(View("Index", SelectedBooks.OrderBy(r => r.Title)));

            case SortOrderOpt.Author:
                return(View("Index", SelectedBooks.OrderBy(r => r.Author)));

            case SortOrderOpt.MostPopular:
                return(View("Index", SelectedBooks.OrderBy(r => r.BookID)));

            case SortOrderOpt.Newest:
                return(View("Index", SelectedBooks.OrderByDescending(r => r.PublishDate)));

            case SortOrderOpt.Oldest:
                return(View("Index", SelectedBooks.OrderBy(r => r.PublishDate)));

            case SortOrderOpt.HighestRating:
                return(View("Index", SelectedBooks.OrderByDescending(r => r.AvgRating)));
            }


            SelectedBooks = query.ToList();
            ViewBag.SelectedBooksCount = SelectedBooks.Count();
            ViewBag.TotalBooks         = _db.Books.Count();
            //ViewBag.SelectedBooksSearch = SelectedBooksSearch.Count();
            return(View("Index", SelectedBooks));
        }