// GET: /View
        public ActionResult View(int id)
        {
            //Check Exists
            FareRestriction fareRestriction = new FareRestriction();

            fareRestriction = fareRestrictionRepository.GetFareRestriction(id);
            if (fareRestriction == null)
            {
                ViewData["ActionMethod"] = "ViewGet";
                return(View("RecordDoesNotExistError"));
            }

            fareRestrictionRepository.EditForDisplay(fareRestriction);

            //add the PolicyRouting information
            PolicyRouting policyRouting = new PolicyRouting();

            if (fareRestriction.RoutingId != null)
            {
                policyRouting = policyRoutingRepository.GetPolicyRouting((int)fareRestriction.RoutingId);
                policyRoutingRepository.EditForDisplay(policyRouting);
            }
            FareRestrictionViewModel fareRestrictionViewModel = new FareRestrictionViewModel(fareRestriction, policyRouting);

            //Show View
            return(View(fareRestrictionViewModel));
        }
        // GET: /CreatePolicyRouting
        public ActionResult CreatePolicyRouting(int id)
        {
            //Get PolicyAirVendorGroupItem
            FareRestriction fareRestriction = new FareRestriction();

            fareRestriction = fareRestrictionRepository.GetFareRestriction(id);

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

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

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

            //populate new PolicyAirVendorGroupItem with known PolicyGroup Information
            fareRestrictionRepository.EditForDisplay(fareRestriction);

            PolicyRouting            policyRouting            = new PolicyRouting();
            FareRestrictionViewModel fareRestrictionViewModel = new FareRestrictionViewModel(fareRestriction, policyRouting);

            //Show 'Create' Form
            return(View(fareRestrictionViewModel));
        }
        public ActionResult Edit(FareRestrictionViewModel fareRestrictionViewModel)
        {
            //Get PolicyRouting Info
            PolicyRouting policyRouting = new PolicyRouting();

            policyRouting = fareRestrictionViewModel.PolicyRouting;
            policyRoutingRepository.EditPolicyRouting(policyRouting);

            FareRestriction fareRestriction = new FareRestriction();

            fareRestriction = fareRestrictionRepository.GetFareRestriction(fareRestrictionViewModel.FareRestriction.FareRestrictionId);

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

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

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



            try{
                fareRestrictionRepository.Update(fareRestriction, policyRouting);
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/FareRestriction.mvc/Edit/" + fareRestriction.FareRestrictionId.ToString();
                    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"));
            }

            //Success
            return(RedirectToAction("List"));
        }
        public ActionResult Create(FareRestrictionViewModel fareRestrictionViewModel, string btnSubmit)
        {
            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

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

            //Get PolicyRouting Info
            PolicyRouting policyRouting = new PolicyRouting();

            policyRouting = fareRestrictionViewModel.PolicyRouting;

            //Get PolicyAirVendorGroupItem Info
            FareRestriction fareRestriction = new FareRestriction();

            fareRestriction = fareRestrictionViewModel.FareRestriction;

            //Edit Routing
            policyRoutingRepository.EditPolicyRouting(policyRouting);

            try
            {
                fareRestrictionRepository.Add(fareRestriction, policyRouting);
            }
            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"));
            }


            //Send to new form based on submit button pressed
            switch (btnSubmit)
            {
            case "Save":
                return(RedirectToAction("List"));

            default:
                return(RedirectToAction("CreatePolicyRouting", new { id = fareRestriction.FareRestrictionId }));
            }
        }
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            //Check Exists
            FareRestriction fareRestriction = new FareRestriction();

            fareRestriction = fareRestrictionRepository.GetFareRestriction(id);
            if (fareRestriction == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

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

            //Populate List of Languages
            LanguageRepository languageRepository = new LanguageRepository();
            SelectList         languages          = new SelectList(languageRepository.GetAllLanguages().ToList(), "LanguageCode", "LanguageName");

            ViewData["LanguageList"] = languages;

            //Populate List of Products
            ProductRepository productRepository = new ProductRepository();
            SelectList        products          = new SelectList(productRepository.GetAllProducts().ToList(), "ProductId", "ProductName");

            ViewData["ProductList"] = products;

            fareRestrictionRepository.EditForDisplay(fareRestriction);

            //add the PolicyRouting information
            PolicyRouting policyRouting = new PolicyRouting();

            if (fareRestriction.RoutingId != null)
            {
                policyRouting = policyRoutingRepository.GetPolicyRouting((int)fareRestriction.RoutingId);
                policyRoutingRepository.EditPolicyRouting(policyRouting);
            }
            FareRestrictionViewModel fareRestrictionViewModel = new FareRestrictionViewModel(fareRestriction, policyRouting);

            return(View(fareRestrictionViewModel));
        }
        // GET: /Create
        public ActionResult Create()
        {
            FareRestriction fareRestriction = new FareRestriction();

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

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

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

            //Populate List of Languages
            LanguageRepository languageRepository = new LanguageRepository();
            SelectList         languages          = new SelectList(languageRepository.GetAllLanguages().ToList(), "LanguageCode", "LanguageName");

            ViewData["LanguageList"] = languages;

            //Populate List of Products
            ProductRepository productRepository = new ProductRepository();
            SelectList        products          = new SelectList(productRepository.GetAllProducts().ToList(), "ProductId", "ProductName");

            ViewData["ProductList"] = products;

            PolicyRouting policyRouting = new PolicyRouting();

            policyRouting.FromGlobalFlag = false;
            policyRouting.ToGlobalFlag   = false;

            FareRestrictionViewModel fareRestrictionViewModel = new FareRestrictionViewModel(fareRestriction, policyRouting);

            //Show 'Create' Form
            return(View(fareRestrictionViewModel));
        }
        public ActionResult Delete(int id)
        {
            //Check Exists
            FareRestriction fareRestriction = new FareRestriction();

            fareRestriction = fareRestrictionRepository.GetFareRestriction(id);
            if (fareRestriction == null)
            {
                ViewData["ActionMethod"] = "DeleteGet";
                return(View("RecordDoesNotExistError"));
            }

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

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

            //EditForDisplay
            fareRestrictionRepository.EditForDisplay(fareRestriction);

            //add the PolicyRouting information
            PolicyRouting policyRouting = new PolicyRouting();

            if (fareRestriction.RoutingId != null)
            {
                policyRouting = policyRoutingRepository.GetPolicyRouting((int)fareRestriction.RoutingId);
                policyRoutingRepository.EditForDisplay(policyRouting);
            }
            FareRestrictionViewModel fareRestrictionViewModel = new FareRestrictionViewModel(fareRestriction, policyRouting);

            //Show 'Create' Form
            return(View(fareRestrictionViewModel));
        }