Exemple #1
0
        public ActionResult Products(string Sku)

        {
            Tuple <List <Product>, Product> tuple;
            List <Product> ProductsList = ProductAccess.GetAllProducts();

            var CurrentProductIndex = 0;

            try
            {
                CurrentProductIndex = ProductsList.FindIndex(a => a.Sku == Sku);
            }
            catch
            {
                CurrentProductIndex = 0;
            }

            if (CurrentProductIndex == -1)
            {
                CurrentProductIndex = 0;
            }
            tuple = new Tuple <List <Product>, Product>(ProductsList, ProductsList[CurrentProductIndex]);

            return(View("~/Views/Product/Products.cshtml", model: tuple));
        }
Exemple #2
0
        public ActionResult ProductsInitial()

        {
            Tuple <List <Product>, Product> tuple;
            List <Product> ProductsList = ProductAccess.GetAllProducts();

            var CurrentProductIndex = 0;

            tuple = new Tuple <List <Product>, Product>(ProductsList, ProductsList[CurrentProductIndex]);

            return(View("~/Views/Product/Products2.cshtml", model: tuple));
        }
Exemple #3
0
        public void List_InputGBP_ReturnsExpectedResult()
        {
            // Arrange
            var productAccess = new ProductAccess();

            // Act
            var actual = productAccess.List(0, 5);

            // Assert
            actual.Should().HaveCount(5);
            actual.First().Name          = "Coca Cola";
            actual.First().PriceInPounds = 1.2m;
        }
Exemple #4
0
        public ActionResult CreateProduct(Product product)
        {
            if (ModelState.IsValid)
            {
                string status = ProductAccess.CreateProduct(product);
                ViewBag.CreationStatus = status;
            }

            else
            {
                RedirectToAction("ProductForm");
            }

            return(RedirectToAction("Status", "Product"));
        }
        /*
         * Returns a list of the next 12 products to be displayed, until 1000 total products have been returned.
         * For demo purposes, these products are generated instead of being stored in a database.
         */
        public List <product> getProducts(int index)
        {
            List <product> products = new List <product>();

            ProductAccess access = new ProductAccess();

            int numProducts = 12;
            int maxProducts = 1000;

            if (index + numProducts > maxProducts)
            {
                numProducts = maxProducts - index;
            }

            int lowerLimit = index + 1;
            int upperLimit = index + numProducts;

            products = access.getProducts(lowerLimit, upperLimit);

            return(products);
        }
Exemple #6
0
 public static List <Product> GetAllProducts()
 {
     return(ProductAccess.GetAllProducts());
 }
        protected override void Seed(ROZETKA.Entities.EFContext context)
        {
            for (int i = 0; i <= 4; i += 2)
            {
                ProductAccess acc = new ProductAccess()
                {
                    Id         = i + 1,
                    DateOfLock = DateTime.Now
                };
                context.ProductAccesses.AddOrUpdate(t => t.Id, acc);
            }

            Categories categories1 = new Categories()
            {
                Id   = 0,
                Name = "NoteBook"
            };
            Categories categories2 = new Categories()
            {
                Id   = 1,
                Name = "Computers"
            };
            Categories categories3 = new Categories()
            {
                Id   = 2,
                Name = "Telephones"
            };
            Categories categories4 = new Categories()
            {
                Id   = 3,
                Name = "Other devices"
            };

            context.Categories.AddOrUpdate(t => t.Id, categories1);
            context.Categories.AddOrUpdate(t => t.Id, categories2);
            context.Categories.AddOrUpdate(t => t.Id, categories3);
            context.Categories.AddOrUpdate(t => t.Id, categories4);


            for (int i = 0; i < 5; i++)
            {
                Product product = new Product()
                {
                    Id            = i + 1,
                    Price         = i * 4500,
                    Name          = $"Notebook{i}",
                    Categories_id = 1,
                    Description   = "Sorry , this notebook not for you"
                };
                context.Products.AddOrUpdate(t => t.Id, product);
            }

            for (int i = 0; i < 5; i++)
            {
                Images images = new Images()
                {
                    Id     = i + 1,
                    ImageF = $"../../Images/ImageF{i + 1}.jpg",
                    ImageS = $"../../Images/ImageS{i + 1}.jpg",
                    ImageT = $"../../Images/ImageT{i + 1}.jpg",
                };
                context.Images.AddOrUpdate(t => t.Id, images);
            }
        }