public bool Remove(VMProductMG svm) { ProductMG p = db.ProductMG.Find(svm.ID); db.ProductMG.Remove(p); db.SaveChanges(); return(true); }
public bool Remove(long id) { ProductMG p = db.ProductMG.Find(id); db.ProductMG.Remove(p); db.SaveChanges(); return(true); }
public ActionResult Create(ProductViewModel model, int?IsDefaultCheckBox) { if (ModelState.IsValid) { try { Product product = new Product { Name = model.Name, Brand = model.Brand, CategoryID = model.CategoryID, Details = model.Details, IsActive = model.IsActive, IsFavorite = model.IsFavorite, Price = model.Price, StockQuantity = model.StockQuantity }; productRepository.Add(product); string uniqueFileName = null; int i = 1; if (model.ImagePath != null && model.ImagePath.Count > 0) { foreach (var photo in model.ImagePath) { uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName; string uploaddFile = Path.Combine(Server.MapPath("~/ProductPhoto"), uniqueFileName); photo.SaveAs(uploaddFile); ProductMG productMG = new ProductMG { ImgPath = uniqueFileName, DisplayOrder = i, ProductID = product.ID, ThumbnailPath = "" }; if (i == IsDefaultCheckBox) { productMG.IsDefaultImg = true; } productMGRepository.Add(productMG); i++; } } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } return(RedirectToAction("Index")); } return(View(model)); }
public VMProductMG Update(VMProductMG svm) { ProductMG productMG = db.ProductMG.Find(svm.ID); productMG.ProductID = svm.ProductID; productMG.ImgPath = svm.ImgPath; productMG.ThumbnailPath = svm.ThumbnailPath; productMG.DisplayOrder = svm.DisplayOrder; productMG.IsDefaultImg = svm.IsDefaultImg; db.Entry(productMG).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(svm); }
public VMProductMG Add(VMProductMG svm) { ProductMG productMG = new ProductMG(); productMG.ProductID = svm.ProductID; productMG.ImgPath = svm.ImgPath; productMG.ThumbnailPath = svm.ThumbnailPath; productMG.DisplayOrder = svm.DisplayOrder; productMG.IsDefaultImg = svm.IsDefaultImg; db.ProductMG.Add(productMG); db.SaveChanges(); svm.ID = productMG.ID; return(svm); }
public ActionResult Edit(ProductMG model) { if (ModelState.IsValid) { var productImage = productMGRepository.Get(model.ProductID); if (productImage != null) { productImage.ImgPath = model.ImgPath; productImage.IsDefaultImg = model.IsDefaultImg; productImage.ThumbnailPath = model.ThumbnailPath; productImage.DisplayOrder = model.DisplayOrder; } productMGRepository.Update(productImage); return(RedirectToAction("index")); } return(View(model)); }