Пример #1
0
        public ActionResult Stock()
        {
            ProductsDb dbProduct = new ProductsDb();

            ModelState.Clear();
            return(View(dbProduct.GetAllProducts()));
        }
Пример #2
0
        public ActionResult DeleteProduct(int id)
        {
            ProductsDb dbProduct = new ProductsDb();

            ModelState.Clear();
            return(View(dbProduct.GetProductsDetail(id)));
        }
Пример #3
0
        public ActionResult EditProduct(int id, FormCollection collection)
        {
            Product productForm = new Product()
            {
                IdProduct   = id,
                Title       = Request.Form["Item1.Title"],
                Synopsis    = Request.Form["Item1.Synopsis"],
                Price       = Convert.ToDecimal(Request.Form["Item1.Price"].Replace('.', ',')),
                ReleaseDate = Convert.ToDateTime(Request.Form["Item1.ReleaseDate"]),
                Picture     = Request.Form["Item1.Picture"],
                Stock       = Convert.ToInt32(Request.Form["Item1.Stock"]),
                TypeP       = new Videorama.Models.Type()
                {
                    IdType = Convert.ToInt32(Request.Form["Item1.TypeP"])
                }
            };

            ProductsDb dbProduct = new ProductsDb();
            bool       productValid;

            productValid = dbProduct.UpdateProduct(productForm);
            if (productValid)
            {
                return(RedirectToAction("Stock"));
            }
            else
            {
                return(RedirectToAction("EditProduct"));
            }
        }
Пример #4
0
        public ActionResult Basket()
        {
            var claimIdentity = User.Identity as ClaimsIdentity;
            var idstYet       = claimIdentity.FindAll(ClaimTypes.UserData);// List of the products id

            ModelState.Clear();

            ProductsDb     dbProducts       = new ProductsDb();
            List <Product> listProductFound = new List <Product>();
            Product        productFound;

            // Search all products id in the auth cookie
            foreach (var id in idstYet)
            {
                // Don't take the first because it's ""
                if (id.Value != "")
                {
                    // Find the product in DB
                    productFound = dbProducts.GetProductsDetail(Convert.ToInt32(id.Value)).Item1;
                    if (productFound != null)
                    {
                        listProductFound.Add(productFound);
                    }
                }
            }

            return(View(listProductFound));
        }
Пример #5
0
        /// <summary>
        /// Show a list of product, it's the result of the search bar
        /// </summary>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <returns>View</returns>
        public ActionResult ProductsSearchResult(int type, string name)
        {
            ModelState.Clear();

            ProductsDb     dbProducts = new ProductsDb();
            List <Product> listProductFound;

            listProductFound = dbProducts.SearchProductByNameAndType(type, name);

            return(View(listProductFound));
        }
Пример #6
0
        /// <summary>
        /// Show view with the list of product with a given product type
        /// </summary>
        /// <param name="type"></param>
        /// <returns>View</returns>
        public ActionResult ProductsList(int type)
        {
            ProductsDb dbProducts = new ProductsDb();

            ModelState.Clear();
            List <Product> list     = dbProducts.GetProductsByType(type);
            string         typeName = list[0].TypeP.TypeName;

            ViewData["type"] = typeName;
            return(View(dbProducts.GetProductsByType(type)));
        }
Пример #7
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));
        }
Пример #8
0
        public async Task <IActionResult> Add(Product p)
        {
            try
            {
                // TODO: Add insert logic here
                await ProductsDb.Add(p, _context);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Пример #9
0
        public ActionResult DeleteProduct(int id, FormCollection collection)
        {
            ProductsDb dbProduct = new ProductsDb();
            bool       productValid;

            productValid = dbProduct.DeleteProduct(id);

            if (productValid)
            {
                return(RedirectToAction("Stock"));
            }
            else
            {
                return(RedirectToAction("DeleteProduct", id));
            }
        }
Пример #10
0
        public void When_Saving_A_Product_Index_View_Should_be_Returned_With_The_New_Product_List()
        {
            //Arrange
            var controller = new ProductsController();
            var product    = new Product {
                Name = "dummy", Cost = 20
            };

            //Act
            var existingCount = ProductsDb.GetAllProducts().Count();
            var result        = controller.Save(product);

            //Assert
            Assert.IsTrue(ProductsDb.GetAllProducts().Count() == existingCount + 1);
            Assert.IsTrue(((RedirectToRouteResult)result).RouteValues["action"].ToString() == "Index");
        }
Пример #11
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"));
        }
Пример #12
0
        public ActionResult CreateProduct(FormCollection collection, HttpPostedFileBase Picture)
        {
            if (Picture != null && Picture.ContentLength > 0)
            {
                string path = Path.Combine(Server.MapPath("~/Content/Images/"),
                                           Path.GetFileName(Picture.FileName));
                Picture.SaveAs(path);
            }

            Product productForm = new Product()
            {
                Title       = Request.Form["Title"],
                Synopsis    = Request.Form["Synopsis"],
                Price       = Convert.ToDecimal(Request.Form["Price"].Replace('.', ',')),
                ReleaseDate = Convert.ToDateTime(Request.Form["ReleaseDate"]),
                Picture     = Request.Form["Picture"],
                Stock       = Convert.ToInt32(Request.Form["Stock"]),
                TypeP       = new Videorama.Models.Type()
                {
                    IdType = Convert.ToInt32(Request.Form["IdType"])
                }
            };

            ProductsDb dbProduct = new ProductsDb();
            bool       productValid;

            productValid = dbProduct.AddProduct(productForm);
            if (productValid)
            {
                return(RedirectToAction("Stock"));
            }
            else
            {
                return(RedirectToAction("CreateProduct"));
            }
        }
Пример #13
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));
        }
Пример #14
0
 public ProductsBLL()
 {
     db = new ProductsDb();
 }
Пример #15
0
        // GET: User
        public async Task <IActionResult> Index(int?id)
        {
            List <Product> products = await ProductsDb.GetAllProducts(_context);

            return(View(products));
        }
 public ProductsAPIController()
 {
     products = new ProductsDb();
 }
        //
        // GET: /Products/

        public ViewResult Index()
        {
            return(View("Index", ProductsDb.GetAllProducts()));
        }
        public ActionResult Save(Product product)
        {
            var newProduct = ProductsDb.Add(product);

            return(RedirectToAction("Index"));
        }
Пример #19
0
        static void Main()
        {
            /*Implement a class PriorityQueue<T> based on the data structure "binary heap".
            Write a program to read a large collection of products(name + price) and efficiently find the first 20 products in the price range[a…b].
            Test for 500 000 products and 10 000 price searches.
            Hint: you may use OrderedBag<T> and sub-ranges.
            Write a program that finds a set of words (e.g. 1000 words) in a large text(e.g. 100 MB text file).
            Print how many times each word occurs in the text.
            Hint: you may find a C# trie in Internet.*/
            var priorityQueue = new MyPriorityQueue<int>();

            priorityQueue.Enqueue(1);
            priorityQueue.Enqueue(3);
            priorityQueue.Enqueue(18);
            priorityQueue.Enqueue(4);
            priorityQueue.Enqueue(105);
            priorityQueue.Enqueue(213);

            var last = priorityQueue.Dequeue();

            Console.WriteLine("TASK 1:");
            Console.WriteLine("Dequed: " + last);
            Console.WriteLine("Size of queue: " + priorityQueue.Count());
            Console.WriteLine("All elements: \n" + String.Join(", ", priorityQueue.All()));
            Console.WriteLine();

            /*Write a program to read a large collection of products (name + price) and efficiently find
            the first 20 products in the price range [a…b].
            Test for 500 000 products and 10 000 price searches.
            Hint: you may use OrderedBag<T> and sub-ranges.*/
            var db = new ProductsDb();

            for (int i = 0; i < 500000; i++)
            {
                db.AddProduct(new Product(GetRandomName(), GetRandomPriceInRange(0, 100000)));
            }

            Console.WriteLine("TASK 2:");
            Console.WriteLine("500 000 products added");

            var stopWatch = new Stopwatch();
            stopWatch.Start();
            var productsInRange = db.GetProductsInPriceRange(100, 3000);
            stopWatch.Stop();

            Console.WriteLine("Alll products in this range: " + productsInRange.Count);
            Console.WriteLine("Elapsed time to find all products: "+ stopWatch.Elapsed);
            Console.WriteLine();

            /*Write a program that finds a set of words(e.g. 1000 words) in a large text(e.g. 100 MB text file).
            Print how many times each word occurs in the text.
            Hint: you may find a C# trie in Internet.*/
            var sw = new Stopwatch();

            var trie = new Trie();

            for (int i = 0; i < wordsToAdd; i++)
            {
                string word = GetRandomName();
                sw.Start();
                trie.Add(word);
                sw.Stop();
            }

            Console.WriteLine("TASK 3");
            Console.WriteLine("Added {0} words for {1} time", wordsToAdd, sw.Elapsed);

            sw.Reset();
            for (int i = 0; i < wordsToSearch; i++)
            {
                string word = GetRandomName();
                sw.Start();
                trie.GetWordOccurance(word);
                sw.Stop();
            }

            Console.WriteLine("Found {0} words for {1} time", wordsToSearch, sw.Elapsed);
            Console.WriteLine("Most common word: {0}", trie.GetMostCommonWord());

        }