public ActionResult Addcategzer(Categzer categzer) { if (ModelState.IsValid) { cont.Categzers.Add(categzer); TempData["message"] = string.Format("Раздел товара '{0}' сохранена", categzer.Name); cont.SaveChanges(); } return(RedirectToAction("Allcategzer")); }
public ActionResult Edcategzer(Categzer categzer, HttpPostedFileBase image) { if (ModelState.IsValid) { Categzer dbEntry = cont.Categzers.Find(categzer.CategzerID); if (dbEntry != null) { dbEntry.Name = categzer.Name; dbEntry.SectoneID = categzer.SectoneID; cont.Entry(dbEntry).State = EntityState.Modified; TempData["message"] = string.Format("Товар '{0}' сохранен", categzer.Name); cont.SaveChanges(); } return(RedirectToAction("Allcategzer")); } else { // there is something wrong with the data values return(View(categzer)); } }
public ViewResult Edcategzer(int categzerId) { Categzer categzer = repository.Categzers.FirstOrDefault(p => p.CategzerID == categzerId); return(View(categzer)); }
// [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")); }