public ActionResult Product_Create(Product product) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { bool exist = db.Product.Where(x => x.Product_Name == product.Product_Name).Any(); Product prod = new Product(); prod.Product_Name = product.Product_Name; prod.Product_Price = product.Product_Price; if (!exist) //check to updat eor create { db.Product.Add(prod); } else { prod = db.Product.SingleOrDefault(x => x.Product_Name == product.Product_Name); prod.Product_Name = product.Product_Name; prod.Product_Price = product.Product_Price; } // executes the commands to implement the changes to the database db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
public ActionResult Create(Customer customer) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { bool exist = db.Customer.Where(x => x.Cust_Name == customer.Cust_Name).Any(); Customer cust = new Customer(); cust.Cust_Name = customer.Cust_Name; cust.Cust_Address = customer.Cust_Address; if (!exist) //check to updat eor create { db.Customer.Add(cust); } else { cust = db.Customer.SingleOrDefault(x => x.Cust_Name == customer.Cust_Name); cust.Cust_Name = customer.Cust_Name; cust.Cust_Address = customer.Cust_Address; } // executes the commands to implement the changes to the database db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
public ActionResult Create(Store store) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { bool exist = db.Store.Where(x => x.Store_Name == store.Store_Name).Any(); Store str = new Store(); str.Store_Name = store.Store_Name; str.Store_Address = store.Store_Address; if (!exist) //check to updat eor create { db.Store.Add(str); } else { str = db.Store.SingleOrDefault(x => x.Store_Name == store.Store_Name); str.Store_Name = store.Store_Name; str.Store_Address = store.Store_Address; } // executes the commands to implement the changes to the database db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
public JsonResult Add(ProductSold prod) { try { using (db) { db.ProductSold.Add(prod); db.SaveChanges(); return(Json(prod, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Console.WriteLine(ex.InnerException); return(Json(prod, JsonRequestBehavior.AllowGet)); } }
public ActionResult Delete(int id, Product product) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { Product prod = db.Product.SingleOrDefault(x => x.Id == product.Id); db.Product.Remove(prod); db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
public ActionResult Delete(int id, Customer customer) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { Customer cust = db.Customer.SingleOrDefault(x => x.Id == customer.Id); db.Customer.Remove(cust); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { Console.WriteLine(ex.InnerException); return(View()); } }
public ActionResult Edit(int id, Product product) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { Product prod = db.Product.SingleOrDefault(x => x.Product_Name == product.Product_Name); prod.Product_Name = product.Product_Name; prod.Product_Price = product.Product_Price; // executes the commands to implement the changes to the database db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }