//Get items public List <PolicyAllOtherGroupItemDataTableItem> GetPolicyAllOtherGroupItemDataTableItems(int policyGroupId, int policyOtherGroupHeaderId) { List <PolicyAllOtherGroupItemDataTableItem> policyAllOtherGroupItemDataTableItems = new List <PolicyAllOtherGroupItemDataTableItem>(); PolicyAllOtherGroupItem policyAllOtherGroupItem = new PolicyAllOtherGroupItem(); PolicyAllOtherGroupItemRepository policyAllOtherGroupItemRepository = new PolicyAllOtherGroupItemRepository(); policyAllOtherGroupItem = policyAllOtherGroupItemRepository.GetPolicyAllOtherGroupItem(policyGroupId, policyOtherGroupHeaderId); //Get Columns List <PolicyOtherGroupHeaderColumnName> policyOtherGroupHeaderColumnNames = new List <PolicyOtherGroupHeaderColumnName>(); PolicyOtherGroupHeaderColumnNameRepository policyOtherGroupHeaderColumnNameRepository = new PolicyOtherGroupHeaderColumnNameRepository(); policyOtherGroupHeaderColumnNames = policyOtherGroupHeaderColumnNameRepository.GetPolicyOtherGroupHeaderColumnNames(policyOtherGroupHeaderId); if (policyOtherGroupHeaderColumnNames != null) { foreach (PolicyOtherGroupHeaderColumnName item in policyOtherGroupHeaderColumnNames) { PolicyAllOtherGroupItemDataTableItem policyAllOtherGroupItemDataTableItem = new PolicyAllOtherGroupItemDataTableItem() { PolicyOtherGroupHeaderColumnNameId = item.PolicyOtherGroupHeaderColumnNameId, PolicyOtherGroupHeaderColumnName = item }; policyAllOtherGroupItemDataTableItems.Add(policyAllOtherGroupItemDataTableItem); } } return(policyAllOtherGroupItemDataTableItems); }
//Get items public List <PolicyAllOtherGroupItemDataTableItem> GetPolicyAllOtherGroupItemDataTableItems(int policyAllOtherGroupItemDataTableRowId, int policyOtherGroupHeaderId) { List <PolicyAllOtherGroupItemDataTableItem> policyAllOtherGroupItemDataTableItems = new List <PolicyAllOtherGroupItemDataTableItem>(); List <int> policyOtherGroupHeaderColumnNameIds = new List <int>(); //Get Completed Columns List <PolicyAllOtherGroupItemDataTableItem> policyAllOtherGroupItemDataTableItemsCompleted = new List <PolicyAllOtherGroupItemDataTableItem>(); policyAllOtherGroupItemDataTableItemsCompleted = db.PolicyAllOtherGroupItemDataTableItems.Where( c => c.PolicyAllOtherGroupItemDataTableRowId == policyAllOtherGroupItemDataTableRowId ).ToList(); foreach (PolicyAllOtherGroupItemDataTableItem policyAllOtherGroupItemDataTableItem in policyAllOtherGroupItemDataTableItemsCompleted) { policyAllOtherGroupItemDataTableItems.Add(policyAllOtherGroupItemDataTableItem); policyOtherGroupHeaderColumnNameIds.Add(policyAllOtherGroupItemDataTableItem.PolicyOtherGroupHeaderColumnNameId); } //Get Empty Columns List <PolicyOtherGroupHeaderColumnName> policyOtherGroupHeaderColumnNames = new List <PolicyOtherGroupHeaderColumnName>(); PolicyOtherGroupHeaderColumnNameRepository policyOtherGroupHeaderColumnNameRepository = new PolicyOtherGroupHeaderColumnNameRepository(); policyOtherGroupHeaderColumnNames = policyOtherGroupHeaderColumnNameRepository.GetIncompletePolicyOtherGroupHeaderColumnNames( policyOtherGroupHeaderId, policyOtherGroupHeaderColumnNameIds); foreach (PolicyOtherGroupHeaderColumnName item in policyOtherGroupHeaderColumnNames) { PolicyAllOtherGroupItemDataTableItem policyAllOtherGroupItemDataTableItem = new PolicyAllOtherGroupItemDataTableItem() { PolicyOtherGroupHeaderColumnNameId = item.PolicyOtherGroupHeaderColumnNameId, PolicyOtherGroupHeaderColumnName = item }; policyAllOtherGroupItemDataTableItems.Add(policyAllOtherGroupItemDataTableItem); } return(policyAllOtherGroupItemDataTableItems); }
public ActionResult Edit(PolicyAllOtherGroupItemDataTableItemVM policyAllOtherGroupItemDataTableItemVM, FormCollection formCollection) { //Check Policy Exists PolicyGroup policyGroup = new PolicyGroup(); policyGroup = policyGroupRepository.GetGroup(policyAllOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId); if (policyGroup == null) { ViewData["ActionMethod"] = "CreatePost"; return(View("RecordDoesNotExistError")); } //Check PolicyOtherGroupHeader Exists PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader(); policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyAllOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId); if (policyOtherGroupHeader == null) { ViewData["ActionMethod"] = "CreatePost"; return(View("RecordDoesNotExistError")); } //We need to extract group from groupVM List <PolicyAllOtherGroupItemDataTableItem> policyAllOtherGroupItemDataTableItems = new List <PolicyAllOtherGroupItemDataTableItem>(); foreach (string item in formCollection) { if (item.StartsWith("PolicyOtherGroupHeaderColumnNameId")) { PolicyAllOtherGroupItemDataTableItem policyAllOtherGroupItemDataTableItem = new PolicyAllOtherGroupItemDataTableItem() { PolicyOtherGroupHeaderColumnNameId = Int32.Parse(item.Replace("PolicyOtherGroupHeaderColumnNameId_", "")), TableDataItem = formCollection[item] }; policyAllOtherGroupItemDataTableItems.Add(policyAllOtherGroupItemDataTableItem); } } if (policyAllOtherGroupItemDataTableItems.Count() <= 0) { ViewData["Message"] = "ValidationError : missing item";; return(View("Error")); } policyAllOtherGroupItemDataTableItemVM.PolicyAllOtherGroupItemDataTableItems = policyAllOtherGroupItemDataTableItems; //Update Model From Form + Validate against DB try { UpdateModel <PolicyAllOtherGroupItemDataTableItemVM>(policyAllOtherGroupItemDataTableItemVM, "PolicyAllOtherGroupItemDataTableItemVM"); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } //Database Update try { policyAllOtherGroupItemDataTableItemRepository.Edit(policyAllOtherGroupItemDataTableItemVM); } catch (SqlException ex) { //Non-Unique Name if (ex.Message == "NonUniqueName") { return(View("NonUniqueNameError")); } LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } ViewData["NewSortOrder"] = 0; return(RedirectToAction("List", new { id = policyAllOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, policyGroupId = policyAllOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId })); }