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); }
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); }
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); }
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); }
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")); } }
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); } } } }
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); } } } }
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); } //} } }
public void AddStock(Producttable producttable) { onlineShoppingDbcontext.Entry(producttable).State = EntityState.Modified; onlineShoppingDbcontext.SaveChanges(); }
public void AddProduct(Producttable product) { onlineShoppingDbcontext.Producttables.Add(product); onlineShoppingDbcontext.SaveChanges(); }