public ActionResult Delete(PolicyOtherGroupItemDataTableItemVM policyOtherGroupItemDataTableItemVM) { //Check PolicyOtherGroupItemDataTableRow Exists PolicyOtherGroupItemDataTableRow policyOtherGroupItemDataTableRow = new PolicyOtherGroupItemDataTableRow(); policyOtherGroupItemDataTableRow = policyOtherGroupItemDataTableRowRepository.GetPolicyOtherGroupItemDataTableRow( policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableRow.PolicyOtherGroupItemDataTableRowId ); if (policyOtherGroupItemDataTableRow == null) { ViewData["ActionMethod"] = "DeletePost"; return(View("RecordDoesNotExistError")); } //Check Policy Exists PolicyGroup policyGroup = new PolicyGroup(); policyGroup = policyGroupRepository.GetGroup(policyOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId); if (policyGroup == null) { ViewData["ActionMethod"] = "DeletePost"; return(View("RecordDoesNotExistError")); } //Check PolicyOtherGroupHeader Exists PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader(); policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader( policyOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId ); if (policyOtherGroupHeader == null) { ViewData["ActionMethod"] = "DeletePost"; return(View("RecordDoesNotExistError")); } //Delete Form Item try { policyOtherGroupItemDataTableItemRepository.Delete(policyOtherGroupItemDataTableRow); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/PolicyOtherGroupItemDataTableItem.mvc/Delete/" + policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableRow.PolicyOtherGroupItemDataTableRowId; return(View("VersionError")); } 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")); } return(RedirectToAction("List", new { id = policyOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, policyGroupId = policyOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId })); }
//Edit public void Edit(PolicyOtherGroupItemDataTableItemVM policyOtherGroupItemDataTableItemVM) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; XmlDocument doc = ConvertPolicyOtherGroupItemDataTableItemsToXML(policyOtherGroupItemDataTableItemVM); db.spDesktopDataAdmin_UpdatePolicyOtherGroupItemDataTableItem_v1( policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableRow.PolicyOtherGroupItemDataTableRowId, System.Xml.Linq.XElement.Parse(doc.OuterXml), adminUserGuid, policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableRow.VersionNumber ); }
//Add public void Add(PolicyOtherGroupItemDataTableItemVM policyOtherGroupItemDataTableItemVM) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; XmlDocument doc = ConvertPolicyOtherGroupItemDataTableItemsToXML(policyOtherGroupItemDataTableItemVM); db.spDesktopDataAdmin_InsertPolicyOtherGroupItemDataTableItem_v1( policyOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId, policyOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, System.Xml.Linq.XElement.Parse(doc.OuterXml), adminUserGuid ); }
public ActionResult Delete(int id, int policyGroupId, int policyOtherGroupHeaderId) { PolicyOtherGroupItemDataTableItemVM policyOtherGroupItemDataTableItemVM = new PolicyOtherGroupItemDataTableItemVM(); //Check PolicyOtherGroupItemDataTableRow Exists PolicyOtherGroupItemDataTableRow policyOtherGroupItemDataTableRow = new PolicyOtherGroupItemDataTableRow(); policyOtherGroupItemDataTableRow = policyOtherGroupItemDataTableRowRepository.GetPolicyOtherGroupItemDataTableRow(id); if (policyOtherGroupItemDataTableRow == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } //Check Policy Exists PolicyGroup policyGroup = new PolicyGroup(); policyGroup = policyGroupRepository.GetGroup(policyGroupId); if (policyGroup == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } //Check PolicyOtherGroupHeader Exists PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader(); policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyOtherGroupHeaderId); if (policyOtherGroupHeader == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } policyOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader = policyOtherGroupHeader; policyGroupRepository.EditGroupForDisplay(policyGroup); policyOtherGroupItemDataTableItemVM.PolicyGroup = policyGroup; policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableRow = policyOtherGroupItemDataTableRow; List <PolicyOtherGroupItemDataTableItem> policyOtherGroupItemDataTableItems = new List <PolicyOtherGroupItemDataTableItem>(); policyOtherGroupItemDataTableItems = policyOtherGroupItemDataTableRowRepository.GetPolicyOtherGroupItemDataTableItems(id, policyOtherGroupHeaderId); if (policyOtherGroupItemDataTableItems != null) { policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableItems = policyOtherGroupItemDataTableItems; } return(View(policyOtherGroupItemDataTableItemVM)); }
//Loop through PolicyOtherGroupItemDataTableItems into XML public XmlDocument ConvertPolicyOtherGroupItemDataTableItemsToXML(PolicyOtherGroupItemDataTableItemVM policyOtherGroupItemDataTableItemVM) { XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null); doc.AppendChild(dec); XmlElement root = doc.CreateElement("PolicyOtherGroupItemDataTableItems"); doc.AppendChild(root); if (policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableItems != null) { if (policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableItems.Count > 0) { XmlElement xmlPolicyOtherGroupItemDataTableItems = doc.CreateElement("PolicyOtherGroupItemDataTableItems"); foreach (PolicyOtherGroupItemDataTableItem item in policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableItems) { if (item != null && !string.IsNullOrEmpty(item.TableDataItem)) { XmlElement xmlPolicyOtherGroupItemDataTableItem = doc.CreateElement("PolicyOtherGroupItemDataTableItem"); XmlElement xmlPolicyOtherGroupItemDataTableItem_TableDataItem = doc.CreateElement("TableDataItem"); xmlPolicyOtherGroupItemDataTableItem_TableDataItem.InnerText = item.TableDataItem; xmlPolicyOtherGroupItemDataTableItem.AppendChild(xmlPolicyOtherGroupItemDataTableItem_TableDataItem); XmlElement xmlPolicyOtherGroupItemDataTableItem_PolicyOtherGroupHeaderColumnNameId = doc.CreateElement("PolicyOtherGroupHeaderColumnNameId"); xmlPolicyOtherGroupItemDataTableItem_PolicyOtherGroupHeaderColumnNameId.InnerText = item.PolicyOtherGroupHeaderColumnNameId.ToString(); xmlPolicyOtherGroupItemDataTableItem.AppendChild(xmlPolicyOtherGroupItemDataTableItem_PolicyOtherGroupHeaderColumnNameId); xmlPolicyOtherGroupItemDataTableItems.AppendChild(xmlPolicyOtherGroupItemDataTableItem); } } root.AppendChild(xmlPolicyOtherGroupItemDataTableItems); } } return(doc); }
public ActionResult Edit(PolicyOtherGroupItemDataTableItemVM policyOtherGroupItemDataTableItemVM, FormCollection formCollection) { //Check Policy Exists PolicyGroup policyGroup = new PolicyGroup(); policyGroup = policyGroupRepository.GetGroup(policyOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId); if (policyGroup == null) { ViewData["ActionMethod"] = "CreatePost"; return(View("RecordDoesNotExistError")); } //Check PolicyOtherGroupHeader Exists PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader(); policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId); if (policyOtherGroupHeader == null) { ViewData["ActionMethod"] = "CreatePost"; return(View("RecordDoesNotExistError")); } //We need to extract group from groupVM List <PolicyOtherGroupItemDataTableItem> policyOtherGroupItemDataTableItems = new List <PolicyOtherGroupItemDataTableItem>(); foreach (string item in formCollection) { if (item.StartsWith("PolicyOtherGroupHeaderColumnNameId")) { PolicyOtherGroupItemDataTableItem policyOtherGroupItemDataTableItem = new PolicyOtherGroupItemDataTableItem() { PolicyOtherGroupHeaderColumnNameId = Int32.Parse(item.Replace("PolicyOtherGroupHeaderColumnNameId_", "")), TableDataItem = formCollection[item] }; policyOtherGroupItemDataTableItems.Add(policyOtherGroupItemDataTableItem); } } if (policyOtherGroupItemDataTableItems.Count() <= 0) { ViewData["Message"] = "ValidationError : missing item";; return(View("Error")); } policyOtherGroupItemDataTableItemVM.PolicyOtherGroupItemDataTableItems = policyOtherGroupItemDataTableItems; //Update Model From Form + Validate against DB try { UpdateModel <PolicyOtherGroupItemDataTableItemVM>(policyOtherGroupItemDataTableItemVM, "PolicyOtherGroupItemDataTableItemVM"); } 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 { policyOtherGroupItemDataTableItemRepository.Edit(policyOtherGroupItemDataTableItemVM); } 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 = policyOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, policyGroupId = policyOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId })); }