//----------------------------------------------------- //Редактирование косметики public ActionResult EditCosmetic(int ProductId) { Cosmetic cosmetic = cosmeticrepo.GetProductById(ProductId); CosmeticViewModel obj = Mapper.Map <CosmeticViewModel>(cosmetic); return(View(obj)); }
//------------------------------------------------------ //Добавление косметики в категорию public ActionResult AddCosmetic(int CategoryId) { TempData["CategoryName"] = repo.GetCategoryName(CategoryId); CosmeticViewModel cosmetic = new CosmeticViewModel(); return(View("AddCosmetic", cosmetic)); }
public ActionResult EditCosmetic(CosmeticViewModel obj, HttpPostedFileBase Image) { if (ModelState.IsValid) { if (Image != null) { obj.ImageMimeType = Image.ContentType; obj.ImageData = new byte[Image.ContentLength]; Image.InputStream.Read(obj.ImageData, 0, Image.ContentLength); } Cosmetic p = Mapper.Map <Cosmetic>(obj); cosmeticrepo.SaveProduct(p); TempData["message"] = String.Format("Изменения в товаре '{0}' сохранены", obj.ProductName); return(RedirectToAction("ShowProductsInCategory", "Admin", new { obj.CategoryId })); } else { return(View(obj)); } }
public ActionResult AddCosmetic(CosmeticViewModel obj, HttpPostedFileBase Image, IEnumerable <HttpPostedFileBase> Images) { if (ModelState.IsValid) { if (Image != null) { obj.ImageMimeType = Image.ContentType; obj.ImageData = new byte[Image.ContentLength]; Image.InputStream.Read(obj.ImageData, 0, Image.ContentLength); } Cosmetic prod = Mapper.Map <Cosmetic>(obj); cosmeticrepo.SaveProduct(prod); TempData["message"] = String.Format("Товар '{0}' добавлен", obj.ProductName); if (Images.First() != null) { foreach (var item in Images) { Color newColor = new Color(); newColor.CategoryId = prod.CategoryId; newColor.ProductId = prod.ProductId; newColor.ColorName = item.FileName.Substring(0, item.FileName.IndexOf(".")); newColor.ImageData = new byte[item.ContentLength]; newColor.ImageMimeType = item.ContentType; newColor.IsAvailable = true; item.InputStream.Read(newColor.ImageData, 0, item.ContentLength); colorrepo.SaveColor(newColor); } } return(RedirectToAction("Categories", "Admin")); } else { return(View(obj)); } }