Example #1
0
        public IActionResult All()
        {
            List <Product> products = context.Products.ToList();

            List <AllProductViewModel> productsViewModels = new List <AllProductViewModel>();

            foreach (Product product in products)
            {
                int     productId = product.Id;
                string  name      = product.Name;
                decimal price     = product.Price;
                long    barcode   = product.Barcode;
                string  picture   = product.Picture;

                AllProductViewModel productViewModel = new AllProductViewModel()
                {
                    Id      = productId,
                    Name    = name,
                    Price   = price,
                    Barcode = barcode,
                    Picture = picture,
                };
                productsViewModels.Add(productViewModel);
            }

            this.Model["Products"] = productsViewModels;
            return(this.View());
        }
        public IActionResult CreateProduct(AllProductViewModel product)
        {
            if (ModelState.IsValid)
            {
                string fileName = "../img/Catalog/" + _books.UpLoadFile(product.ImgFile);
                _books.CreateBook(new Book
                {
                    NameBook           = product.NameBook,
                    NormalizedNameBook = product.NameBook.ToUpper(),
                    AuthorId           = Int32.Parse(Request.Form.FirstOrDefault(o => o.Key == "authors").Value.ToString()),
                    Annotation         = product.Annotation,
                    PublishingHouse    = product.PublishingHouse,
                    Img        = fileName,
                    Price      = product.Price,
                    Year       = product.Year,
                    IsFavorite = product.IsFavorite,
                    IsNew      = product.IsNew,
                    IsStock    = product.IsStock,
                    GenreId    = Int32.Parse(Request.Form.FirstOrDefault(o => o.Key == "genres").Value.ToString())
                });
                return(RedirectToAction("AllProduct"));
            }

            else
            {
                product.Genres  = _genre.AllGenres;
                product.Authors = _author.AllAuthors;
                return(View(product));
            }
        }
        public IActionResult CreateProduct()
        {
            var obj = new AllProductViewModel()
            {
                Authors = _author.AllAuthors,
                Genres  = _genre.AllGenres
            };

            return(View(obj));
        }
Example #4
0
        public IActionResult All(int page = 0)
        {
            var viewModel = new AllProductViewModel
            {
                Page     = page,
                Products = logic.GetAll(page)
            };

            return(View(viewModel));
        }
        public IActionResult DeleteProduct(AllProductViewModel product)
        {
            var book = _books.GetBookById(product.Id);

            if (book != null)
            {
                _books.DeleteBook(book);
            }
            return(RedirectToAction("AllProduct"));
        }
Example #6
0
        public IActionResult Category(string category, int page)
        {
            var viewModel = new AllProductViewModel
            {
                Page     = page,
                Category = category,
                Products = logic.GetCategoryProducts(category, page)
            };

            return(View(viewModel));
        }
Example #7
0
        public IActionResult Search(string search, int page)
        {
            var viewModel = new AllProductViewModel
            {
                Page     = page,
                Search   = search,
                Products = logic.GetSearchedProducts(search, page)
            };

            return(View(viewModel));
        }
Example #8
0
        public IActionResult AllProduct()
        {
            var result = new AllProductViewModel()
            {
                All = this.adminServices.AllProducts()
            };

            if (result == null)
            {
                this.ViewBag.Error = "The result is null";
                return(View());
            }
            return(View(result));
        }
        public IActionResult Details(int id)
        {
            var receipt = context.Receipts.FirstOrDefault(r => r.Id == id);

            var user = context.Users.FirstOrDefault(u => u.Id == receipt.CashierId);


            var orders   = context.Orders;
            var products = context.Products;

            var actualReceiptOrders = context.ReceiptsOrders.Where(ro => ro.ReceiptId == receipt.Id);
            var orderIds            = actualReceiptOrders.Select(ro => ro.OrderId).ToList();

            List <Order> ordersList = new List <Order>();

            foreach (var orderId in orderIds)
            {
                var order = orders.FirstOrDefault(o => o.Id == orderId);
                ordersList.Add(order);
            }

            List <AllProductViewModel> productsViewModels = new List <AllProductViewModel>();
            decimal total = 0;

            foreach (Order order in ordersList)
            {
                var product = products.FirstOrDefault(p => p.Id == order.ProductId);
                AllProductViewModel productViewModel = new AllProductViewModel()
                {
                    Id      = product.Id,
                    Barcode = product.Barcode,
                    Name    = product.Name,
                    Picture = product.Picture,
                    Price   = product.Price
                };
                productsViewModels.Add(productViewModel);

                total += product.Price * order.Quantity;
            }

            this.Model["Products"] = productsViewModels;
            this.Model["Total"]    = total;
            this.Model["Cashier"]  = user.Username;
            this.Model["IssuedOn"] = receipt.IssuedOn.ToShortDateString();
            this.Model["Receipt"]  = receipt.Id;

            return(this.View());
        }
        public ActionResult IndexCategory(int Id)
        {
            var model        = new List <AllProductViewModel>();
            var modelService = new ProductService();
            var products     = modelService.GetProductsByCategory(Id);

            foreach (var item in products)
            {
                var product = new AllProductViewModel();
                product.Id      = item.Id;
                product.Image   = String.Concat(Url.Content("~/Content/images/Product/"), item.Image, ".jpg");
                product.Title   = item.Title;
                product.Price   = item.Price;
                product.Balance = item.Balance;
                model.Add(product);
            }
            ViewData["CategoryId"] = Id;
            return(View("Index", model));
        }
Example #11
0
        //THis function show the product whose quantity is less 15
        public ActionResult ProductTable(string search, int?pageNo)
        {
            AllProductViewModel model   = new AllProductViewModel();
            ProductHandler      handler = new ProductHandler();

            model.SearchItem = search;
            pageNo           = pageNo.HasValue ? pageNo.Value > 0 ? pageNo.Value : 1 : 1;

            var totalRecord = handler.GetProductCount(search);

            model.productList = handler.GetAllProducts(search, pageNo.Value);

            if (model.productList != null)
            {
                model.Pager = new Pager(totalRecord, pageNo, 6);
                return(PartialView("_ProductTable", model));
            }

            return(PartialView("_ProductTable", model));
        }
Example #12
0
        public IActionResult SearchProduct(string searchProduct)
        {
            if (!String.IsNullOrEmpty(searchProduct))
            {
                var result = new AllProductViewModel()
                {
                    All = this.adminServices.SearchProduct(searchProduct)
                };

                if (result == null)
                {
                    this.TempData["Error"] = "Product whith name is not found !!!";
                    return(RedirectToAction(nameof(AllProduct)));
                }
                return(View("AllProduct", result));
            }

            this.TempData["Error"] = "Search string is null or empty !!!";
            return(RedirectToAction(nameof(AllProduct)));
        }
        public IActionResult DeleteProduct(int BookId)
        {
            var book = _books.GetBookById(BookId);
            var obj  = new AllProductViewModel
            {
                Id              = BookId,
                NameBook        = book.NameBook,
                Author          = _author.AllAuthors.FirstOrDefault(a => a.Id == book.AuthorId).NameAuthor,
                Genre           = _genre.AllGenres.FirstOrDefault(g => g.Id == book.GenreId).NameGenre,
                Annotation      = book.Annotation,
                Img             = book.Img,
                PublishingHouse = book.PublishingHouse,
                Price           = book.Price,
                Year            = book.Year,
                IsNew           = book.IsNew,
                IsStock         = book.IsStock,
                IsFavorite      = book.IsFavorite
            };

            return(View(obj));
        }
        public ActionResult IndexUser(string sortOrder, string searchTitle, int?searchminPrice, int?searchmaxPrice, int?page, int?pSize)
        {
            //================================== Viewbags ====================================
            ViewBag.CurrentTitle     = searchTitle;
            ViewBag.CurrentMinPrice  = searchminPrice;
            ViewBag.CurrentMaxPrice  = searchmaxPrice;
            ViewBag.CurrentSortOrder = sortOrder;
            ViewBag.CurrentpSize     = pSize;

            //Viebag that holds the sorting
            ViewBag.TitleSortParam = String.IsNullOrWhiteSpace(sortOrder) ? "TitleDesc" : "";
            ViewBag.PriceSortParam = sortOrder == "PriceAsc" ? "PriceDesc" : "PriceAsc";

            ViewBag.TitleView = "badge badge-light";
            ViewBag.PriceView = "badge badge-light";

            AllProductViewModel allProductVM = new AllProductViewModel();

            //============================  Get all the eshop categories ====================
            var homes       = unitOfWork.Homes.GetAll();
            var cares       = unitOfWork.Cares.GetAll();
            var foodHerbs   = unitOfWork.FoodHerbs.GetAll();
            var supplements = unitOfWork.Supplements.GetAll();

            //================================== Sorting ====================================


            //Pagination
            int pageSize   = pSize ?? 3;
            int pageNumber = page ?? 1;


            // Assign the sorting - searching to the viewModel
            allProductVM.HomeProducts       = homes.ToPagedList(pageNumber, pageSize);
            allProductVM.CareProducts       = cares.ToPagedList(pageNumber, pageSize);
            allProductVM.FoodHerbProducts   = foodHerbs.ToPagedList(pageNumber, pageSize);
            allProductVM.SupplementProducts = supplements.ToPagedList(pageNumber, pageSize);

            return(View(allProductVM));
        }
        public IActionResult AllProduct()
        {
            var obj = new AllProductViewModel()
            {
                AllProducts = _books.AllBooks.Select(o => new AllProductViewModel
                {
                    Id              = o.Id,
                    NameBook        = o.NameBook,
                    Author          = o.Author.NameAuthor,
                    Genre           = o.Genre.NameGenre,
                    Annotation      = o.Annotation,
                    Img             = o.Img,
                    PublishingHouse = o.PublishingHouse,
                    Price           = o.Price,
                    Year            = o.Year,
                    IsNew           = o.IsNew,
                    IsStock         = o.IsStock,
                    IsFavorite      = o.IsFavorite
                })
            };

            return(View(obj));
        }
        public ActionResult SearchProduct()
        {
            string searchText   = Request.QueryString["searchText"] != null ? Request.QueryString["searchText"] : string.Empty;
            var    model        = new List <AllProductViewModel>();
            var    modelService = new ProductService();
            var    products     = modelService.GetProducts();

            foreach (var item in products)
            {
                var product = new AllProductViewModel();
                product.Id      = item.Id;
                product.Image   = String.Concat(Url.Content("~/Content/images/Product/"), item.Image, ".jpg");
                product.Title   = item.Title;
                product.Price   = item.Price;
                product.Balance = item.Balance;

                if (((item.Title).ToLower()).Contains(searchText.ToLower()))
                {
                    model.Add(product);
                }
                ViewData["CategoryId"] = 0;
            }
            return(View("Index", model));
        }
        public IActionResult EditProduct(AllProductViewModel product)
        {
            string fileName = "../img/Catalog/" + _books.UpLoadFile(product.ImgFile);
            var    book     = _books.GetBookById(product.Id);
            var    obj      = new Book
            {
                Id                 = book.Id,
                NameBook           = product.NameBook,
                NormalizedNameBook = product.NameBook.ToUpper(),
                AuthorId           = Int32.Parse(Request.Form.FirstOrDefault(o => o.Key == "authors").Value.ToString()),
                GenreId            = Int32.Parse(Request.Form.FirstOrDefault(o => o.Key == "genres").Value.ToString()),
                Annotation         = product.Annotation,
                Img                = fileName,
                PublishingHouse    = product.PublishingHouse,
                Price              = product.Price,
                Year               = product.Year,
                IsNew              = product.IsNew,
                IsStock            = product.IsStock,
                IsFavorite         = product.IsFavorite
            };

            _books.EditBook(obj);
            return(RedirectToAction("AllProduct"));
        }