public ActionResult Edit(PolicyOnlineOtherGroupItemLanguageVM PolicyOnlineOtherGroupItemLanguageVM, FormCollection formCollection)
        {
            //Get Item
            PolicyOnlineOtherGroupItemLanguage PolicyOnlineOtherGroupItemLanguage = new PolicyOnlineOtherGroupItemLanguage();

            PolicyOnlineOtherGroupItemLanguage = PolicyOnlineOtherGroupItemLanguageRepository.GetPolicyOnlineOtherGroupItemLanguage(PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage.PolicyOnlineOtherGroupItemLanguageId);

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

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <PolicyOnlineOtherGroupItemLanguage>(PolicyOnlineOtherGroupItemLanguage, "PolicyOnlineOtherGroupItemLanguage");
            }
            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
            {
                PolicyOnlineOtherGroupItemLanguageRepository.Edit(PolicyOnlineOtherGroupItemLanguageVM);
            }
            catch (SqlException ex)
            {
                //Non-Unique Name
                if (ex.Message == "NonUniqueName")
                {
                    return(View("NonUniqueNameError"));
                }
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyOnlineOtherGroupItemLanguage.mvc/Edit/" + PolicyOnlineOtherGroupItemLanguage.PolicyOnlineOtherGroupItemLanguageId;
                    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 = PolicyOnlineOtherGroupItemLanguageVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, policyGroupId = PolicyOnlineOtherGroupItemLanguageVM.PolicyGroup.PolicyGroupId }));
        }
        ////Edit
        public void Edit(PolicyOnlineOtherGroupItemLanguageVM PolicyOnlineOtherGroupItemLanguageVM)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_UpdatePolicyOnlineOtherGroupItemLanguage_v1(
                PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage.PolicyOnlineOtherGroupItemLanguageId,
                PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage.Translation,
                PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage.LanguageCode,
                adminUserGuid,
                PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage.VersionNumber
                );
        }
        //Add
        public void Add(PolicyOnlineOtherGroupItemLanguageVM PolicyOnlineOtherGroupItemLanguageVM)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_InsertPolicyOnlineOtherGroupItemLanguage_v1(
                PolicyOnlineOtherGroupItemLanguageVM.PolicyGroup.PolicyGroupId,
                PolicyOnlineOtherGroupItemLanguageVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId,
                PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage.Translation,
                PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage.LanguageCode,
                adminUserGuid
                );
        }
        // GET: /PolicyOnlineOtherGroupItemLanguage/Create
        public ActionResult Create(int id, int policyGroupId)
        {
            PolicyOnlineOtherGroupItemLanguageVM PolicyOnlineOtherGroupItemLanguageVM = new PolicyOnlineOtherGroupItemLanguageVM();

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

            policyGroup = policyGroupRepository.GetGroup(policyGroupId);
            if (policyGroup == null)
            {
                ViewData["ActionMethod"] = "CreateGet";
                return(View("RecordDoesNotExistError"));
            }

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

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(id);
            if (policyOtherGroupHeader == null)
            {
                ViewData["ActionMethod"] = "CreateGet";
                return(View("RecordDoesNotExistError"));
            }

            //Set Access Rights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToPolicyGroup(policyGroupId) || !rolesRepository.HasWriteAccessToPolicyOnlineOtherGroupItemRepository())
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

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

            PolicyOnlineOtherGroupItemLanguage PolicyOnlineOtherGroupItemLanguage = new PolicyOnlineOtherGroupItemLanguage();

            PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage = PolicyOnlineOtherGroupItemLanguage;

            //Languages
            SelectList languages = new SelectList(PolicyOnlineOtherGroupItemLanguageRepository.GetAvailableLanguages(id, policyGroupId).ToList(), "LanguageCode", "LanguageName");

            PolicyOnlineOtherGroupItemLanguageVM.Languages = languages;

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

            //Get Item From Database
            PolicyOnlineOtherGroupItemLanguage PolicyOnlineOtherGroupItemLanguage = new PolicyOnlineOtherGroupItemLanguage();

            PolicyOnlineOtherGroupItemLanguage = PolicyOnlineOtherGroupItemLanguageRepository.GetPolicyOnlineOtherGroupItemLanguage(PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage.PolicyOnlineOtherGroupItemLanguageId);

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

            //Delete Form Item
            try
            {
                PolicyOnlineOtherGroupItemLanguageRepository.Delete(PolicyOnlineOtherGroupItemLanguage);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyOnlineOtherGroupItemLanguage.mvc/Delete/" + PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage.PolicyOnlineOtherGroupItemLanguageId;
                    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 = PolicyOnlineOtherGroupItemLanguageVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, policyGroupId = PolicyOnlineOtherGroupItemLanguageVM.PolicyGroup.PolicyGroupId }));
        }
        public ActionResult Delete(int id, int policyGroupId, int policyOtherGroupHeaderId)
        {
            PolicyOnlineOtherGroupItemLanguageVM PolicyOnlineOtherGroupItemLanguageVM = new PolicyOnlineOtherGroupItemLanguageVM();

            //Check Item Exists
            PolicyOnlineOtherGroupItemLanguage policyOnlineOtherGroupItemLanguage = new PolicyOnlineOtherGroupItemLanguage();

            policyOnlineOtherGroupItemLanguage = PolicyOnlineOtherGroupItemLanguageRepository.GetPolicyOnlineOtherGroupItemLanguage(id);
            if (policyOnlineOtherGroupItemLanguage == 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"] = "CreateGet";
                return(View("RecordDoesNotExistError"));
            }

            //Set Access Rights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToPolicyGroup(policyGroupId) || !rolesRepository.HasWriteAccessToPolicyOnlineOtherGroupItemRepository())
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //If user does not have OnlineUserFlag and the OnlineSensitiveDataFlag is set to true on the PolicyOtherGroupHeader, then mask the translation
            if (policyOtherGroupHeader.OnlineSensitiveDataFlag == true)
            {
                string adminUserGuid = System.Web.HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];
                SystemUserRepository systemUserRepository = new SystemUserRepository();
                SystemUser           systemUser           = systemUserRepository.GetUserBySystemUserGuid(adminUserGuid);
                if (systemUser != null && systemUser.OnlineUserFlag != true)
                {
                    policyOnlineOtherGroupItemLanguage.Translation = new string('*', 20);
                }
            }

            PolicyOnlineOtherGroupItemLanguageVM.PolicyOtherGroupHeader             = policyOtherGroupHeader;
            PolicyOnlineOtherGroupItemLanguageVM.PolicyOnlineOtherGroupItemLanguage = policyOnlineOtherGroupItemLanguage;
            policyGroupRepository.EditGroupForDisplay(policyGroup);
            PolicyOnlineOtherGroupItemLanguageVM.PolicyGroup = policyGroup;

            return(View(PolicyOnlineOtherGroupItemLanguageVM));
        }
        public ActionResult Create(PolicyOnlineOtherGroupItemLanguageVM PolicyOnlineOtherGroupItemLanguageVM, FormCollection formCollection)
        {
            //Check Policy Exists
            PolicyGroup policyGroup = new PolicyGroup();

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

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

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

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

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

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