Exemplo n.º 1
0
        public bool CheckAvailability(int id, int quantity)
        {
            Producttable producttable = new Producttable();
            IEnumerable <Producttable> producttables = userRepository.FindID(id);
            bool IdExists = producttables.Any(x => x.ProductID == id);

            if (IdExists)
            {
                foreach (var item in producttables)
                {
                    if (item.ProductID == id)
                    {
                        if (quantity <= item.Stock)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public void Update(ProductViewModel productViewModel)   //does the mapping function and calls the update function in product Repository
        {
            var          config       = new MapperConfiguration(cfg => cfg.CreateMap <ProductViewModel, Producttable> ());
            var          Mapper       = config.CreateMapper();
            Producttable producttable = Mapper.Map <Producttable>(productViewModel);

            productRepository.Update(producttable);
        }
Exemplo n.º 3
0
        public void AddProduct(ProductViewModel productViewModel) //Does the mapping function and passes the data to the Addproduct function in P
        {
            var          config  = new MapperConfiguration(cfg => cfg.CreateMap <ProductViewModel, Producttable>());
            IMapper      mapper  = config.CreateMapper();
            Producttable product = mapper.Map <ProductViewModel, Producttable>(productViewModel);

            productRepository.AddProduct(product);
        }
Exemplo n.º 4
0
        public ProductViewModel GetId(int id)  //does the mapping function and passes the id to the GetID method in Product Repository
        {
            Producttable     product          = productRepository.GetId(id);
            var              config           = new MapperConfiguration(cfg => cfg.CreateMap <Producttable, ProductViewModel>());
            var              Mapper           = config.CreateMapper();
            ProductViewModel productViewModel = Mapper.Map <ProductViewModel>(product);

            return(productViewModel);
        }
Exemplo n.º 5
0
 public ActionResult ProductSpecification(int id) //Displays the full specification details of a single product
 {
     if (Session["UserEmail"] != null)
     {
         Producttable producttable = productService.ProductSpecification(id);
         return(View(producttable));
     }
     else
     {
         return(RedirectToAction("UserLogin", "Account"));
     }
 }
Exemplo n.º 6
0
        public void SubtractQuantity(int productID)
        {
            Producttable producttable = new Producttable();
            IEnumerable <Producttable> producttables = userRepository.FindID(productID);
            bool IdExists = producttables.Any(x => x.ProductID == productID);

            if (IdExists)
            {
                foreach (var item in producttables)
                {
                    if (item.ProductID == productID)
                    {
                        item.quantity = --item.quantity;
                        userRepository.StockUpdate(item);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void StockUpdate(int id, int quantity)
        {
            Producttable producttable = new Producttable();
            IEnumerable <Producttable> producttables = userRepository.FindID(id);
            bool IdExists = producttables.Any(x => x.ProductID == id);

            if (IdExists)
            {
                foreach (var item in producttables)
                {
                    if (item.ProductID == id)
                    {
                        item.Stock = (item.Stock - quantity);
                        userRepository.StockUpdate(item);
                    }
                }
            }
        }
Exemplo n.º 8
0
        public void AddStock(int id, int quantity)
        {
            OnlineShoppingDbcontext onlineShoppingDbcontext = new OnlineShoppingDbcontext();
            // IEnumerable<Producttable> producttables = productRepository.FindID(id);
            Producttable producttable = onlineShoppingDbcontext.Producttables.Find(id);

            //
            //bool IdExists = producttables.Any(x => x.ProductID == id);
            if (producttable != null)
            {
                //foreach (var item in producttables)
                //{
                if (producttable.ProductID == id)
                {
                    producttable.Stock = (producttable.Stock + quantity);
                    productRepository.AddStock(producttable);
                }
                //}
            }
        }
Exemplo n.º 9
0
 public void AddStock(Producttable producttable)
 {
     onlineShoppingDbcontext.Entry(producttable).State = EntityState.Modified;
     onlineShoppingDbcontext.SaveChanges();
 }
Exemplo n.º 10
0
 public void AddProduct(Producttable product)
 {
     onlineShoppingDbcontext.Producttables.Add(product);
     onlineShoppingDbcontext.SaveChanges();
 }