public ActionResult DeleteProduct(Guid id) { using (var db = new qStoreDBEntities()) { var prod = db.Products.SingleOrDefault(x => x.Id == id); if (prod != null) { db.Products.Remove(prod); db.SaveChanges(); } else { throw new InvalidOperationException("Product not found"); } } return RedirectToAction("GetProducts"); }
public ActionResult DeleteCategory(Guid id) { using (var db = new qStoreDBEntities()) { var cat = db.Categories.SingleOrDefault(x => x.Id == id); if (cat != null) { db.Categories.Remove(cat); } else { throw new InvalidOperationException("Category not found"); } db.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult SaveProduct(HttpPostedFileBase file, Product model) { using (var db = new qStoreDBEntities()) { var product = db.Products.SingleOrDefault(x => x.Id == model.Id); model.Category = db.Categories.SingleOrDefault(x => x.Id == model.CategoryId); if (file != null && file.ContentLength > 0) { model.ImageContentType = file.ContentType; model.ImageBase64String = GetByteArrayString(file); } if (product != null) { product.Title = model.Title; product.Description = model.Description; product.Category = model.Category; product.ImageBase64String = model.ImageBase64String; product.ImageContentType = model.ImageContentType; product.Price = model.Price; } else { db.Products.Add(model); } db.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult SaveCategory(Category model) { using (var db = new qStoreDBEntities()) { var cat = db.Categories.SingleOrDefault(x => x.Id == model.Id); if (cat != null) { cat.Title = model.Title; cat.IsDisabled = model.IsDisabled; } else { db.Categories.Add(model); } db.SaveChanges(); } return RedirectToAction("Index"); }