//Add PolicyOtherGroupHeaderColumnName
        public void Add(PolicyOtherGroupHeaderColumnNameVM policyOtherGroupHeaderColumnNameVM)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_InsertPolicyOtherGroupHeaderColumnName_v1(
                policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderTableName.PolicyOtherGroupHeaderTableNameId,
                policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderColumnName.ColumnName,
                adminUserGuid
                );
        }
        public ActionResult Delete(int id)
        {
            //Get Item From Database
            PolicyOtherGroupHeaderColumnName policyOtherGroupHeaderColumnName = new PolicyOtherGroupHeaderColumnName();

            policyOtherGroupHeaderColumnName = policyOtherGroupHeaderColumnNameRepository.GetPolicyOtherGroupHeaderColumnName(id);

            //Check Exists
            if (policyOtherGroupHeaderColumnName == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Get Table Name
            PolicyOtherGroupHeaderTableName policyOtherGroupHeaderTableName = new PolicyOtherGroupHeaderTableName();

            policyOtherGroupHeaderTableName = policyOtherGroupHeaderTableNameRepository.GetPolicyOtherGroupHeaderTableNameByPolicyOtherGroupHeaderTableNameId(policyOtherGroupHeaderColumnName.PolicyOtherGroupHeaderTableNameId);

            //Check Exists
            if (policyOtherGroupHeaderTableName == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //Get Item From Database
            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyOtherGroupHeaderTableName.PolicyOtherGroupHeaderId);

            //Check Exists
            if (policyOtherGroupHeader == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            PolicyOtherGroupHeaderColumnNameVM policyOtherGroupHeaderColumnNameVM = new PolicyOtherGroupHeaderColumnNameVM();

            policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderColumnName = policyOtherGroupHeaderColumnName;
            policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderTableName  = policyOtherGroupHeaderTableName;
            policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeader           = policyOtherGroupHeader;

            return(View(policyOtherGroupHeaderColumnNameVM));
        }
        public ActionResult Delete(PolicyOtherGroupHeaderColumnNameVM policyOtherGroupHeaderColumnNameVM)
        {
            //Check Valid Item passed in Form
            if (policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderColumnName == null)
            {
                ViewData["ActionMethod"] = "DeletePost";
                return(View("RecordDoesNotExistError"));
            }

            //Get Item From Database
            PolicyOtherGroupHeaderColumnName policyOtherGroupHeaderColumnName = new PolicyOtherGroupHeaderColumnName();

            policyOtherGroupHeaderColumnName = policyOtherGroupHeaderColumnNameRepository.GetPolicyOtherGroupHeaderColumnName(policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderColumnName.PolicyOtherGroupHeaderColumnNameId);

            //Check Exists
            if (policyOtherGroupHeaderColumnName == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Delete Form Item
            try
            {
                policyOtherGroupHeaderColumnNameRepository.Delete(policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderColumnName);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyOtherGroupHeaderColumnName.mvc/Delete/" + policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderColumnName.PolicyOtherGroupHeaderColumnNameId;
                    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 = policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId }));
        }
        public ActionResult Edit(PolicyOtherGroupHeaderColumnNameVM policyOtherGroupHeaderColumnNameVM, FormCollection formCollection)
        {
            //Get Item
            PolicyOtherGroupHeaderColumnName policyOtherGroupHeaderColumnName = new PolicyOtherGroupHeaderColumnName();

            policyOtherGroupHeaderColumnName = policyOtherGroupHeaderColumnNameRepository.GetPolicyOtherGroupHeaderColumnName(policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderColumnName.PolicyOtherGroupHeaderColumnNameId);

            //Check Exists
            if (policyOtherGroupHeaderColumnName == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <PolicyOtherGroupHeaderColumnName>(policyOtherGroupHeaderColumnName, "PolicyOtherGroupHeaderColumnName");
            }
            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
            {
                policyOtherGroupHeaderColumnNameRepository.Edit(policyOtherGroupHeaderColumnName);
            }
            catch (SqlException ex)
            {
                //Non-Unique Name
                if (ex.Message == "NonUniqueName")
                {
                    return(View("NonUniqueNameError"));
                }
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyOtherGroupHeaderColumnName.mvc/Edit/" + policyOtherGroupHeaderColumnName.PolicyOtherGroupHeaderColumnNameId;
                    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 = policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId }));
        }
        public ActionResult Create(PolicyOtherGroupHeaderColumnNameVM policyOtherGroupHeaderColumnNameVM, FormCollection formCollection)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //We need to extract group from groupVM
            PolicyOtherGroupHeaderColumnName policyOtherGroupHeaderColumnName = new PolicyOtherGroupHeaderColumnName();

            policyOtherGroupHeaderColumnName = policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeaderColumnName;
            if (policyOtherGroupHeaderColumnName == null)
            {
                ViewData["Message"] = "ValidationError : missing item";;
                return(View("Error"));
            }

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <PolicyOtherGroupHeaderColumnName>(policyOtherGroupHeaderColumnName, "PolicyOtherGroupHeaderColumnName");
            }
            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
            {
                policyOtherGroupHeaderColumnNameRepository.Add(policyOtherGroupHeaderColumnNameVM);
            }
            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 = policyOtherGroupHeaderColumnNameVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId }));
        }