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)); }
public ActionResult Edit(EditProduct editProduct, string score, string chkSendSms) { try { float scoreValue = score != "" ? float.Parse(score) : 0; var product = Mapper.Map <Product>(editProduct); product.LastUpdate = DateTime.Now; product.ProductScore = scoreValue; ViewBag.Success = true; int productID = product.ID; if (productID == -1) { if (base.IsAdmin) { product.ProductStatus = editProduct.ProductStatus; } else { product.ProductStatus = ProductStatus.NotChecked; } product.UserID = base.UserID; product.CreatedDate = DateTime.Now; Products.Insert(product); productID = product.ID; string[] dKeys = GetDefaultKeys(editProduct); SaveGroups(editProduct, productID); SaveImages(editProduct, productID); SaveFiles(editProduct, productID); SaveMarks(editProduct, productID); SavePoints(editProduct, productID); SaveKeywords(editProduct, productID); SaveDefaultKeywords(dKeys, productID); SaveNotes(editProduct, productID, UserID); SaveProductLinks(editProduct, productID); SaveSupplies(editProduct, productID); SavePrices(editProduct, productID); SaveAttributes(Request, productID); SaveVarients(editProduct, productID); UserNotifications.Send(UserID, String.Format("جدید - محصول '{0}'", editProduct.Title), "/Admin/Products/Edit/" + editProduct.ID, NotificationType.Success); editProduct = new EditProduct(); editProduct.userID = product.UserID; } else { Products.Update(product); SaveGroups(editProduct, productID); SaveImages(editProduct, productID); SaveFiles(editProduct, productID); SaveMarks(editProduct, productID); SavePoints(editProduct, productID); SaveKeywords(editProduct, productID); SaveNotes(editProduct, productID, UserID); SaveProductLinks(editProduct, productID); SaveSupplies(editProduct, productID); SavePrices(editProduct, productID); SaveAttributes(Request, productID); SaveVarients(editProduct, productID); editProduct.Text = HttpUtility.HtmlDecode(editProduct.Text); editProduct.Groups = ProductGroups.GetByProductID(editProduct.ID).Select(item => item.GroupID).ToList(); editProduct.Supplies = ProductSupplies.GetByProductID(editProduct.ID); editProduct.Prices = ProductPrices.GetByProductID(editProduct.ID); editProduct.Varients = ProductVarients.GetByProductID(editProduct.ID); editProduct.Keywords = ProductKeywords.GetByProductID(editProduct.ID); editProduct.Notes = ProductNotes.GetByProductID(editProduct.ID); editProduct.userID = product.UserID; editProduct.GroupUrlPerfix = Groups.GetByID(editProduct.GroupID.Value).UrlPerfix; editProduct.ProductScore = scoreValue; if (chkSendSms == "on") { SendMessageToRequests(editProduct, productID); } } Products.UpdateIsUnavailable(product.ID); } catch (Exception ex) { SetErrors(ex); } return(ClearView(editProduct)); }