public ActionResult Delete(PolicyOnlineOtherGroupItemDataTableItemVM PolicyOnlineOtherGroupItemDataTableItemVM)
        {
            //Check PolicyOnlineOtherGroupItemDataTableRow Exists
            PolicyOnlineOtherGroupItemDataTableRow PolicyOnlineOtherGroupItemDataTableRow = new PolicyOnlineOtherGroupItemDataTableRow();

            PolicyOnlineOtherGroupItemDataTableRow = PolicyOnlineOtherGroupItemDataTableRowRepository.GetPolicyOnlineOtherGroupItemDataTableRow(
                PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableRow.PolicyOnlineOtherGroupItemDataTableRowId
                );
            if (PolicyOnlineOtherGroupItemDataTableRow == null)
            {
                ViewData["ActionMethod"] = "DeletePost";
                return(View("RecordDoesNotExistError"));
            }

            //Check Policy Exists
            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup = policyGroupRepository.GetGroup(PolicyOnlineOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId);
            if (policyGroup == null)
            {
                ViewData["ActionMethod"] = "DeletePost";
                return(View("RecordDoesNotExistError"));
            }

            //Check PolicyOtherGroupHeader Exists
            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(
                PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId
                );
            if (policyOtherGroupHeader == null)
            {
                ViewData["ActionMethod"] = "DeletePost";
                return(View("RecordDoesNotExistError"));
            }

            //Delete Form Item
            try
            {
                PolicyOnlineOtherGroupItemDataTableItemRepository.Delete(PolicyOnlineOtherGroupItemDataTableRow);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyOnlineOtherGroupItemDataTableItem.mvc/Delete/" + PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableRow.PolicyOnlineOtherGroupItemDataTableRowId;
                    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 = PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, policyGroupId = PolicyOnlineOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId }));
        }
        //Edit
        public void Edit(PolicyOnlineOtherGroupItemDataTableItemVM PolicyOnlineOtherGroupItemDataTableItemVM)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            XmlDocument doc = ConvertPolicyOnlineOtherGroupItemDataTableItemsToXML(PolicyOnlineOtherGroupItemDataTableItemVM);

            db.spDesktopDataAdmin_UpdatePolicyOnlineOtherGroupItemDataTableItem_v1(
                PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableRow.PolicyOnlineOtherGroupItemDataTableRowId,
                System.Xml.Linq.XElement.Parse(doc.OuterXml),
                adminUserGuid,
                PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableRow.VersionNumber
                );
        }
        //Add
        public void Add(PolicyOnlineOtherGroupItemDataTableItemVM PolicyOnlineOtherGroupItemDataTableItemVM)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            XmlDocument doc = ConvertPolicyOnlineOtherGroupItemDataTableItemsToXML(PolicyOnlineOtherGroupItemDataTableItemVM);

            db.spDesktopDataAdmin_InsertPolicyOnlineOtherGroupItemDataTableItem_v1(
                PolicyOnlineOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId,
                PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId,
                System.Xml.Linq.XElement.Parse(doc.OuterXml),
                adminUserGuid
                );
        }
        public ActionResult Delete(int id, int policyGroupId, int policyOtherGroupHeaderId)
        {
            PolicyOnlineOtherGroupItemDataTableItemVM PolicyOnlineOtherGroupItemDataTableItemVM = new PolicyOnlineOtherGroupItemDataTableItemVM();

            //Check PolicyOnlineOtherGroupItemDataTableRow Exists
            PolicyOnlineOtherGroupItemDataTableRow PolicyOnlineOtherGroupItemDataTableRow = new PolicyOnlineOtherGroupItemDataTableRow();

            PolicyOnlineOtherGroupItemDataTableRow = PolicyOnlineOtherGroupItemDataTableRowRepository.GetPolicyOnlineOtherGroupItemDataTableRow(id);
            if (PolicyOnlineOtherGroupItemDataTableRow == 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"));
            }

            PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader = policyOtherGroupHeader;
            policyGroupRepository.EditGroupForDisplay(policyGroup);
            PolicyOnlineOtherGroupItemDataTableItemVM.PolicyGroup = policyGroup;

            PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableRow = PolicyOnlineOtherGroupItemDataTableRow;

            List <PolicyOnlineOtherGroupItemDataTableItem> PolicyOnlineOtherGroupItemDataTableItems = new List <PolicyOnlineOtherGroupItemDataTableItem>();

            PolicyOnlineOtherGroupItemDataTableItems = PolicyOnlineOtherGroupItemDataTableRowRepository.GetPolicyOnlineOtherGroupItemDataTableItems(id, policyOtherGroupHeaderId);
            if (PolicyOnlineOtherGroupItemDataTableItems != null)
            {
                PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableItems = PolicyOnlineOtherGroupItemDataTableItems;
            }

            return(View(PolicyOnlineOtherGroupItemDataTableItemVM));
        }
        //Loop through PolicyOnlineOtherGroupItemDataTableItems into XML
        public XmlDocument ConvertPolicyOnlineOtherGroupItemDataTableItemsToXML(PolicyOnlineOtherGroupItemDataTableItemVM PolicyOnlineOtherGroupItemDataTableItemVM)
        {
            XmlDocument    doc = new XmlDocument();
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

            doc.AppendChild(dec);
            XmlElement root = doc.CreateElement("PolicyOnlineOtherGroupItemDataTableItems");

            doc.AppendChild(root);

            if (PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableItems != null)
            {
                if (PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableItems.Count > 0)
                {
                    XmlElement xmlPolicyOnlineOtherGroupItemDataTableItems = doc.CreateElement("PolicyOnlineOtherGroupItemDataTableItems");
                    foreach (PolicyOnlineOtherGroupItemDataTableItem item in PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableItems)
                    {
                        if (item != null && !string.IsNullOrEmpty(item.TableDataItem))
                        {
                            XmlElement xmlPolicyOnlineOtherGroupItemDataTableItem = doc.CreateElement("PolicyOnlineOtherGroupItemDataTableItem");

                            XmlElement xmlPolicyOnlineOtherGroupItemDataTableItem_TableDataItem = doc.CreateElement("TableDataItem");
                            xmlPolicyOnlineOtherGroupItemDataTableItem_TableDataItem.InnerText = item.TableDataItem;
                            xmlPolicyOnlineOtherGroupItemDataTableItem.AppendChild(xmlPolicyOnlineOtherGroupItemDataTableItem_TableDataItem);

                            XmlElement xmlPolicyOnlineOtherGroupItemDataTableItem_PolicyOtherGroupHeaderColumnNameId = doc.CreateElement("PolicyOtherGroupHeaderColumnNameId");
                            xmlPolicyOnlineOtherGroupItemDataTableItem_PolicyOtherGroupHeaderColumnNameId.InnerText = item.PolicyOtherGroupHeaderColumnNameId.ToString();
                            xmlPolicyOnlineOtherGroupItemDataTableItem.AppendChild(xmlPolicyOnlineOtherGroupItemDataTableItem_PolicyOtherGroupHeaderColumnNameId);

                            xmlPolicyOnlineOtherGroupItemDataTableItems.AppendChild(xmlPolicyOnlineOtherGroupItemDataTableItem);
                        }
                    }
                    root.AppendChild(xmlPolicyOnlineOtherGroupItemDataTableItems);
                }
            }
            return(doc);
        }
        public ActionResult Edit(PolicyOnlineOtherGroupItemDataTableItemVM PolicyOnlineOtherGroupItemDataTableItemVM, FormCollection formCollection)
        {
            //Check Policy Exists
            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup = policyGroupRepository.GetGroup(PolicyOnlineOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId);
            if (policyGroup == null)
            {
                ViewData["ActionMethod"] = "CreatePost";
                return(View("RecordDoesNotExistError"));
            }

            //Check PolicyOtherGroupHeader Exists
            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId);
            if (policyOtherGroupHeader == null)
            {
                ViewData["ActionMethod"] = "CreatePost";
                return(View("RecordDoesNotExistError"));
            }

            //We need to extract group from groupVM
            List <PolicyOnlineOtherGroupItemDataTableItem> PolicyOnlineOtherGroupItemDataTableItems = new List <PolicyOnlineOtherGroupItemDataTableItem>();

            foreach (string item in formCollection)
            {
                if (item.StartsWith("PolicyOtherGroupHeaderColumnNameId"))
                {
                    PolicyOnlineOtherGroupItemDataTableItem PolicyOnlineOtherGroupItemDataTableItem = new PolicyOnlineOtherGroupItemDataTableItem()
                    {
                        PolicyOtherGroupHeaderColumnNameId = Int32.Parse(item.Replace("PolicyOtherGroupHeaderColumnNameId_", "")),
                        TableDataItem = formCollection[item]
                    };
                    PolicyOnlineOtherGroupItemDataTableItems.Add(PolicyOnlineOtherGroupItemDataTableItem);
                }
            }
            if (PolicyOnlineOtherGroupItemDataTableItems.Count() <= 0)
            {
                ViewData["Message"] = "ValidationError : missing item";;
                return(View("Error"));
            }

            PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOnlineOtherGroupItemDataTableItems = PolicyOnlineOtherGroupItemDataTableItems;

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <PolicyOnlineOtherGroupItemDataTableItemVM>(PolicyOnlineOtherGroupItemDataTableItemVM, "PolicyOnlineOtherGroupItemDataTableItemVM");
            }
            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
            {
                PolicyOnlineOtherGroupItemDataTableItemRepository.Edit(PolicyOnlineOtherGroupItemDataTableItemVM);
            }
            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 = PolicyOnlineOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, policyGroupId = PolicyOnlineOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId }));
        }