public ActionResult Create(ProductModel request) { if (ModelState.IsValid) { try { var model = new Product { Id = request.Id, ServiceId = request.ServiceId, ProductTypeId = request.ProductTypeId, Name = request.Name, Description = request.Description, TimeCost = TimeUtils.TimeToUt(request.TimeCost), IsActive = true }; if (Session["Dummy"] != null) { var dummy = (DummyModel)Session["Dummy"]; if (dummy.NailDesigns.Any(i => i != null)) { var newDummy = new Dummye(); db.Dummyes.Add(newDummy); model.Dummye = newDummy; model.DummyId = newDummy.Id; model.Dummye.ServiceId = request.ServiceId; model.Dummye.h1Id = dummy.NailDesigns[0]?.Id; model.Dummye.h2Id = dummy.NailDesigns[1]?.Id; model.Dummye.h3Id = dummy.NailDesigns[2]?.Id; model.Dummye.h4Id = dummy.NailDesigns[3]?.Id; model.Dummye.h5Id = dummy.NailDesigns[4]?.Id; model.Dummye.h6Id = dummy.NailDesigns[5]?.Id; model.Dummye.h7Id = dummy.NailDesigns[6]?.Id; model.Dummye.h8Id = dummy.NailDesigns[7]?.Id; model.Dummye.h9Id = dummy.NailDesigns[8]?.Id; model.Dummye.h10Id = dummy.NailDesigns[9]?.Id; } } db.Products.Add(model); db.SaveChanges(); return(RedirectToAction("List")); } catch (Exception exc) { ModelState.AddModelError("", "Что то пошло не так."); } } InitFilds(); return(PartialView(request)); }
public ActionResult Edit(ProductModel request) { if (ModelState.IsValid) { try { var model = db.Products.Find(request.Id); var dummy = (DummyModel)Session["Dummy"]; if (dummy.NailDesigns.Any(i => i != null)) { if (model.Dummye == null) { var newDummy = new Dummye(); db.Dummyes.Add(newDummy); model.Dummye = newDummy; model.DummyId = newDummy.Id; } model.Dummye.ServiceId = request.ServiceId; model.Dummye.h1Id = dummy.NailDesigns[0]?.Id; model.Dummye.h2Id = dummy.NailDesigns[1]?.Id; model.Dummye.h3Id = dummy.NailDesigns[2]?.Id; model.Dummye.h4Id = dummy.NailDesigns[3]?.Id; model.Dummye.h5Id = dummy.NailDesigns[4]?.Id; model.Dummye.h6Id = dummy.NailDesigns[5]?.Id; model.Dummye.h7Id = dummy.NailDesigns[6]?.Id; model.Dummye.h8Id = dummy.NailDesigns[7]?.Id; model.Dummye.h9Id = dummy.NailDesigns[8]?.Id; model.Dummye.h10Id = dummy.NailDesigns[9]?.Id; } else { if (model.Dummye != null) { db.Dummyes.Remove(model.Dummye); model.DummyId = null; } } model.ServiceId = request.ServiceId; model.ProductTypeId = request.ProductTypeId; model.Name = request.Name; model.Description = request.Description; model.TimeCost = TimeUtils.TimeToUt(request.TimeCost); db.SaveChanges(); return(RedirectToAction("List")); } catch (Exception exc) { Console.WriteLine(exc); } } InitFilds(); return(PartialView(request)); }