private static void SaveFiles(EditProduct editProduct, int productID) { var curList = ProductFiles.GetByProductID(productID); foreach (var file in editProduct.Files) { if (!curList.Any(item => item.ID == file.ID)) { var productFile = Mapper.Map <ProductFile>(file); productFile.ProductID = productID; ProductFiles.Insert(productFile); } else { ProductFiles.UpdateTitle(file.ID, file.Title); curList.Remove(curList.Single(cls => cls.ID == file.ID)); } } foreach (var item in curList) { ProductFiles.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)); }