internal ProductsResp AddProducts(ProductsDatas products) { using (var db = new ProductsContext()) { db.Products.Add(products); db.SaveChanges(); return(new ProductsResp() { Status = true, StatusMsg = "" }); } }
internal ProductsResp AddProducts(ProductsDatas products) { using (var db = new ProductsContext()) { if (db.Products.Any(x => x.Name == products.Name)) { return(new ProductsResp() { Status = false, StatusMsg = "The Product whith this name already exist! Please try again." }); } db.Products.Add(products); db.SaveChanges(); return(new ProductsResp() { Status = true, StatusMsg = "" }); } }
public ActionResult NewProduct(UserData products) { SessionStatus(); var user = System.Web.HttpContext.Current.GetMySessionObject(); if (user == null) { return(View()); } UserData u = new UserData { Username = user.Username, Level = user.Level }; if (ModelState.IsValid) { ProductsDatas data = new ProductsDatas { Name = products.Name, Description = products.Description, Price = products.Price, imageUrl = products.imageURL }; var productResp = _product.SetProductsList(data); if (productResp.Status) { return(RedirectToAction("Index", "Product")); } else { ModelState.AddModelError("", productResp.StatusMsg); return(View()); } } return(View()); }
public ProductsResp SetProductsList(ProductsDatas prod) { return(AddProducts(prod)); }