public ActionResult Subcategtw(Categtw categtw) { if (ModelState.IsValid) { cont.Categtws.Add(categtw); cont.SaveChanges(); TempData["message"] = string.Format("Подкатегория товара '{0}' сохранена", categtw.Name); } return(RedirectToAction("Subcategtw")); }
public ActionResult DelCategtw(int categtwId) { Categtw deletedCategtw = cont.Categtws.Find(categtwId); if (deletedCategtw != null) { TempData["message"] = string.Format("Подкатегория '{0}' удалена", deletedCategtw.Name); cont.Categtws.Remove(deletedCategtw); cont.SaveChanges(); } return(RedirectToAction("Allcategtw")); }
// [ValidateInput(false)] // чтобы не отбрасывало хтмл или [AllowHtml] public ActionResult Create(Product product, Categzer categzer, Categone categone, Categtw categtw, HttpPostedFileBase image, object sender, EventArgs e, int[] selectedApplyings, int[] selectedPropertys, int[] selectedTechcharacters) // - создание нового товара в админке { if (ModelState.IsValid) { if (image != null) { product.ImageMimeType = image.ContentType; product.ImageData = new byte[image.ContentLength]; image.InputStream.Read(product.ImageData, 0, image.ContentLength); } TempData["message"] = string.Format("Товар '{0}' сохранен", product.Name); product.Applyings = new List <Applying>(); if (selectedApplyings != null) { foreach (var c in cont.Applyings) { if (selectedApplyings.Contains(c.ApplyingID)) { product.Applyings.Add(c); } } } product.Propers = new List <Proper>(); if (selectedPropertys != null) { foreach (var c in cont.Propers) { if (selectedPropertys.Contains(c.ProperID)) { product.Propers.Add(c); } } } if (selectedTechcharacters != null) { foreach (var c in cont.Techcharacters) { if (selectedTechcharacters.Contains(c.TechcharacterID)) { product.Techcharacters.Add(c); } } } ViewBag.Alldescription = product.Alldescription; ViewBag.Description = product.Description; ViewBag.ProducerID = new SelectList(cont.Producers, "ProducerID", "Name", product.ProducerID); ViewBag.CategoneID = new SelectList(cont.Categones, "CategoneID", "Name", product.CategoneID); ViewBag.CategtwID = new SelectList(cont.Categtws, "CategtwID", "Name", product.CategtwID); ViewBag.PackingID = new SelectList(cont.Packings, "PackingID", "Name", product.PackingID); ViewBag.CategzerID = new SelectList(cont.Categzers, "CategzerID", "Name", product.CategzerID); cont.Entry(product).State = EntityState.Modified; cont.Products.Add(product); cont.SaveChanges(); TempData["message"] = string.Format("Товар '{0}' сохранен", product.Name); } ViewBag.Techcharacters = cont.Techcharacters.ToList(); ViewBag.Applyings = cont.Applyings.ToList(); ViewBag.Propers = cont.Propers.ToList(); return(RedirectToAction("Create")); }