public ActionResult Edit(int id) { LFileViewModel model = new LFileViewModel(); LFile doc = lfileRepo.LFiles.Where(p => p.LFile_ID == id).FirstOrDefault(); model.Document = doc; List <Struct> structs = structRepo.Structs.Where(s => s.LFile_ID == doc.LFile_ID).ToList(); // and all the structures linked to every document AddRowViewModel rowview = new AddRowViewModel(); List <StructPosViewModel> strpos = new List <StructPosViewModel>(); foreach (var st in structs) { //we create the list of StructPosViewModel for each doc StructPosViewModel strpvm = new StructPosViewModel { ID = st.ID, Name = st.St_Name, Description = st.St_Description, Order = (int)st.Order_In_Doc }; strpos.Add(strpvm); } ; ViewBag.Action = "edit"; ViewBag.FieldName = structRepo.Structs.AsEnumerable(); rowview.NewStId = 0; rowview.Posit = 0; rowview.StructurePos = strpos; model.DocStructs = rowview; return(PartialView("_Create", model)); }
// GET: Document public ActionResult Index(int?id = 0) { List <LFileViewModel> model = new List <LFileViewModel>(); List <LFile> lfiles = lfileRepo.LFiles.ToList(); foreach (var n in lfiles) // we iterate over all the documents { LFileViewModel mod = new LFileViewModel { Document = n }; List <Struct> structs = structRepo.Structs.Where(s => s.LFile_ID == n.LFile_ID).ToList(); // and all the structures linked to every document AddRowViewModel rowview = new AddRowViewModel(); List <StructPosViewModel> strpos = new List <StructPosViewModel>(); foreach (var st in structs) //we create the list of StructPosViewModel for each doc { StructPosViewModel strpvm = new StructPosViewModel { ID = st.ID, Name = st.St_Name, Description = st.St_Description, Order = (int)st.Order_In_Doc }; strpos.Add(strpvm); } ; rowview.NewStId = 0; rowview.Posit = 0; rowview.StructurePos = strpos; mod.DocStructs = rowview; model.Add(mod); } if (id != 0) { ViewBag.Element = id; } else if (model.Count() > 0) { ViewBag.Element = model[0].Document.LFile_ID; } else { ViewBag.Element = 0; } ViewBag.Action = "index"; return(View(model)); }
public ActionResult Create() { LFileViewModel lfvmodel = new LFileViewModel(); AddRowViewModel spmodel = new AddRowViewModel(); List <StructPosViewModel> listStr = new List <StructPosViewModel>(); spmodel.StructurePos = listStr; lfvmodel.DocStructs = spmodel; return(PartialView("_Create", lfvmodel)); }
public ActionResult Create(LFileViewModel inbModel) { try { if (ModelState.IsValid) { if (inbModel.Document.LFile_ID > 0) { //if the document already exist lfileRepo.SaveLFile(inbModel.Document); List <Struct> strInDoc = structRepo.Structs.Where(p => p.LFile_ID == inbModel.Document.LFile_ID).ToList(); foreach (var p in strInDoc) { bool found = false; foreach (var n in inbModel.DocStructs.StructurePos) { if (p.ID == n.ID) { found = true; var struc = structRepo.Structs.Where(k => k.ID == p.ID).FirstOrDefault(); struc.Order_In_Doc = n.Order; structRepo.SaveStruct(struc); } } if (!found) { p.Order_In_Doc = 0; p.LFile_ID = 0; p.LFile = null; structRepo.SaveStruct(p); } } } else // document is new { lfileRepo.SaveLFile(inbModel.Document); foreach (var n in inbModel.DocStructs.StructurePos) { Struct str = structRepo.Structs.Where(k => k.ID == n.ID).FirstOrDefault(); str.LFile_ID = inbModel.Document.LFile_ID; str.Order_In_Doc = n.Order; structRepo.SaveStruct(str); } } if (inbModel.Document.LFile_ID > 0) { ViewBag.Action = "Edited"; } else { ViewBag.Action = "Created"; } return(PartialView("_DocumEditSuccess")); } else { return(PartialView("_Create", inbModel)); } } catch (Exception ex) { return(new HttpStatusCodeResult(404, "Error in cloud - GetPLUInfo" + ex.Message)); } }
public ActionResult Create(LFileViewModel inbModel) { try { if (ModelState.IsValid) { if (inbModel.Document.LFile_ID > 0) { //if the document already exist lfileRepo.SaveLFile(inbModel.Document); List <Struct> strInDoc = structRepo.Structs.Where(p => p.LFile_ID == inbModel.Document.LFile_ID).ToList(); IEnumerable <StructPosViewModel> st_inp = inbModel.DocStructs.StructurePos.AsEnumerable(); foreach (var p in strInDoc) { var element = st_inp.Where(k => k.ID == p.ID).FirstOrDefault(); if (element != null) { p.Order_In_Doc = element.Order; structRepo.SaveStruct(p); } else { p.LFile_ID = 0; p.Order_In_Doc = 0; structRepo.SaveStruct(p); } } foreach (var inp_element in inbModel.DocStructs.StructurePos) { Struct new_value = structRepo.Structs.Where(k => k.ID == inp_element.ID).FirstOrDefault(); if (new_value.LFile_ID != inbModel.Document.LFile_ID) { new_value.LFile_ID = inbModel.Document.LFile_ID; structRepo.SaveStruct(new_value); } } } else // document is new { lfileRepo.SaveLFile(inbModel.Document); foreach (var n in inbModel.DocStructs.StructurePos) { Struct str = structRepo.Structs.Where(k => k.ID == n.ID).FirstOrDefault(); str.LFile_ID = inbModel.Document.LFile_ID; str.Order_In_Doc = n.Order; structRepo.SaveStruct(str); } } if (inbModel.Document.LFile_ID > 0) { ViewBag.Action = "Edited"; } else { ViewBag.Action = "Created"; } return(PartialView("_DocumEditSuccess")); } else { return(PartialView("_Create", inbModel)); } } catch (Exception ex) { return(new HttpStatusCodeResult(404, "Error in cloud - GetPLUInfo" + ex.Message)); } }