public ActionResult UpdateProduct(ProductModel model) { if (ModelState.IsValid) { List <DataLibrary.Models.ProductModel> products = ProductProcessor.LoadProducts(); ProductModel sessionModel = (ProductModel)Session["ProductUpdateModel"]; //recreating list without the session model in it. products = products.Where(a => a.ProductID != sessionModel.ProductID).ToList(); //isolate(if any) duplicates products = products.Where(a => a.ProductID == model.ProductID || a.ProductName == model.ProductName).ToList(); //if the session model's identifying variable is the same as the parameter model, then it is okay to update (same account, same update) //if the session model's identifying variable is NOT the same, then it is NOT okay to update (updating the current model to a duplicate that already exists) //checking to see if the session model is the same as the parameter model. If same, update, if not, proceed. if (sessionModel.ProductName == model.ProductName) { //left as int for testing purposes int recordsCreated = ProductProcessor.UpdateProduct(model.ProductID, model.ProductName, model.Manufacturer, model.Style, model.PurchasePrice, model.SalePrice, model.Qty, model.CommissionPercentage); return(RedirectToAction("ViewProduct")); } else { //if duplicates exist, throw alert and deny update. if (products.Count() > 0) { TempData["DuplicateProduct"] = "You have entered a duplicate product, please enter a new product."; return(View()); } else { //left as int for testing purposes int recordsCreated = ProductProcessor.UpdateProduct(model.ProductID, model.ProductName, model.Manufacturer, model.Style, model.PurchasePrice, model.SalePrice, model.Qty, model.CommissionPercentage); return(RedirectToAction("ViewProduct")); } } } return(View()); }
public ActionResult CreateProduct(ProductModel model) { if (ModelState.IsValid) { List <DataLibrary.Models.ProductModel> products = ProductProcessor.LoadProducts(); products = products.Where(a => a.ProductID == model.ProductID || a.ProductName == model.ProductName).ToList(); if (products.Count() > 0) { TempData["DuplicateProduct"] = "You have entered a duplicate product, please enter a new product."; return(View()); } else { //left as int for testing purposes int recordsCreated = ProductProcessor.CreateProduct(model.ProductID, model.ProductName, model.Manufacturer, model.Style, model.PurchasePrice, model.SalePrice, model.Qty, model.CommissionPercentage); return(RedirectToAction("ViewProduct")); } } return(View()); }
public ActionResult Products() { ViewBag.Message = "Display Products."; var data = ProductProcessor.LoadProducts(); List <ProductModel> products = new List <ProductModel>(); data.ForEach(row => { products.Add(new ProductModel { Id = row.Id, ProductName = row.ProductName, SupplierName = row.SupplierName, URL = row.URL, Username = row.Username, Password = row.Password }); }); return(View(products)); }
public ActionResult Index() { if (IsActiveSession()) { //getting store products var data = ProductProcessor.LoadProducts(); List <ProductModel> products = new List <ProductModel>(); foreach (var row in data) { products.Add(new ProductModel { Id = row.Id, ProductCode = row.ProductCode, Description = row.Description, UnitOfMeasure = row.UnitOfMeasure, Category = row.Category, Price = row.Price, ImageTitle = row.ImageTitle, ImagePath = row.ImagePath, IsActive = row.IsActive }); } //getting cart products int userId = (int)Session["userId"]; List <CartProductsModel> cartProducts = GetCartProducts(userId); //setting store products StoreViewModel storeViewModel = new StoreViewModel { StoreProducts = products, CartProducts = cartProducts }; return(View(storeViewModel)); } return(RedirectToAction("Login", "Login", null)); }
public ActionResult ViewProduct() { ViewBag.Message = "View product page."; var data = ProductProcessor.LoadProducts(); List <ProductModel> products = new List <ProductModel>(); foreach (var row in data) { products.Add(new ProductModel { ProductID = row.ProductID, ProductName = row.ProductName, Manufacturer = row.Manufacturer, Style = row.Style, PurchasePrice = row.PurchasePrice, SalePrice = row.SalePrice, Qty = row.Qty, CommissionPercentage = row.CommissionPercentage }); } return(View(products)); }