Example #1
0
        public ActionResult RentDetails(int idr)
        {
            RentDb dbRent = new RentDb();

            ModelState.Clear();
            return(View(dbRent.GetRentDetails(idr)));
        }
Example #2
0
        public ActionResult Rents()
        {
            RentDb dbRent = new RentDb();

            ModelState.Clear();
            return(View(dbRent.GetRents()));
        }
Example #3
0
        /// <summary>
        /// Display the rents concerning the user connected
        /// </summary>
        /// <param name="id"></param>
        /// <returns>View</returns>
        public ActionResult Rents(int id)
        {
            RentDb dbRent = new RentDb();

            ModelState.Clear();
            return(View(dbRent.GetDistinctRentByCustomer(id)));
        }
Example #4
0
        /// <summary>
        /// Display a PDF with the information of the customer
        /// and the products for one rent selected.
        /// The PDF is open in a new tab from the rents page.
        /// Rotativa is a package to help displaying PDF.
        /// </summary>
        /// <param name="idR"></param>
        /// <returns></returns>
        public ActionResult DownloadBill(int idR)
        {
            RentDb dbProducts = new RentDb();

            ModelState.Clear();
            BillViewModel model = dbProducts.GetRentDetails(idR);

            return(new Rotativa.ViewAsPdf("ViewPDF", model));
        }
Example #5
0
        /// <summary>
        /// Show in a partial view the result of top n rented products
        /// In the index page, the user choose top 5, 10, 25 etc
        /// and then the partial view ask the the ressult to the database
        /// depending on the user demand
        /// </summary>
        /// <param name="topValue"></param>
        /// <returns>PartialView</returns>
        public ActionResult IndexTop(int topValue)
        {
            ProductsDb dbProducts = new ProductsDb();
            RentDb     dbRent     = new RentDb();

            ModelState.Clear();
            AccueilViewModel vm = new AccueilViewModel
            {
                Product = dbProducts.GetTopNProducts(topValue)
            };

            return(PartialView(vm));
        }
Example #6
0
        public ActionResult ReturnBack(int idCustomer, int idRent)
        {
            RentDb dbRent = new RentDb();
            bool   rentValid;

            rentValid = dbRent.UpdateRentReturnedBack(idRent);

            if (rentValid)
            {
                return(RedirectToAction("Rents"));
            }
            else
            {
                return(RedirectToAction("RentDetails", new { idc = idCustomer, idr = idRent }));
            }
        }
Example #7
0
        public ActionResult Basket(FormCollection collection)
        {
            RentDb     dbRent    = new RentDb();
            ProductsDb dbProduct = new ProductsDb();
            bool       rent      = false;
            bool       isRemove  = false;
            bool       resultat  = false;

            var claimIdentity = User.Identity as ClaimsIdentity;
            int idUser        = Convert.ToInt32(claimIdentity.FindFirst(ClaimTypes.NameIdentifier).Value);
            var productList   = claimIdentity.FindAll(ClaimTypes.UserData);

            if (collection["getRentDate"] != null)
            {
                foreach (var product in productList)
                {
                    if (product.Value != "")
                    {
                        // Down the product's stock in DB
                        isRemove = dbProduct.RemoveStock(Convert.ToInt32(product.Value));
                        resultat = isRemove;
                        if (isRemove == false)
                        {
                            break;
                        }
                    }
                }
            }

            // Create the rent in DB with the date when the customer will get the products in the shop
            if (resultat)
            {
                rent = dbRent.AddRent(Convert.ToDateTime(collection["getRentDate"]), idUser, productList);
                RemoveAllProductBasket();// Remove all products in basket
                return(RedirectToAction("Rents", "Rents", new { id = idUser }));
            }

            return(RedirectToAction("Basket"));
        }
Example #8
0
        /// <summary>
        /// Show the index page.
        /// The content depends on whether the user is connected or not
        /// The page contains the new products and the top n of rented products for anyone
        /// It shows the products currently rented by someone if he's connected
        /// </summary>
        /// <returns>View</returns>
        public ActionResult Index()
        {
            string role   = "";
            string id     = "";
            int    idUser = 0;

            if (Request.IsAuthenticated)
            {
                var claimIdentity = User.Identity as ClaimsIdentity;

                if (claimIdentity != null)
                {
                    role   = claimIdentity.FindFirst(ClaimTypes.Role).Value;
                    id     = claimIdentity.FindFirst(ClaimTypes.NameIdentifier).Value;
                    idUser = Convert.ToInt32(id);
                }
            }

            ProductsDb dbProducts = new ProductsDb();
            RentDb     dbRent     = new RentDb();

            ModelState.Clear();
            AccueilViewModel vm = new AccueilViewModel
            {
                NewProducts = dbProducts.GetNewProducts()
            };

            if (Request.IsAuthenticated)
            {
                if (role == "User")
                {
                    vm.Rent = dbRent.GetRentByCustomer(idUser);
                }
            }
            return(View(vm));
        }