public ActionResult Delete(int id) { using (var context = new ShopContainer()) { var order = context.Order.Include("OrderItems").First(o => o.Id == id); while (order.OrderItems.Any()) { var item = order.OrderItems.First(); context.DeleteObject(item); } context.DeleteObject(order); context.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Delete(int id) { using (var context = new ShopContainer()) { var comment = context.Comment.First(c => c.Id == id); context.DeleteObject(comment); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = "about" }); } }
public ActionResult Delete(int id) { using (var context = new ShopContainer()) { var article = context.Article.First(c => c.Id == id); context.DeleteObject(article); return RedirectToAction("Index"); } }
public ActionResult Delete(int id) { using (var context = new ShopContainer()) { var category = context.Category.Include("ProductAttributes").First(c => c.Id == id); if (!string.IsNullOrEmpty(category.ImageSource)) { IOHelper.DeleteFile("~/Content/Images", category.ImageSource); foreach (var folder in GraphicsHelper.ThumbnailFolders) { IOHelper.DeleteFile("~/ImageCache/" + folder, category.ImageSource); } } category.ProductAttributes.Clear(); context.DeleteObject(category); context.SaveChanges(); return RedirectToAction("Index"); } }
// // GET: /Admin/Tag/Delete/5 public ActionResult Delete(int id) { try { using (var context = new ShopContainer()) { var tag = context.Tag.First(t => t.Id == id); context.DeleteObject(tag); context.SaveChanges(); } return RedirectToAction("Index"); } catch { return RedirectToAction("Index"); } }
public ActionResult Attributes(int productId, FormCollection form) { using (var context = new ShopContainer()) { var product = context.Product.Include("ProductAttributeValues").First(p => p.Id == productId); PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr", "productId"); PostData staticAttrData = form.ProcessPostData("tb", "productId"); product.ProductAttributeValues.Clear(); foreach (var kvp in cbData) { var attributeValueId = kvp.Key; bool attributeValue = kvp.Value; if (attributeValue) { var productAttributeValue = context.ProductAttributeValues.First(pv => pv.Id == attributeValueId); product.ProductAttributeValues.Add(productAttributeValue); } } foreach (var kvp in staticAttrData) { int attributeId = Convert.ToInt32(kvp.Key); foreach (var value in kvp.Value) { string attributeValue = value.Value; var productAttribute = context.ProductAttribute.Include("ProductAttributeStaticValues").First(pa => pa.Id == attributeId); //productAttribute.ProductAttributeStaticValues.Clear(); ProductAttributeStaticValues productAttributeValue = null; productAttributeValue = context.ProductAttributeStaticValues.FirstOrDefault( pav => pav.ProductAttribute.Id == productAttribute.Id && pav.Product.Id == product.Id); if (string.IsNullOrEmpty(attributeValue)) { if (productAttributeValue != null) context.DeleteObject(productAttributeValue); } else { if (productAttributeValue == null) { productAttributeValue = new ProductAttributeStaticValues { Value = attributeValue, ProductAttribute = productAttribute }; product.ProductAttributeStaticValues.Add(productAttributeValue); } else { productAttributeValue.Value = attributeValue; } } //productAttribute.ProductAttributeValues.Add(productAttributeValue); } } context.SaveChanges(); return RedirectToAction("Index"); } }
public ActionResult Delete(int id) { using (var context = new ShopContainer()) { var product = context.Product.Include("ProductAttributeValues").Include("ProductAttributeStaticValues").First(p => p.Id == id); product.ProductAttributeValues.Clear(); while (product.ProductAttributeStaticValues.Any()) { var pav = product.ProductAttributeStaticValues.First(); context.DeleteObject(pav); } while (product.ProductImages.Any()) { var image = product.ProductImages.First(); DeleteImage(image, context); } product.Tags.Clear(); context.DeleteObject(product); context.SaveChanges(); return RedirectToAction("Index"); } }
private void DeleteImage(ProductImage image, ShopContainer context) { IOHelper.DeleteFile("~/Content/Images", image.ImageSource); foreach (var folder in GraphicsHelper.ThumbnailFolders) { IOHelper.DeleteFile("~/ImageCache/" + folder, image.ImageSource); } //IOHelper.DeleteFile("~/ImageCache/thumbnail0", image.ImageSource); //IOHelper.DeleteFile("~/ImageCache/thumbnail1", image.ImageSource); context.DeleteObject(image); }
public ActionResult Delete(int id) { using (var context = new ShopContainer()) { var category = context.Category.Include("Products").First(c => c.Id == id); while (category.Products.Any()) { var product = category.Products.First(); ImageHelper.DeleteImage(product.ImageSource); context.DeleteObject(product); } category.Products.Clear(); context.DeleteObject(category); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "" }); } }
public ActionResult Delete(int id) { using (var context = new ShopContainer()) { var product = context.Product.Include("Category").First(p => p.Id == id); var catName = product.Category.Name; ImageHelper.DeleteImage(product.ImageSource); context.DeleteObject(product); context.SaveChanges(); return RedirectToAction("Category", "Home", new { area = "", id = catName }); } }
public ActionResult Delete(int id) { using (var context = new ShopContainer()) { try { var attribute = context.ProductAttribute.Include("ProductAttributeValues").First(a => a.Id == id); while (attribute.ProductAttributeValues.Any()) { var pav = attribute.ProductAttributeValues.First(); pav.Products.Clear(); context.DeleteObject(pav); } attribute.Categories.Clear(); context.DeleteObject(attribute); context.SaveChanges(); return RedirectToAction("Index"); } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message +"<br/>"+ ex.InnerException.Message; var productAttributes = context.ProductAttribute.Include("ProductAttributeValues").ToList(); return View("Index", productAttributes); } } }
public ActionResult DeleteProductAttributeValue(int id, int productAttributeId) { using (var context = new ShopContainer()) { var productAttributeValue = context.ProductAttributeValues.First(pav => pav.Id == id); productAttributeValue.Products.Clear(); context.DeleteObject(productAttributeValue); context.SaveChanges(); return RedirectToAction("ProductAttributeValues", new { id = productAttributeId }); } }
// // GET: /Admin/Brand/Delete/5 public ActionResult Delete(int id) { using (var context = new ShopContainer()) { var brand = context.Brand.Where(b => b.Id == id).First(); if (!string.IsNullOrEmpty(brand.Logo)) { IOHelper.DeleteFile("~/Content/Images", brand.Logo); foreach (var folder in GraphicsHelper.ThumbnailFolders) { IOHelper.DeleteFile("~/ImageCache/" + folder, brand.Logo); } } context.DeleteObject(brand); context.SaveChanges(); return RedirectToAction("Index"); } }