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

            //Get Item From Database
            PolicyOtherGroupHeaderLabelLanguage policyOtherGroupHeaderLabelLanguage = new PolicyOtherGroupHeaderLabelLanguage();

            policyOtherGroupHeaderLabelLanguage = policyOtherGroupHeaderLabelLanguageRepository.GetPolicyOtherGroupHeaderLabelLanguage(id);

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

            PolicyOtherGroupHeaderLabelLanguageVM policyOtherGroupHeaderLabelLanguageVM = new PolicyOtherGroupHeaderLabelLanguageVM();

            policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabelLanguage = policyOtherGroupHeaderLabelLanguage;

            PolicyOtherGroupHeaderLabel policyOtherGroupHeaderLabel = new PolicyOtherGroupHeaderLabel();

            policyOtherGroupHeaderLabel = policyOtherGroupHeaderLabelRepository.GetPolicyOtherGroupHeaderLabelByPolicyOtherGroupHeaderLabelId(
                policyOtherGroupHeaderLabelLanguage.PolicyOtherGroupHeaderLabelId
                );
            if (policyOtherGroupHeaderLabel != null)
            {
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabel = policyOtherGroupHeaderLabel;
            }

            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyOtherGroupHeaderLabel.PolicyOtherGroupHeaderId);
            if (policyOtherGroupHeader != null)
            {
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeader = policyOtherGroupHeader;
            }

            //Languages
            List <Language>    availableLanguages = policyOtherGroupHeaderLabelLanguageRepository.GetAvailableLanguages(policyOtherGroupHeaderLabel.PolicyOtherGroupHeaderId).ToList();
            Language           selectedLanguage   = new Language();
            LanguageRepository languageRepository = new LanguageRepository();

            selectedLanguage = languageRepository.GetLanguage(policyOtherGroupHeaderLabelLanguage.LanguageCode);
            if (selectedLanguage != null)
            {
                availableLanguages.Add(selectedLanguage);
            }

            SelectList languages = new SelectList(availableLanguages.OrderBy(x => x.LanguageCode), "LanguageCode", "LanguageName", policyOtherGroupHeaderLabelLanguage.LanguageCode);

            policyOtherGroupHeaderLabelLanguageVM.Languages = languages;

            return(View(policyOtherGroupHeaderLabelLanguageVM));
        }
        //Add PolicyOtherGroupHeaderLabelLanguage
        public void Add(PolicyOtherGroupHeaderLabelLanguageVM policyOtherGroupHeaderLabelLanguageVM)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_InsertPolicyOtherGroupHeaderLabelLanguage_v1(
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId,
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabelLanguage.LabelTranslation,
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabelLanguage.LanguageCode,
                adminUserGuid
                );
        }
        public ActionResult Delete(int id)
        {
            //Get Item From Database
            PolicyOtherGroupHeaderLabelLanguage policyOtherGroupHeaderLabelLanguage = new PolicyOtherGroupHeaderLabelLanguage();

            policyOtherGroupHeaderLabelLanguage = policyOtherGroupHeaderLabelLanguageRepository.GetPolicyOtherGroupHeaderLabelLanguage(id);

            //Check Exists
            if (policyOtherGroupHeaderLabelLanguage == 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"));
            }

            PolicyOtherGroupHeaderLabelLanguageVM policyOtherGroupHeaderLabelLanguageVM = new PolicyOtherGroupHeaderLabelLanguageVM();

            policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabelLanguage = policyOtherGroupHeaderLabelLanguage;

            PolicyOtherGroupHeaderLabel policyOtherGroupHeaderLabel = new PolicyOtherGroupHeaderLabel();

            policyOtherGroupHeaderLabel = policyOtherGroupHeaderLabelRepository.GetPolicyOtherGroupHeaderLabelByPolicyOtherGroupHeaderLabelId(
                policyOtherGroupHeaderLabelLanguage.PolicyOtherGroupHeaderLabelId
                );
            if (policyOtherGroupHeaderLabel != null)
            {
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabel = policyOtherGroupHeaderLabel;
            }

            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyOtherGroupHeaderLabel.PolicyOtherGroupHeaderId);
            if (policyOtherGroupHeader != null)
            {
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeader = policyOtherGroupHeader;
            }

            return(View(policyOtherGroupHeaderLabelLanguageVM));
        }
        //
        // GET: /PolicyOtherGroupHeaderLabelLanguage/Create
        public ActionResult Create(int id)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

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

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(id);

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

            PolicyOtherGroupHeaderLabelLanguageVM policyOtherGroupHeaderLabelLanguageVM = new PolicyOtherGroupHeaderLabelLanguageVM();

            policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeader = policyOtherGroupHeader;

            PolicyOtherGroupHeaderLabelLanguage policyOtherGroupHeaderLabelLanguage = new PolicyOtherGroupHeaderLabelLanguage();

            policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabelLanguage = policyOtherGroupHeaderLabelLanguage;

            PolicyOtherGroupHeaderLabel policyOtherGroupHeaderLabel = new PolicyOtherGroupHeaderLabel();

            policyOtherGroupHeaderLabel = policyOtherGroupHeaderLabelRepository.GetPolicyOtherGroupHeaderLabel(policyOtherGroupHeader.PolicyOtherGroupHeaderId);
            if (policyOtherGroupHeaderLabel != null)
            {
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabel = policyOtherGroupHeaderLabel;
            }

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

            policyOtherGroupHeaderLabelLanguageVM.Languages = languages;

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

            //Get Item From Database
            PolicyOtherGroupHeaderLabelLanguage policyOtherGroupHeaderLabelLanguage = new PolicyOtherGroupHeaderLabelLanguage();

            policyOtherGroupHeaderLabelLanguage = policyOtherGroupHeaderLabelLanguageRepository.GetPolicyOtherGroupHeaderLabelLanguage(
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabelLanguage.PolicyOtherGroupHeaderLabelLanguageId
                );

            //Check Exists
            if (policyOtherGroupHeaderLabelLanguage == 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"));
            }

            PolicyOtherGroupHeaderLabel policyOtherGroupHeaderLabel = new PolicyOtherGroupHeaderLabel();

            policyOtherGroupHeaderLabel = policyOtherGroupHeaderLabelRepository.GetPolicyOtherGroupHeaderLabelByPolicyOtherGroupHeaderLabelId(
                policyOtherGroupHeaderLabelLanguage.PolicyOtherGroupHeaderLabelId
                );
            if (policyOtherGroupHeaderLabel != null)
            {
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabel = policyOtherGroupHeaderLabel;
            }

            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyOtherGroupHeaderLabel.PolicyOtherGroupHeaderId);
            if (policyOtherGroupHeader != null)
            {
                policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeader = policyOtherGroupHeader;
            }


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

            policyOtherGroupHeaderLabelLanguage = policyOtherGroupHeaderLabelLanguageRepository.GetPolicyOtherGroupHeaderLabelLanguage(policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeaderLabelLanguage.PolicyOtherGroupHeaderLabelLanguageId);

            //Check Exists
            if (policyOtherGroupHeaderLabelLanguage == 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 <PolicyOtherGroupHeaderLabelLanguage>(policyOtherGroupHeaderLabelLanguage, "PolicyOtherGroupHeaderLabelLanguage");
            }
            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
            {
                policyOtherGroupHeaderLabelLanguageRepository.Edit(policyOtherGroupHeaderLabelLanguage);
            }
            catch (SqlException ex)
            {
                //Non-Unique Name
                if (ex.Message == "NonUniqueName")
                {
                    return(View("NonUniqueNameError"));
                }
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyOtherGroupHeaderLabelLanguage.mvc/Edit/" + policyOtherGroupHeaderLabelLanguage.PolicyOtherGroupHeaderLabelLanguageId;
                    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 = policyOtherGroupHeaderLabelLanguageVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId }));
        }