public ActionResult InsertNormaNomGroup() { string NormaContentId = null; int NormaId = 0; if (Session["NormaContentId"] != null) { NormaContentId = Session["NormaContentId"].ToString(); } if (Session["NormaId"] != null) { NormaId = int.Parse(Session["NormaId"].ToString()); } NormaNomGroup normaNomGroup = new NormaNomGroup(); if (TryUpdateModel <NormaNomGroup>(normaNomGroup)) { ValidateNormaNomGroup(int.Parse(NormaContentId), normaNomGroup); normaNomGroup.IsBase = false; normaNomGroup.NormaContent = normaContentRepository.Get(int.Parse(NormaContentId)); if (ModelState.IsValid) { normaNomGroupRepository.SaveOrUpdate(normaNomGroup); ChangeContentIns(normaNomGroup); } } return(_Selection_NormaNomGroups(NormaContentId)); }
public static NormaContent rebuildNormaContent(NormaContent inNormaContent) { NormaContent normaContent = new NormaContent(inNormaContent.Id, inNormaContent.Quantity, inNormaContent.UsePeriod); normaContent.NormaId = inNormaContent.NormaId; normaContent.IsActive = inNormaContent.IsActive; // if (inNormaContent.QuantityTON != 0) normaContent.QuantityTON = inNormaContent.QuantityTON; // else // normaContent.QuantityTON = inNormaContent.Quantity; NomGroup nomGroup = rebuildNomGroup(inNormaContent.NomGroup); normaContent.NomGroup = nomGroup; normaContent.InShop = inNormaContent.InShop; List <NormaNomGroup> normaNomGroups = new List <NormaNomGroup>(); foreach (var item in inNormaContent.NormaNomGroups) { NormaNomGroup normaNomGroup = rebuildNormaNomGroup(item); normaNomGroups.Add(normaNomGroup); } normaContent.NormaNomGroups = normaNomGroups; string normaContentInfo = ""; foreach (var item in normaContent.NormaNomGroups) { if (item.IsBase == false) { normaContentInfo = normaContentInfo + item.NomGroup.Name + "; "; } } normaContent.NormaContentInfo = normaContentInfo; return(normaContent); }
public ActionResult SaveNormaNomGroup(string id) { string NormaContentId = null; if (Session["NormaContentId"] != null) { NormaContentId = Session["NormaContentId"].ToString(); } // NormaNomGroup normaNomGroup = new NormaNomGroup(); NormaNomGroup newNormaNomGroup = normaNomGroupRepository.Get(int.Parse(id)); NormaNomGroup normaNomGroup = new NormaNomGroup(); normaNomGroup.NomGroup = newNormaNomGroup.NomGroup; NormaContent normaContent = normaContentRepository.Get(int.Parse(NormaContentId)); if (TryUpdateModel <NormaNomGroup>(normaNomGroup, null, new string[] { "NomGroup" }, new string[] { "NormaContent" })) { if (normaNomGroup.NomGroup.Id != newNormaNomGroup.NomGroup.Id) { ValidateNormaNomGroup(normaContent.Id, normaNomGroup); } if (ModelState.IsValid) { newNormaNomGroup.NormaContent = normaContent; newNormaNomGroup.NomGroup = normaNomGroup.NomGroup; normaNomGroupRepository.SaveOrUpdate(newNormaNomGroup); ChangeContentIns(newNormaNomGroup); } } return(_Selection_NormaNomGroups(NormaContentId)); }
public ActionResult InsertContent() { int NormaId = int.Parse(Session["NormaId"].ToString()); NormaContent normaContent = new NormaContent(); IList <NormaNomGroup> normaNomGroups = new List <NormaNomGroup>(); TryUpdateModel(normaContent); { ValidateContent(NormaId, normaContent, true); if (ModelState.IsValid) { normaContent.NormaId = NormaId; NormaNomGroup normaNomGroup = new NormaNomGroup(); normaNomGroup.NomGroup = normaContent.NomGroup; normaNomGroup.IsBase = true; normaNomGroup.NormaContent = normaContent; normaNomGroups.Add(normaNomGroup); normaContent.NormaNomGroups = normaNomGroups; normaContent.IsActive = true; normaContentRepository.SaveOrUpdate(normaContent); ChangeContentIns(normaNomGroup); } } return(_SelectionClientSide_NormaContents(NormaId.ToString())); }
public static NormaNomGroup rebuildNormaNomGroup(NormaNomGroup inNormaNomGroup) { NormaNomGroup normaNomGroup = new NormaNomGroup(inNormaNomGroup.Id); normaNomGroup.NomGroup = rebuildNomGroup(inNormaNomGroup.NomGroup); normaNomGroup.IsBase = inNormaNomGroup.IsBase; NormaContent nc = new NormaContent(inNormaNomGroup.NormaContent.Id); normaNomGroup.NormaContent = nc; return(normaNomGroup); }
public ActionResult DeleteNormaNomGroup(int Id) { NormaNomGroup normaNomGroup = normaNomGroupRepository.Get(Id); string NormaContentId = null; //if (HttpContext.Cache.Get("NormaContentId") != null) // NormaContentId = HttpContext.Cache.Get("NormaContentId").ToString(); if (Session["NormaContentId"] != null) { NormaContentId = Session["NormaContentId"].ToString(); } normaNomGroupRepository.Delete(normaNomGroup); return(_Selection_NormaNomGroups(NormaContentId)); }
public ActionResult Copy(string Id) { Norma norma = normaRepository.Get(int.Parse(Id)); Norma newNorma = new Norma(); newNorma.Organization = norma.Organization; newNorma.Name = norma.Name + " (Копия)"; newNorma.IsActive = norma.IsActive; newNorma.NormaComment = norma.NormaComment; normaRepository.SaveOrUpdate(newNorma); Dictionary <string, object> queryParams = new Dictionary <string, object>(); queryParams.Add("NormaId", int.Parse(Id)); queryParams.Add("IsActive", true); Dictionary <string, object> orderParams = new Dictionary <string, object>(); orderParams.Add("Id", ASC); IEnumerable <NormaContent> normaContents = normaContentRepository.GetByCriteria(queryParams, orderParams); foreach (var item in normaContents) { NormaContent nc = new NormaContent(); nc.Quantity = item.Quantity; nc.QuantityTON = item.QuantityTON; nc.UsePeriod = item.UsePeriod; nc.IsActive = item.IsActive; nc.NormaId = newNorma.Id; nc.NomGroup = item.NomGroup; nc.InShop = item.InShop; normaContentRepository.SaveOrUpdate(nc); foreach (var nng in item.NormaNomGroups) { NomGroup nomGroup = new NomGroup(nng.NomGroup.Id, nng.NomGroup.Name); NomBodyPart nb = new NomBodyPart(nng.NomGroup.NomBodyPart.Id, nng.NomGroup.NomBodyPart.Name); Organization o = rebuildOrganization(nng.NomGroup.Organization); nomGroup.Organization = o; nomGroup.NomBodyPart = nb; NormaNomGroup ng = new NormaNomGroup(); ng.NomGroup = nomGroup; ng.IsBase = nng.IsBase; ng.NormaContent = nc; normaNomGroupRepository.SaveOrUpdate(ng); } } ; return(View(viewName)); // return _SelectionClientSide_Normas(); }
public ActionResult _Selection_NormaNomGroups(string NormaContentId) { Dictionary <string, object> queryParams = new Dictionary <string, object>(); List <NormaNomGroup> model = new List <NormaNomGroup>(); int idNormaContent = 0; if (NormaContentId == null) { if (Session["NormaId"] != null) { if (Session["NormaContentId"] != null) { idNormaContent = int.Parse(Session["NormaContentId"].ToString()); } } } else { idNormaContent = int.Parse(NormaContentId); } if (idNormaContent != 0) { Session.Add("NormaContentId", idNormaContent); queryParams.Add("NormaContent.Id", idNormaContent); Dictionary <string, object> orderParams = new Dictionary <string, object>(); orderParams.Add("NomGroup.Name", ASC); IEnumerable <NormaNomGroup> normaNomGroups = normaNomGroupRepository.GetByLikeCriteria(queryParams, orderParams); foreach (var item in normaNomGroups) { if (item.IsBase != true) { NormaNomGroup nng = rebuildNormaNomGroup(item); model.Add(nng); } } } return(View(new GridModel <NormaNomGroup> { Data = model })); }
public void ValidateNormaNomGroup(int NormaContentId, NormaNomGroup normaNomGroup) { NormaContent normaContent = normaContentRepository.Get(NormaContentId); Dictionary <string, object> queryParams = new Dictionary <string, object>(); queryParams.Add("NormaId", normaContent.NormaId); queryParams.Add("IsActive", true); IList <NormaContent> normaContents = normaContentRepository.FindAll(queryParams); foreach (var nc in normaContents) { queryParams.Clear(); queryParams.Add("NormaContent", nc); IList <NormaNomGroup> normaNomGroups = normaNomGroupRepository.FindAll(queryParams); foreach (var nng in normaNomGroups) { if (nng.NomGroup.Id == normaNomGroup.NomGroup.Id) { ModelState.AddModelError(nng.NomGroup.Id.ToString(), "Группа " + normaNomGroup.NomGroup.Name + " уже добавлена в норму"); } } } }
public void ChangeContentIns(NormaNomGroup normaNomgroup) { Dictionary <string, object> queryParams = new Dictionary <string, object>(); queryParams.Add("NormaId", normaNomgroup.NormaContent.NormaId); // queryParams.Add("IsActive", false); // queryParams.Add("InShop", false); IList <NormaContent> normaContents = normaContentRepository.FindAll(queryParams); foreach (var item in normaContents) { queryParams.Clear(); queryParams.Add("NormaContent.Id", item.Id); IList <WorkerCardContent> workerCardContents = workerCardContentRepository.FindAll(queryParams); foreach (var wcc in workerCardContents) { if (wcc.Storage.Nomenclature.NomGroup.Id == normaNomgroup.NomGroup.Id) { wcc.NormaContent = normaNomgroup.NormaContent; workerCardContentRepository.SaveOrUpdate(wcc); } } } }