public ActionResult NewType(Int32 id, Int32 sid, Int32 tid) { var TypeCont = new TypeConteiner(); if (id == 0) { var Main = new ProdType() { Id = -1 }; TypeCont.Main.Add(Main); } else if (sid == 0) { var Sub = new SubType() { Id = -1 }; TypeCont.SubList.Add(Sub); } else if (tid == 0) { var Th = new ThSubType() { Id = -1 }; TypeCont.ThList.Add(Th); } return(View("TypeForm", TypeCont)); }
public ActionResult SaveType(TypeConteiner TypeCont) { if (!ModelState.IsValid) { return(View("TypeForm", TypeCont)); } if (TypeCont.Main.ToList().Count() > 0) { if (TypeCont.Main[0].Id == -1) { var Main = new ProdType(); Main.RusName = TypeCont.Main[0].RusName; Main.EngName = TypeCont.Main[0].EngName; Main.Icon = TypeCont.Main[0].Icon; _DBdata.ProdType.Add(Main); _DBdata.SaveChanges(); } else { var index = TypeCont.Main[0].Id; var Main = _DBdata.ProdType.SingleOrDefault(m => m.Id == index); if (Main == null) { return(HttpNotFound()); } Main.RusName = TypeCont.Main[0].RusName; Main.EngName = TypeCont.Main[0].EngName; Main.Icon = TypeCont.Main[0].Icon; _DBdata.SaveChanges(); } } else if (TypeCont.SubList.ToList().Count() > 0) { if (TypeCont.SubList[0].Id == -1) { var Sub = new SubType(); Sub.ProdTypeId = TypeCont.SubList[0].ProdTypeId; Sub.SubTypeName = TypeCont.SubList[0].SubTypeName; _DBdata.SubType.Add(Sub); _DBdata.SaveChanges(); } else { var index = TypeCont.SubList[0].Id; var Sub = _DBdata.SubType.SingleOrDefault(s => s.Id == index); if (Sub == null) { return(HttpNotFound()); } Sub.ProdTypeId = TypeCont.SubList[0].ProdTypeId; Sub.SubTypeName = TypeCont.SubList[0].SubTypeName; _DBdata.SaveChanges(); } } else if (TypeCont.ThList.ToList().Count() > 0) { if (TypeCont.ThList[0].Id == -1) { var Th = new ThSubType(); Th.SubTypeId = TypeCont.ThList[0].SubTypeId; Th.SubTypeName = TypeCont.ThList[0].SubTypeName; _DBdata.ThSubType.Add(Th); _DBdata.SaveChanges(); } else { var index = TypeCont.ThList[0].Id; var Th = _DBdata.ThSubType.SingleOrDefault(t => t.Id == index); if (Th == null) { return(HttpNotFound()); } Th.SubTypeId = TypeCont.ThList[0].SubTypeId; Th.SubTypeName = TypeCont.ThList[0].SubTypeName; _DBdata.SaveChanges(); } } return(RedirectToAction("TypeList", "Manager")); }