private static void SaveImages(EditProduct editProduct, int productID) { var curList = ProductImages.GetByProductID(productID); foreach (var image in editProduct.Images) { if (!curList.Any(item => item.ID == image.ID)) { var productImage = Mapper.Map <ProductImage>(image); productImage.ProductID = productID; ProductImages.Insert(productImage); } else { ProductImages.UpdateProductImagePlace(image.ID, image.ProductImagePlace); curList.Remove(curList.Single(cls => cls.ID == image.ID)); } } foreach (var item in curList) { ProductImages.Delete(item.ID); } }
public ActionResult Edit(int?id) { EditProduct editProduct; if (id.HasValue) { editProduct = Mapper.Map <EditProduct>(Products.GetByID(id.Value)); editProduct.Text = HttpUtility.HtmlDecode(editProduct.Text); editProduct.GroupUrlPerfix = Groups.GetByID(editProduct.GroupID.Value).UrlPerfix; editProduct.Groups = ProductGroups.GetByProductID(editProduct.ID).Select(item => item.GroupID).ToList(); editProduct.Images = ProductImages.GetByProductID(editProduct.ID); editProduct.Files = ProductFiles.GetByProductID(editProduct.ID); editProduct.Marks = ProductMarks.GetByProductID(editProduct.ID); editProduct.Points = ProductPoints.GetByProductID(editProduct.ID); editProduct.Keywords = ProductKeywords.GetByProductID(editProduct.ID); editProduct.Notes = ProductNotes.GetByProductID(editProduct.ID); editProduct.ProductPricesLinks = ProductPricesLinks.GetByProductID(editProduct.ID); editProduct.Supplies = ProductSupplies.GetByProductID(editProduct.ID); editProduct.Prices = ProductPrices.GetByProductID(editProduct.ID); editProduct.Varients = ProductVarients.GetByProductID(editProduct.ID); editProduct.Discounts = ProductDiscounts.GetAllByProductID(editProduct.ID); } else { editProduct = new EditProduct(); editProduct.userID = UserID; } return(View(editProduct)); }