//Add Data From Linked Tables for Display
        public void EditItemForDisplay(PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage)
        {
            //Add LanguageName
            if (policyAirCabinGroupItemLanguage.LanguageCode != null)
            {
                LanguageRepository languageRepository = new LanguageRepository();
                Language           language           = new Language();
                language = languageRepository.GetLanguage(policyAirCabinGroupItemLanguage.LanguageCode);
                if (language != null)
                {
                    policyAirCabinGroupItemLanguage.LanguageName = language.LanguageName;
                }
            }

            //Add PolicyGroup Information
            PolicyAirCabinGroupItemRepository policyAirCabinGroupItemRepository = new PolicyAirCabinGroupItemRepository();
            PolicyAirCabinGroupItem           policyAirCabinGroupItem           = new PolicyAirCabinGroupItem();

            policyAirCabinGroupItem = policyAirCabinGroupItemRepository.GetPolicyAirCabinGroupItem(policyAirCabinGroupItemLanguage.PolicyAirCabinGroupItemId);


            if (policyAirCabinGroupItem != null)
            {
                policyAirCabinGroupItemRepository.EditItemForDisplay(policyAirCabinGroupItem);
                policyAirCabinGroupItemLanguage.PolicyGroupName = policyAirCabinGroupItem.PolicyGroupName;
                policyAirCabinGroupItemLanguage.PolicyGroupId   = policyAirCabinGroupItem.PolicyGroupId;
            }
        }
        public ActionResult Create(PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage)
        {
            PolicyAirCabinGroupItem policyAirCabinGroupItem = new PolicyAirCabinGroupItem();

            policyAirCabinGroupItem = policyAirCabinGroupItemRepository.GetPolicyAirCabinGroupItem(policyAirCabinGroupItemLanguage.PolicyAirCabinGroupItemId);

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

            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToPolicyGroup(policyAirCabinGroupItem.PolicyGroupId))
            {
                //AccessRights Error
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Update  Model from Form
            try
            {
                UpdateModel(policyAirCabinGroupItemLanguage);
            }
            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"));
            }



            try
            {
                policyAirCabinGroupItemLanguageRepository.Add(policyAirCabinGroupItemLanguage);
            }
            catch (SqlException ex)
            {
                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 = policyAirCabinGroupItem.PolicyAirCabinGroupItemId }));
        }
        //Add to DB
        public void Add(PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_InsertPolicyAirCabinGroupItemAirCabinAdvice_v1(
                policyAirCabinGroupItemLanguage.PolicyAirCabinGroupItemId,
                policyAirCabinGroupItemLanguage.LanguageCode,
                policyAirCabinGroupItemLanguage.AirCabinAdvice,
                adminUserGuid
                );
        }
        //Delete From DB
        public void Delete(PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_DeletePolicyAirCabinGroupItemAirCabinAdvice_v1(
                policyAirCabinGroupItemLanguage.PolicyAirCabinGroupItemId,
                policyAirCabinGroupItemLanguage.LanguageCode,
                adminUserGuid,
                policyAirCabinGroupItemLanguage.VersionNumber
                );
        }
        //GET: View
        public ActionResult View(int id, string languageCode)
        {
            PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage = new PolicyAirCabinGroupItemLanguage();

            policyAirCabinGroupItemLanguage = policyAirCabinGroupItemLanguageRepository.GetItem(id, languageCode);
            if (policyAirCabinGroupItemLanguage == null)
            {
                ViewData["ActionMethod"] = "ViewGet";
                return(View("RecordDoesNotExistError"));
            }
            policyAirCabinGroupItemLanguageRepository.EditItemForDisplay(policyAirCabinGroupItemLanguage);
            return(View(policyAirCabinGroupItemLanguage));
        }
        public ActionResult Delete(int id, string languageCode, FormCollection collection)
        {
            //Get Item
            PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage = new PolicyAirCabinGroupItemLanguage();

            policyAirCabinGroupItemLanguage = policyAirCabinGroupItemLanguageRepository.GetItem(id, languageCode);

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

            //Check AccessRights
            PolicyAirCabinGroupItem policyAirCabinGroupItem = new PolicyAirCabinGroupItem();

            policyAirCabinGroupItem = policyAirCabinGroupItemRepository.GetPolicyAirCabinGroupItem(id);
            RolesRepository rolesRepository = new RolesRepository();

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

            //Delete Item
            try
            {
                policyAirCabinGroupItemLanguage.VersionNumber = Int32.Parse(collection["VersionNumber"]);
                policyAirCabinGroupItemLanguageRepository.Delete(policyAirCabinGroupItemLanguage);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/AirlineAdvice.mvc/Delete/" + policyAirCabinGroupItemLanguage.PolicyAirCabinGroupItemId.ToString() + "/" + policyAirCabinGroupItemLanguage.LanguageCode;
                    return(View("VersionError"));
                }
                //Generic Error
                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }


            //Return
            return(RedirectToAction("List", new { id = policyAirCabinGroupItemLanguage.PolicyAirCabinGroupItemId }));
        }
        // GET: /Create
        public ActionResult Create(int id)
        {
            //Get PolicyAirCabinGroupItem
            PolicyAirCabinGroupItem policyAirCabinGroupItem = new PolicyAirCabinGroupItem();

            policyAirCabinGroupItem = policyAirCabinGroupItemRepository.GetPolicyAirCabinGroupItem(id);

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

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

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

            //New PolicyAirCabinGroupItemLanguage
            PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage = new PolicyAirCabinGroupItemLanguage();

            policyAirCabinGroupItemLanguage.PolicyAirCabinGroupItemId = id;
            policyAirCabinGroupItemLanguageRepository.EditItemForDisplay(policyAirCabinGroupItemLanguage);

            //Language SelectList
            SelectList languageList = new SelectList(policyAirCabinGroupItemLanguageRepository.GetUnUsedLanguages(id).ToList(), "LanguageCode", "LanguageName");

            ViewData["Languages"] = languageList;

            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup = policyGroupRepository.GetGroup(policyAirCabinGroupItemLanguage.PolicyGroupId);

            ViewData["PolicyGroupName"]           = policyGroup.PolicyGroupName;
            ViewData["PolicyGroupId"]             = policyGroup.PolicyGroupId;
            ViewData["PolicyAirCabinGroupItemId"] = id;


            //Show Create Form
            return(View(policyAirCabinGroupItemLanguage));
        }
        // GET: /Edit
        public ActionResult Edit(int id, string languageCode)
        {
            //Get Item
            PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage = new PolicyAirCabinGroupItemLanguage();

            policyAirCabinGroupItemLanguage = policyAirCabinGroupItemLanguageRepository.GetItem(id, languageCode);

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

            //Check AccessRights
            PolicyAirCabinGroupItem policyAirCabinGroupItem = new PolicyAirCabinGroupItem();

            policyAirCabinGroupItem = policyAirCabinGroupItemRepository.GetPolicyAirCabinGroupItem(id);
            RolesRepository rolesRepository = new RolesRepository();

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

            //Language SelectList
            SelectList languageList = new SelectList(policyAirCabinGroupItemLanguageRepository.GetUnUsedLanguages(id).ToList(), "LanguageCode", "LanguageName");

            ViewData["Languages"] = languageList;

            //Parent Information
            ViewData["PolicyGroupID"]   = policyAirCabinGroupItem.PolicyGroupId;
            ViewData["PolicyGroupName"] = policyGroupRepository.GetGroup(policyAirCabinGroupItem.PolicyGroupId).PolicyGroupName;

            policyAirCabinGroupItemLanguageRepository.EditItemForDisplay(policyAirCabinGroupItemLanguage);
            return(View(policyAirCabinGroupItemLanguage));
        }
        public ActionResult Delete(int id, string languageCode)
        {
            //Get Item
            PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage = new PolicyAirCabinGroupItemLanguage();

            policyAirCabinGroupItemLanguage = policyAirCabinGroupItemLanguageRepository.GetItem(id, languageCode);

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

            //Check AccessRights
            PolicyAirCabinGroupItem policyAirCabinGroupItem = new PolicyAirCabinGroupItem();

            policyAirCabinGroupItem = policyAirCabinGroupItemRepository.GetPolicyAirCabinGroupItem(id);
            RolesRepository rolesRepository = new RolesRepository();

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

            //Parent Information
            ViewData["PolicyGroupID"]   = policyAirCabinGroupItem.PolicyGroupId;
            ViewData["PolicyGroupName"] = policyGroupRepository.GetGroup(policyAirCabinGroupItem.PolicyGroupId).PolicyGroupName;

            //Add Linked Information
            policyAirCabinGroupItemLanguageRepository.EditItemForDisplay(policyAirCabinGroupItemLanguage);

            //Return View
            return(View(policyAirCabinGroupItemLanguage));
        }
        public ActionResult Edit(int id, string languageCode, FormCollection formCollection)
        {
            //Get Item
            PolicyAirCabinGroupItemLanguage policyAirCabinGroupItemLanguage = new PolicyAirCabinGroupItemLanguage();

            policyAirCabinGroupItemLanguage = policyAirCabinGroupItemLanguageRepository.GetItem(id, languageCode);

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

            //Check AccessRights
            PolicyAirCabinGroupItem policyAirCabinGroupItem = new PolicyAirCabinGroupItem();

            policyAirCabinGroupItem = policyAirCabinGroupItemRepository.GetPolicyAirCabinGroupItem(id);
            RolesRepository rolesRepository = new RolesRepository();

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

            //Update Item from Form
            try
            {
                UpdateModel(policyAirCabinGroupItemLanguage);
            }
            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"));
            }


            //Update AirlineAdvice
            try
            {
                policyAirCabinGroupItemLanguageRepository.Update(policyAirCabinGroupItemLanguage);
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/AirlineAdvice.mvc/Edit/" + policyAirCabinGroupItemLanguage.PolicyAirCabinGroupItemId.ToString();
                    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 = policyAirCabinGroupItemLanguage.PolicyAirCabinGroupItemId }));
        }