public ActionResult Edit(Product product) { if (ModelState.IsValid) { product.DateEnter = DateTime.Now; using (StoreOlineEntities db = new StoreOlineEntities()) { var temp = db.Products.Where(t => t.ProductID == product.ProductID).SingleOrDefault(); if (temp == null) { db.Products.Add(product); db.SaveChanges(); TempData["message"] = product.ProductName + " has been added"; return(RedirectToAction("Products")); } else { using (StoreOlineEntities db1 = new StoreOlineEntities()) { db1.Entry(product).State = EntityState.Modified; db1.SaveChanges(); TempData["message"] = product.ProductName + " has been saved"; return(RedirectToAction("Products")); } } } } return(View(product)); }
public Product Delete(Product obj) { db = new StoreOlineEntities(); var tmp = db.Products.SingleOrDefault(t => t.ProductID == obj.ProductID); db.Products.Remove(tmp); db.SaveChanges(); return(tmp); }
public bool Update(Order obj) { db = new StoreOlineEntities(); if (db.Orders.SingleOrDefault(o => o.OrderID == obj.OrderID) == null) { return(false); } db.Orders.Attach(obj); db.Entry(obj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); }
public Order Delete(Order obj) { db = new StoreOlineEntities(); var tmp = db.Orders.SingleOrDefault(o => o.OrderID == obj.OrderID); if (tmp != null) { db.Orders.Remove(obj); } db.SaveChanges(); return(tmp); }
public ActionResult Contact(MailBox mail) { if (ModelState.IsValid) { using (StoreOlineEntities db = new StoreOlineEntities()) { mail.DateEnter = DateTime.Now; db.MailBoxes.Add(mail); db.SaveChanges(); } } return(RedirectToAction("Contact")); }
public bool Add(Order obj) { db = new StoreOlineEntities(); var tmp = db.Orders.SingleOrDefault(o => o.OrderID == obj.OrderID); if (tmp != null) { return(false); } db.Orders.Add(obj); db.SaveChanges(); return(true); }
public bool Add(Product obj) { db = new StoreOlineEntities(); var tmp = db.Products.SingleOrDefault(t => t.ProductID == obj.ProductID); if (tmp != null) { return(false); } db.Products.Add(obj); db.SaveChanges(); return(true); }
public bool Update(Product obj) { db = new StoreOlineEntities(); var tmp = db.Products.SingleOrDefault(t => t.ProductID == obj.ProductID); if (tmp == null) { return(false); } db.Products.Attach(obj); db.Entry(obj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); }
public ActionResult Delete(int OrderID, string state) { using (StoreOlineEntities db = new StoreOlineEntities()) { var tmp = db.Orders.SingleOrDefault(t => t.OrderID == OrderID); if (tmp != null) { db.OrderDets.RemoveRange(tmp.OrderDets); db.Orders.Remove(tmp); db.SaveChanges(); TempData["message"] = tmp.OrderID + " at " + tmp.OrderDate.ToString("dd/MM/yyyy") + " was deleted"; } } return(RedirectToAction("Index", new { state = state })); }
public ActionResult Edit(int OrderID, string state) { using (StoreOlineEntities db = new StoreOlineEntities()) { var tmp = db.Orders.SingleOrDefault(t => t.OrderID == OrderID); if (tmp != null) { tmp.IsShipping = true; tmp.ShippingDate = DateTime.Now; db.SaveChanges(); TempData["message"] = tmp.OrderID + " at " + tmp.OrderDate.ToString("dd/MM/yyyy") + " was accepted"; } } return(RedirectToAction("Index", new { state = state })); }