// GET: /UnDelete
        public ActionResult UnDelete(int id)
        {
            //Get Item
            PriceTrackingSetupGroup group = new PriceTrackingSetupGroup();

            group = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

            //Check Exists
            if (group == null || group.DeletedFlag == false)
            {
                ViewData["ActionMethod"] = "UnDeleteGet";
                return(View("RecordDoesNotExistError"));
            }

            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToPriceTrackingSetupGroup(id))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }
            priceTrackingSetupGroupRepository.EditForDisplay(group);
            return(View(group));
        }
        // GET: Linked ClientSubUnits
        public ActionResult LinkedClientSubUnits(int id)
        {
            //Get Group From Database
            PriceTrackingSetupGroup group = new PriceTrackingSetupGroup();

            group = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

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

            PriceTrackingSetupGroupClientSubUnitCountriesVM priceTrackingSetupGroupClientSubUnits = new PriceTrackingSetupGroupClientSubUnitCountriesVM();

            priceTrackingSetupGroupClientSubUnits.PriceTrackingSetupGroupId   = id;
            priceTrackingSetupGroupClientSubUnits.PriceTrackingSetupGroupName = group.PriceTrackingSetupGroupName;

            List <ClientSubUnitCountryVM> clientSubUnitsAvailable = new List <ClientSubUnitCountryVM>();

            clientSubUnitsAvailable = priceTrackingSetupGroupRepository.GetLinkedClientSubUnits(id, false);
            priceTrackingSetupGroupClientSubUnits.ClientSubUnitsAvailable = clientSubUnitsAvailable;

            List <ClientSubUnitCountryVM> clientSubUnitsUnAvailable = new List <ClientSubUnitCountryVM>();

            clientSubUnitsUnAvailable = priceTrackingSetupGroupRepository.GetLinkedClientSubUnits(id, true);
            priceTrackingSetupGroupClientSubUnits.ClientSubUnitsUnAvailable = clientSubUnitsUnAvailable;


            return(View(priceTrackingSetupGroupClientSubUnits));
        }
        public ActionResult Create(int id)
        {
            //Check Parent Exists
            PriceTrackingSetupGroup priceTrackingSetupGroup = new PriceTrackingSetupGroup();

            priceTrackingSetupGroup = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

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

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

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

            PriceTrackingContactVM PriceTrackingContactVM = new PriceTrackingContactVM();

            //Create Item
            PriceTrackingContact priceTrackingContact = new PriceTrackingContact();

            priceTrackingContact.PriceTrackingSetupGroupId = id;
            priceTrackingContact.PriceTrackingSetupGroup   = priceTrackingSetupGroup;

            //ContactTypes
            PriceTrackingContactVM.ContactTypes = new SelectList(contactTypeRepository.GetAllContactTypes().ToList(), "ContactTypeId", "ContactTypeName");

            //PriceTrackingContactUserTypes
            PriceTrackingContactVM.PriceTrackingContactUserTypes = new SelectList(priceTrackingContactUserTypeRepository.GetAllPriceTrackingContactUserTypes().ToList(), "PriceTrackingContactUserTypeId", "PriceTrackingContactUserTypeName");

            //PriceTrackingDashboardAccessTypes
            PriceTrackingContactVM.PriceTrackingDashboardAccessTypes = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text");

            //PriceTrackingEmailAlertTypes
            PriceTrackingContactVM.PriceTrackingEmailAlertTypes = new SelectList(priceTrackingEmailAlertTypeRepository.GetAllPriceTrackingEmailAlertTypes().ToList(), "PriceTrackingEmailAlertTypeId", "PriceTrackingEmailAlertTypeName");

            PriceTrackingContactVM.PriceTrackingContact = priceTrackingContact;

            return(View(PriceTrackingContactVM));
        }
        public ActionResult UnDelete(int id, FormCollection collection)
        {
            //Get Item From Database
            PriceTrackingSetupGroup group = new PriceTrackingSetupGroup();

            group = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

            //Check Exists
            if (group == null || group.DeletedFlag == false)
            {
                ViewData["ActionMethod"] = "UnDeletePost";
                return(View("RecordDoesNotExistError"));
            }
            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

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

            //Delete Item
            try
            {
                group.VersionNumber = Int32.Parse(collection["VersionNumber"]);
                group.DeletedFlag   = false;
                priceTrackingSetupGroupRepository.UpdateGroupDeletedStatus(group);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PriceTrackingSetupGroup.mvc/UnDelete/" + id.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("ListDeleted"));
        }
        // GET: /View
        public ActionResult View(int id)
        {
            PriceTrackingSetupGroup group = new PriceTrackingSetupGroup();

            group = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

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

            priceTrackingSetupGroupRepository.EditForDisplay(group);

            return(View(group));
        }
        public ActionResult LinkedClientSubUnits(int PriceTrackingSetupGroupId, string ClientSubUnitGuid)
        {
            //Get Item From Database
            PriceTrackingSetupGroup group = new PriceTrackingSetupGroup();

            group = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(PriceTrackingSetupGroupId);

            //Check Exists
            if (group == null)
            {
                ViewData["ActionMethod"] = "ClientSubUnitPost";
                return(View("RecordDoesNotExistError"));
            }
            //Check Access Rights
            RolesRepository rolesRepository = new RolesRepository();

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

            //Database Update
            try
            {
                priceTrackingSetupGroupRepository.UpdateLinkedClientSubUnit(PriceTrackingSetupGroupId, ClientSubUnitGuid);
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PriceTrackingSetupGroup.mvc/ClientSubUnit/" + PriceTrackingSetupGroupId.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("LinkedClientSubUnits", new { id = PriceTrackingSetupGroupId }));
        }
        // GET: /List
        public ActionResult List(int id, string filter, int?page, string sortField, int?sortOrder)
        {
            //Set Access Rights
            ViewData["Access"] = "";
            RolesRepository rolesRepository = new RolesRepository();

            if (hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Access"] = "WriteAccess";
            }

            //SortField
            if (string.IsNullOrEmpty(sortField))
            {
                sortField = "ContactTypeName";
            }
            ViewData["CurrentSortField"] = sortField;

            //SortOrder
            if (sortOrder == 1)
            {
                ViewData["NewSortOrder"]     = 0;
                ViewData["CurrentSortOrder"] = 1;
            }
            else
            {
                ViewData["NewSortOrder"]     = 1;
                ViewData["CurrentSortOrder"] = 0;
            }

            //PriceTrackingSetupGroup
            PriceTrackingSetupGroup priceTrackingSetupGroup = new PriceTrackingSetupGroup();

            priceTrackingSetupGroup = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);
            if (priceTrackingSetupGroup != null)
            {
                ViewData["PriceTrackingSetupGroupId"]   = priceTrackingSetupGroup.PriceTrackingSetupGroupId;
                ViewData["PriceTrackingSetupGroupName"] = priceTrackingSetupGroup.PriceTrackingSetupGroupName;
            }

            //return items
            var cwtPaginatedList = priceTrackingContactRepository.PagePriceTrackingContacts(id, page ?? 1, filter ?? "", sortField, sortOrder ?? 0);

            return(View(cwtPaginatedList));
        }
        // GET: /Export
        public ActionResult Export(int id)
        {
            //Get Item From Database
            PriceTrackingSetupGroup priceTrackingSetupGroup = new PriceTrackingSetupGroup();

            priceTrackingSetupGroup = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

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

            priceTrackingSetupGroupRepository.EditForDisplay(priceTrackingSetupGroup);

            //Export to Excel File
            DataSet priceTrackingSetupGroupExcelData = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroupExcelData(priceTrackingSetupGroup.PriceTrackingSetupGroupId);

            using (XLWorkbook workbook = new XLWorkbook())
            {
                workbook.Worksheets.Add(priceTrackingSetupGroupExcelData);
                workbook.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
                workbook.Style.Font.Bold            = true;
                Response.Clear();
                Response.Buffer      = true;
                Response.Charset     = "";
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", string.Format("attachment;filename= {0}.xlsx", priceTrackingSetupGroup.PriceTrackingSetupGroupName));
                using (MemoryStream MyMemoryStream = new MemoryStream())
                {
                    workbook.SaveAs(MyMemoryStream);
                    MyMemoryStream.WriteTo(Response.OutputStream);
                    Response.Flush();
                }
            }

            Response.End();
            return(View());
        }
 public PriceTrackingSetupGroupVM(PriceTrackingSetupGroup priceTrackingSetupGroup)
 {
     PriceTrackingSetupGroup = priceTrackingSetupGroup;
 }
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            //Get Item From Database
            PriceTrackingSetupGroupItemAir group = new PriceTrackingSetupGroupItemAir();

            group = priceTrackingSetupGroupItemAirRepository.GetPriceTrackingSetupGroupItemAir(id);

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

            //Get Item From Database
            PriceTrackingSetupGroup priceTrackingSetupGroup = new PriceTrackingSetupGroup();

            priceTrackingSetupGroup = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(group.PriceTrackingSetupGroupId);

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

            //Check Access to PriceTrackingSetupGroup
            RolesRepository rolesRepository = new RolesRepository();

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

            priceTrackingSetupGroupItemAirRepository.EditForDisplay(group);

            //Set Access Rights to Admin
            ViewData["AdminAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess(adminGroupName))
            {
                ViewData["AdminAccess"] = "WriteAccess";
            }

            //PriceTrackingSetupGroup
            ViewData["PriceTrackingSetupGroupId"]   = priceTrackingSetupGroup.PriceTrackingSetupGroupId;
            ViewData["PriceTrackingSetupGroupName"] = priceTrackingSetupGroup.PriceTrackingSetupGroupName;

            //Currency
            CurrencyRepository currencyRepository = new CurrencyRepository();
            SelectList         currencysList      = new SelectList(currencyRepository.GetAllCurrencies().ToList(), "CurrencyCode", "Name", group.CurrencyCode);

            ViewData["Currencies"] = currencysList;

            //Lists

            ViewData["ClientHasProvidedWrittenApprovalFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.ClientHasProvidedWrittenApprovalFlag);

            ViewData["SharedSavingsList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.SharedSavingsFlag);

            ViewData["TransactionFeeList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.TransactionFeeFlag);

            ViewData["CentralFulfillmentTimeZoneRuleCodes"] = new SelectList(timeZoneRuleRepository.GetAllTimeZoneRules().ToList(), "TimeZoneRuleCode", "TimeZoneRuleCodeDesc", group.CentralFulfillmentTimeZoneRuleCode);

            ViewData["TimeZoneRules"] = new SelectList(timeZoneRuleRepository.GetAllTimeZoneRules().ToList(), "TimeZoneRuleCode", "TimeZoneRuleCodeDesc", group.TimeZoneRuleCode);

            ViewData["RefundableToRefundableWithPenaltyForRefundAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.RefundableToRefundableWithPenaltyForRefundAllowedFlag);

            ViewData["RefundableToNonRefundableAllowedFlag"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.RefundableToNonRefundableAllowedFlag);

            ViewData["VoidWindowAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.VoidWindowAllowedFlag);

            ViewData["RefundableToRefundableOutsideVoidWindowAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.RefundableToRefundableOutsideVoidWindowAllowedFlag);

            ViewData["NonRefundableToNonRefundableOutsideVoidWindowAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.NonRefundableToNonRefundableOutsideVoidWindowAllowedFlag);

            ViewData["ExchangesAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.ExchangesAllowedFlag);

            ViewData["VoidExchangeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.VoidExchangeAllowedFlag);

            if (group.ExchangePreviousExchangeAllowedFlag == true || group.ExchangePreviousExchangeAllowedFlag == false)
            {
                ViewData["ExchangePreviousExchangeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.ExchangePreviousExchangeAllowedFlag);
            }
            else
            {
                ViewData["ExchangePreviousExchangeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text");
            }

            ViewData["NonRefundableToLowerNonRefundableWithDifferentChangeFeeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                                                group.NonRefundableToLowerNonRefundableWithDifferentChangeFeeAllowedFlag);

            ViewData["RefundableToLowerNonRefundableAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                       group.RefundableToLowerNonRefundableAllowedFlag);

            ViewData["RefundableToLowerRefundableAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                    group.RefundableToLowerRefundableAllowedFlag);

            ViewData["NonPenaltyRefundableToLowerPenaltyRefundableAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                                     group.NonPenaltyRefundableToLowerPenaltyRefundableAllowedFlag);

            ViewData["ChargeChangeFeeUpFrontForSpecificCarriersFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                           group.ChargeChangeFeeUpFrontForSpecificCarriersFlag);

            ViewData["ChangeFeeMustBeUsedFromResidualValueFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                      group.ChangeFeeMustBeUsedFromResidualValueFlag);

            ViewData["TrackPrivateNegotiatedFareFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text");

            ViewData["AutomaticReticketingFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.AutomaticReticketingFlag);

            //System User
            ViewData["SystemUser"] = group.LastUpdateUserIdentifier != null ? group.LastUpdateUserIdentifier : group.CreationUserIdentifier;

            return(View(group));
        }
        // GET: /Create
        public ActionResult Create(int id)
        {
            //Get Item From Database
            PriceTrackingSetupGroup group = new PriceTrackingSetupGroup();

            group = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

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

            //Set Access Rights to Admin
            ViewData["AdminAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess(adminGroupName))
            {
                ViewData["AdminAccess"] = "WriteAccess";
            }

            //PriceTrackingSetupGroup
            ViewData["PriceTrackingSetupGroupId"]   = group.PriceTrackingSetupGroupId;
            ViewData["PriceTrackingSetupGroupName"] = group.PriceTrackingSetupGroupName;

            //PriceTrackingSetupGroupItemAir
            PriceTrackingSetupGroupItemAir priceTrackingSetupGroupItemAir = new PriceTrackingSetupGroupItemAir();

            priceTrackingSetupGroupItemAir.PriceTrackingSetupGroupId = id;

            //Default Flags
            priceTrackingSetupGroupItemAir.SharedSavingsFlag  = true;
            priceTrackingSetupGroupItemAir.TransactionFeeFlag = false;
            priceTrackingSetupGroupItemAir.RefundableToRefundableWithPenaltyForRefundAllowedFlag = true;
            priceTrackingSetupGroupItemAir.RefundableToNonRefundableAllowedFlag = true;
            priceTrackingSetupGroupItemAir.VoidWindowAllowedFlag = true;
            priceTrackingSetupGroupItemAir.RefundableToRefundableOutsideVoidWindowAllowedFlag       = true;
            priceTrackingSetupGroupItemAir.NonRefundableToNonRefundableOutsideVoidWindowAllowedFlag = true;
            priceTrackingSetupGroupItemAir.ExchangesAllowedFlag    = true;
            priceTrackingSetupGroupItemAir.VoidExchangeAllowedFlag = true;
            priceTrackingSetupGroupItemAir.NonRefundableToLowerNonRefundableWithDifferentChangeFeeAllowedFlag = true;
            priceTrackingSetupGroupItemAir.RefundableToLowerNonRefundableAllowedFlag = true;
            priceTrackingSetupGroupItemAir.RefundableToLowerRefundableAllowedFlag    = true;
            priceTrackingSetupGroupItemAir.NonPenaltyRefundableToLowerPenaltyRefundableAllowedFlag = true;
            priceTrackingSetupGroupItemAir.ChargeChangeFeeUpFrontForSpecificCarriersFlag           = true;
            priceTrackingSetupGroupItemAir.ChangeFeeMustBeUsedFromResidualValueFlag = true;
            priceTrackingSetupGroupItemAir.AutomaticReticketingFlag = true;

            //Pricing Model Defaults
            priceTrackingSetupGroupItemAir.SharedSavingsAmount = 30;

            //Switch Window Defaults
            priceTrackingSetupGroupItemAir.RefundableToRefundablePreDepartureDayAmount    = 5;
            priceTrackingSetupGroupItemAir.RefundableToNonRefundablePreDepartureDayAmount = 5;

            //Reason Codes
            priceTrackingSetupGroupItemAir.RealisedSavingsCode = "XX";
            priceTrackingSetupGroupItemAir.MissedSavingsCode   = "L";

            //Admin Only
            priceTrackingSetupGroupItemAir.AlphaCodeRemarkField = "Y";

            //Currency
            CurrencyRepository currencyRepository = new CurrencyRepository();
            SelectList         currencysList      = new SelectList(currencyRepository.GetAllCurrencies().ToList(), "CurrencyCode", "Name");

            ViewData["Currencies"] = currencysList;

            //Lists

            ViewData["ClientHasProvidedWrittenApprovalFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.ClientHasProvidedWrittenApprovalFlag);

            ViewData["SharedSavingsList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.SharedSavingsFlag);

            ViewData["TransactionFeeList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.TransactionFeeFlag);

            ViewData["CentralFulfillmentTimeZoneRuleCodes"] = new SelectList(timeZoneRuleRepository.GetAllTimeZoneRules().ToList(), "TimeZoneRuleCode", "TimeZoneRuleCodeDesc");

            ViewData["TimeZoneRules"] = new SelectList(timeZoneRuleRepository.GetAllTimeZoneRules().ToList(), "TimeZoneRuleCode", "TimeZoneRuleCodeDesc");

            ViewData["RefundableToRefundableWithPenaltyForRefundAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.RefundableToRefundableWithPenaltyForRefundAllowedFlag);

            ViewData["RefundableToNonRefundableAllowedFlag"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.RefundableToNonRefundableAllowedFlag);

            ViewData["VoidWindowAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.VoidWindowAllowedFlag);

            ViewData["RefundableToRefundableOutsideVoidWindowAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.RefundableToRefundableOutsideVoidWindowAllowedFlag);

            ViewData["NonRefundableToNonRefundableOutsideVoidWindowAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.NonRefundableToNonRefundableOutsideVoidWindowAllowedFlag);

            ViewData["ExchangesAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.ExchangesAllowedFlag);

            ViewData["VoidExchangeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.VoidExchangeAllowedFlag);

            ViewData["ExchangePreviousExchangeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text");

            ViewData["NonRefundableToLowerNonRefundableWithDifferentChangeFeeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                                                priceTrackingSetupGroupItemAir.NonRefundableToLowerNonRefundableWithDifferentChangeFeeAllowedFlag);

            ViewData["RefundableToLowerNonRefundableAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                       priceTrackingSetupGroupItemAir.RefundableToLowerNonRefundableAllowedFlag);

            ViewData["RefundableToLowerRefundableAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                    priceTrackingSetupGroupItemAir.RefundableToLowerRefundableAllowedFlag);

            ViewData["NonPenaltyRefundableToLowerPenaltyRefundableAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                                     priceTrackingSetupGroupItemAir.NonPenaltyRefundableToLowerPenaltyRefundableAllowedFlag);

            ViewData["ChargeChangeFeeUpFrontForSpecificCarriersFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                           priceTrackingSetupGroupItemAir.ChargeChangeFeeUpFrontForSpecificCarriersFlag);

            ViewData["ChangeFeeMustBeUsedFromResidualValueFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text",
                                                                                      priceTrackingSetupGroupItemAir.ChangeFeeMustBeUsedFromResidualValueFlag);

            ViewData["TrackPrivateNegotiatedFareFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text");

            ViewData["AutomaticReticketingFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroupItemAir.AutomaticReticketingFlag);

            //System User
            ViewData["SystemUser"] = "";
            string adminUserGuid = User.Identity.Name.Split(new[] { '|' })[0];
            SystemUserRepository systemUserRepository = new SystemUserRepository();
            SystemUser           systemUser           = systemUserRepository.GetUserBySystemUserGuid(adminUserGuid);

            if (systemUser != null)
            {
                string username = systemUser.FirstName + " " + systemUser.LastName;
                ViewData["SystemUser"] = string.Format("{0} - {1}", username, adminUserGuid);
            }

            return(View(priceTrackingSetupGroupItemAir));
        }
        // GET: /Create
        public ActionResult Create(int id)
        {
            //Get Item From Database
            PriceTrackingSetupGroup group = new PriceTrackingSetupGroup();

            group = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

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

            //Set Access Rights to Admin
            ViewData["AdminAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess(adminGroupName))
            {
                ViewData["AdminAccess"] = "WriteAccess";
            }

            //PriceTrackingSetupGroup
            ViewData["PriceTrackingSetupGroupId"]   = group.PriceTrackingSetupGroupId;
            ViewData["PriceTrackingSetupGroupName"] = group.PriceTrackingSetupGroupName;

            //PriceTrackingSetupGroupItemHotel
            PriceTrackingSetupGroupItemHotel priceTrackingSetupGroupItemHotel = new PriceTrackingSetupGroupItemHotel();

            priceTrackingSetupGroupItemHotel.PriceTrackingSetupGroupId = id;

            //Default Flags
            priceTrackingSetupGroupItemHotel.SharedSavingsFlag  = true;
            priceTrackingSetupGroupItemHotel.TransactionFeeFlag = false;

            //Pricing Model Defaults
            priceTrackingSetupGroupItemHotel.SharedSavingsAmount = 30;

            //Threshold Defaults
            priceTrackingSetupGroupItemHotel.EstimatedCWTRebookingFeeAmount = decimal.Parse("0.00");;
            priceTrackingSetupGroupItemHotel.CWTVoidRefundFeeAmount         = decimal.Parse("0.00");
            priceTrackingSetupGroupItemHotel.ThresholdAmount = decimal.Parse("0.00");

            priceTrackingSetupGroupItemHotel.CalculatedTotalThresholdAmount =
                priceTrackingSetupGroupItemHotel.EstimatedCWTRebookingFeeAmount +
                priceTrackingSetupGroupItemHotel.CWTVoidRefundFeeAmount +
                priceTrackingSetupGroupItemHotel.ThresholdAmount;

            //Hotel Amenity Values Defaults
            priceTrackingSetupGroupItemHotel.RoomTypeUpgradeAllowedFlag           = true;
            priceTrackingSetupGroupItemHotel.BeddingTypeUpgradeAllowedFlag        = true;
            priceTrackingSetupGroupItemHotel.HotelRateCodeUpgradeAllowedFlag      = true;
            priceTrackingSetupGroupItemHotel.NegotiatedUpgradeAllowedFlag         = true;
            priceTrackingSetupGroupItemHotel.CancellationPolicyUpgradeAllowedFlag = true;
            priceTrackingSetupGroupItemHotel.KingQueenUpgradeAllowedFlag          = true;

            //Rate Codes
            priceTrackingSetupGroupItemHotel.CWTRateTrackingCode1 = "CWT";
            priceTrackingSetupGroupItemHotel.CWTRateTrackingCode2 = "CWV";

            //Admin Only
            priceTrackingSetupGroupItemHotel.AlphaCodeRemarkField = "Y";

            //Currency
            CurrencyRepository currencyRepository = new CurrencyRepository();
            SelectList         currencysList      = new SelectList(currencyRepository.GetAllCurrencies().ToList(), "CurrencyCode", "Name");

            ViewData["Currencies"] = currencysList;

            //Lists

            ViewData["ClientHasProvidedWrittenApprovalFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.ClientHasProvidedWrittenApprovalFlag);

            ViewData["ClientHasHotelFeesInMSAFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.ClientHasHotelFeesInMSAFlag);

            ViewData["ClientUsesConfermaVirtualCardsFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.ClientUsesConfermaVirtualCardsFlag);

            ViewData["CentralFulfillmentTimeZoneRuleCodes"] = new SelectList(timeZoneRuleRepository.GetAllTimeZoneRules().ToList(), "TimeZoneRuleCode", "TimeZoneRuleCodeDesc");

            ViewData["TimeZoneRules"] = new SelectList(timeZoneRuleRepository.GetAllTimeZoneRules().ToList(), "TimeZoneRuleCode", "TimeZoneRuleCodeDesc");

            ViewData["SharedSavingsList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.SharedSavingsFlag);

            ViewData["TransactionFeeList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.TransactionFeeFlag);

            ViewData["RoomTypeUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.RoomTypeUpgradeAllowedFlag);

            ViewData["BeddingTypeUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.BeddingTypeUpgradeAllowedFlag);

            ViewData["HotelRateCodeUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.HotelRateCodeUpgradeAllowedFlag);

            ViewData["CancellationPolicyUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.CancellationPolicyUpgradeAllowedFlag);

            ViewData["KingQueenUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.KingQueenUpgradeAllowedFlag);

            ViewData["BreakfastChangesAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", priceTrackingSetupGroupItemHotel.BreakfastChangesAllowedFlag);

            ViewData["EnableValueTrackingFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text");

            //System User
            ViewData["SystemUser"] = "";
            string adminUserGuid = User.Identity.Name.Split(new[] { '|' })[0];
            SystemUserRepository systemUserRepository = new SystemUserRepository();
            SystemUser           systemUser           = systemUserRepository.GetUserBySystemUserGuid(adminUserGuid);

            if (systemUser != null)
            {
                string username = systemUser.FirstName + " " + systemUser.LastName;
                ViewData["SystemUser"] = string.Format("{0} - {1}", username, adminUserGuid);
            }

            return(View(priceTrackingSetupGroupItemHotel));
        }
        public ActionResult Create(PriceTrackingSetupGroupItemAir group, FormCollection collection)
        {
            //Get Item From Database
            PriceTrackingSetupGroup priceTrackingSetupGroup = new PriceTrackingSetupGroup();

            priceTrackingSetupGroup = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(group.PriceTrackingSetupGroupId);

            //Check Exists
            if (priceTrackingSetupGroup == 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(group);
            }
            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
            {
                priceTrackingSetupGroupItemAirRepository.Add(group);
            }
            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(
                       "ListUnDeleted",
                       new {
                id = priceTrackingSetupGroup.PriceTrackingSetupGroupId,
                controller = "PriceTrackingSetupGroup"
            }
                       ));
        }
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            //Get Item From Database
            PriceTrackingSetupGroupItemHotel group = new PriceTrackingSetupGroupItemHotel();

            group = priceTrackingSetupGroupItemHotelRepository.GetPriceTrackingSetupGroupItemHotel(id);

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

            //Get Item From Database
            PriceTrackingSetupGroup priceTrackingSetupGroup = new PriceTrackingSetupGroup();

            priceTrackingSetupGroup = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(group.PriceTrackingSetupGroupId);

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

            //Check Access to PriceTrackingSetupGroup
            RolesRepository rolesRepository = new RolesRepository();

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

            priceTrackingSetupGroupItemHotelRepository.EditForDisplay(group);

            //Set Access Rights to Admin
            ViewData["AdminAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess(adminGroupName))
            {
                ViewData["AdminAccess"] = "WriteAccess";
            }

            //PriceTrackingSetupGroup
            ViewData["PriceTrackingSetupGroupId"]   = priceTrackingSetupGroup.PriceTrackingSetupGroupId;
            ViewData["PriceTrackingSetupGroupName"] = priceTrackingSetupGroup.PriceTrackingSetupGroupName;

            //Currency
            CurrencyRepository currencyRepository = new CurrencyRepository();
            SelectList         currencysList      = new SelectList(currencyRepository.GetAllCurrencies().ToList(), "CurrencyCode", "Name", group.CurrencyCode);

            ViewData["Currencies"] = currencysList;

            //Lists

            ViewData["ClientHasProvidedWrittenApprovalFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.ClientHasProvidedWrittenApprovalFlag);

            ViewData["ClientHasHotelFeesInMSAFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.ClientHasHotelFeesInMSAFlag);

            ViewData["ClientUsesConfermaVirtualCardsFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.ClientUsesConfermaVirtualCardsFlag);

            ViewData["CentralFulfillmentTimeZoneRuleCodes"] = new SelectList(timeZoneRuleRepository.GetAllTimeZoneRules().ToList(), "TimeZoneRuleCode", "TimeZoneRuleCodeDesc");

            ViewData["ClientHasHotelFeesInMSAFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.ClientHasHotelFeesInMSAFlag);

            ViewData["SharedSavingsList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.SharedSavingsFlag);

            ViewData["TransactionFeeList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.TransactionFeeFlag);

            ViewData["RoomTypeUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.RoomTypeUpgradeAllowedFlag);

            ViewData["BeddingTypeUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.BeddingTypeUpgradeAllowedFlag);

            ViewData["HotelRateCodeUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.HotelRateCodeUpgradeAllowedFlag);

            ViewData["CancellationPolicyUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.CancellationPolicyUpgradeAllowedFlag);

            ViewData["KingQueenUpgradeAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.KingQueenUpgradeAllowedFlag);

            ViewData["BreakfastChangesAllowedFlagList"] = new SelectList(commonRepository.GetAllowedNotAllowedList().ToList(), "Value", "Text", group.BreakfastChangesAllowedFlag);

            ViewData["EnableValueTrackingFlagList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text");

            //System User
            ViewData["SystemUser"] = group.LastUpdateUserIdentifier != null ? group.LastUpdateUserIdentifier : group.CreationUserIdentifier;

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

            //Check Access Rights to Domain Hierarchy
            if (!hierarchyRepository.AdminHasDomainHierarchyWriteAccess(group.HierarchyType, group.HierarchyCode, group.SourceSystemCode, groupName))
            {
                ViewData["Message"] = "You cannot add to this hierarchy item";
                return(View("Error"));
            }

            //Capture XML from multiple fields
            group.PriceTrackingSetupGroupAdditionalPseudoCityOrOfficeIdsXML = GetAdditionalPseudoCityOrOfficeIdsXML(collection);
            group.PriceTrackingSetupGroupExcludedTravelerTypesXML           = GetPriceTrackingSetupGroupExcludedTravelerTypesXML(collection);

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel(group);
            }
            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"));
            }

            //ClientSubUnitTravelerType has extra field
            string hierarchyCode = group.HierarchyCode;

            if (group.HierarchyType == "ClientSubUnitTravelerType")
            {
                group.ClientSubUnitGuid = hierarchyCode;  //ClientSubUnitTravelerType has 2 primarykeys
            }

            //Database Update
            try
            {
                priceTrackingSetupGroupRepository.Add(group);
            }
            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("ListUnDeleted"));
        }
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            //Get Item From Database
            PriceTrackingSetupGroup group = new PriceTrackingSetupGroup();

            group = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

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

            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

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

            //Set Access Rights
            ViewData["FIQIDAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess(fIQIDGroupName))
            {
                ViewData["FIQIDAccess"] = "WriteAccess";
            }

            priceTrackingSetupGroupRepository.EditForDisplay(group);

            TripTypeRepository tripTypeRepository = new TripTypeRepository();
            SelectList         tripTypesList      = new SelectList(tripTypeRepository.GetAllTripTypes().ToList(), "TripTypeId", "TripTypeDescription");

            ViewData["tripTypes"] = tripTypesList;

            GDSRepository gdsRepository = new GDSRepository();
            SelectList    gDSList       = new SelectList(gdsRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName");

            ViewData["GDSs"] = gDSList;

            PNROutputTypeRepository pNROutputTypeRepository = new PNROutputTypeRepository();
            SelectList pNROutputTypeList = new SelectList(pNROutputTypeRepository.GetAllPNROutputTypes().ToList(), "PNROutputTypeId", "PNROutputTypeName");

            ViewData["PNROutputTypes"] = pNROutputTypeList;

            TablesDomainHierarchyLevelRepository tablesDomainHierarchyLevelRepository = new TablesDomainHierarchyLevelRepository();
            SelectList hierarchyTypesList = new SelectList(tablesDomainHierarchyLevelRepository.GetDomainHierarchies(groupName).ToList(), "HierarchyLevelTableName", "HierarchyLevelTableName");

            ViewData["HierarchyTypes"] = hierarchyTypesList;

            PriceTrackingSetupTypeRepository priceTrackingSetupTypeRepository = new PriceTrackingSetupTypeRepository();
            SelectList priceTrackingSetupTypes = new SelectList(priceTrackingSetupTypeRepository.GetAllPriceTrackingSetupTypes().ToList(), "PriceTrackingSetupTypeId", "PriceTrackingSetupTypeName", group.PriceTrackingSetupTypeId);

            ViewData["PriceTrackingSetupTypes"] = priceTrackingSetupTypes;

            DesktopUsedTypeRepository desktopUsedTypeRepository = new DesktopUsedTypeRepository();
            SelectList desktopUsedTypes = new SelectList(desktopUsedTypeRepository.GetAllDesktopUsedTypes().ToList(), "DesktopUsedTypeId", "DesktopUsedTypeDescription", group.DesktopUsedTypeId);

            ViewData["DesktopUsedTypes"] = desktopUsedTypes;

            PriceTrackingMidOfficePlatformRepository priceTrackingMidOfficePlatformRepository = new PriceTrackingMidOfficePlatformRepository();
            SelectList priceTrackingMidOfficePlatforms = new SelectList(priceTrackingMidOfficePlatformRepository.GetAllPriceTrackingMidOfficePlatforms().ToList(), "PriceTrackingMidOfficePlatformId", "PriceTrackingMidOfficePlatformName", group.PriceTrackingMidOfficePlatformId);

            ViewData["PriceTrackingMidOfficePlatforms"] = priceTrackingMidOfficePlatforms;

            ViewData["SharedPseudoCityOrOfficeList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.SharedPseudoCityOrOfficeIdFlag);

            ViewData["MidOfficeUsedForQCTicketingList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.MidOfficeUsedForQCTicketingFlag);

            ViewData["USGovernmentContractorList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", group.USGovernmentContractorFlag);

            ViewData["PriceTrackingSetupGroupAdditionalPseudoCityOrOfficeIdList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", "false");

            PriceTrackingItinerarySolutionRepository priceTrackingItinerarySolutionRepository = new PriceTrackingItinerarySolutionRepository();
            SelectList priceTrackingItinerarySolutions = new SelectList(priceTrackingItinerarySolutionRepository.GetAllPriceTrackingItinerarySolutions().ToList(), "PriceTrackingItinerarySolutionId", "PriceTrackingItinerarySolutionName", group.PriceTrackingItinerarySolutionId);

            ViewData["PriceTrackingItinerarySolutions"] = priceTrackingItinerarySolutions;

            PriceTrackingSystemRuleRepository priceTrackingSystemRuleRepository = new PriceTrackingSystemRuleRepository();
            SelectList priceTrackingSystemRules = new SelectList(priceTrackingSystemRuleRepository.GetAllPriceTrackingSystemRules().ToList(), "PriceTrackingSystemRuleId", "PriceTrackingSystemRuleName", group.PriceTrackingSystemRuleId);

            ViewData["PriceTrackingSystemRules"] = priceTrackingSystemRules;

            BackOfficeSystemRepository backOfficeSystemRepository = new BackOfficeSystemRepository();
            SelectList backOfficeSystems = new SelectList(backOfficeSystemRepository.GetAllBackOfficeSystems().ToList(), "BackOfficeSytemId", "BackOfficeSystemDescription", group.BackOfficeSystemId);

            ViewData["BackOfficeSystems"] = backOfficeSystems;

            PriceTrackingBillingModelRepository priceTrackingBillingModelRepository = new PriceTrackingBillingModelRepository();
            List <PriceTrackingBillingModel>    priceTrackingBillingModels          = priceTrackingBillingModelRepository.GetAllPriceTrackingBillingModels().ToList();

            SelectList airPriceTrackingBillingModels = new SelectList(priceTrackingBillingModels, "PriceTrackingBillingModelId", "PriceTrackingBillingModelName", group.AirPriceTrackingBillingModelId);

            ViewData["AirPriceTrackingBillingModels"] = airPriceTrackingBillingModels;

            SelectList hotelPriceTrackingBillingModels = new SelectList(priceTrackingBillingModels, "PriceTrackingBillingModelId", "PriceTrackingBillingModelName", group.HotelPriceTrackingBillingModelId);

            ViewData["HotelPriceTrackingBillingModels"] = hotelPriceTrackingBillingModels;

            SelectList preTicketPriceTrackingBillingModels = new SelectList(priceTrackingBillingModels, "PriceTrackingBillingModelId", "PriceTrackingBillingModelName", group.PreTicketPriceTrackingBillingModelId);

            ViewData["PreTicketPriceTrackingBillingModels"] = preTicketPriceTrackingBillingModels;

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

            PriceTrackingSetupGroup priceTrackingSetupGroup = new PriceTrackingSetupGroup();

            priceTrackingSetupGroup.MidOfficeUsedForQCTicketingFlag = true;

            TripTypeRepository tripTypeRepository = new TripTypeRepository();
            SelectList         tripTypesList      = new SelectList(tripTypeRepository.GetAllTripTypes().ToList(), "TripTypeId", "TripTypeDescription");

            ViewData["TripTypes"] = tripTypesList;

            GDSRepository gdsRepository = new GDSRepository();
            SelectList    gDSList       = new SelectList(gdsRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName");

            ViewData["GDSs"] = gDSList;

            PNROutputTypeRepository pNROutputTypeRepository = new PNROutputTypeRepository();
            SelectList pNROutputTypeList = new SelectList(pNROutputTypeRepository.GetAllPNROutputTypes().ToList(), "PNROutputTypeId", "PNROutputTypeName");

            ViewData["PNROutputTypes"] = pNROutputTypeList;

            TablesDomainHierarchyLevelRepository tablesDomainHierarchyLevelRepository = new TablesDomainHierarchyLevelRepository();
            SelectList hierarchyTypesList = new SelectList(tablesDomainHierarchyLevelRepository.GetDomainHierarchies(groupName).ToList(), "HierarchyLevelTableName", "HierarchyLevelTableName");

            ViewData["HierarchyTypes"] = hierarchyTypesList;

            PriceTrackingSetupTypeRepository priceTrackingSetupTypeRepository = new PriceTrackingSetupTypeRepository();
            SelectList priceTrackingSetupTypes = new SelectList(priceTrackingSetupTypeRepository.GetAllPriceTrackingSetupTypes().ToList(), "PriceTrackingSetupTypeId", "PriceTrackingSetupTypeName");

            ViewData["PriceTrackingSetupTypes"] = priceTrackingSetupTypes;

            DesktopUsedTypeRepository desktopUsedTypeRepository = new DesktopUsedTypeRepository();
            SelectList desktopUsedTypes = new SelectList(desktopUsedTypeRepository.GetAllDesktopUsedTypes().ToList(), "DesktopUsedTypeId", "DesktopUsedTypeDescription");

            ViewData["DesktopUsedTypes"] = desktopUsedTypes;

            PriceTrackingMidOfficePlatformRepository priceTrackingMidOfficePlatformRepository = new PriceTrackingMidOfficePlatformRepository();
            SelectList priceTrackingMidOfficePlatforms = new SelectList(priceTrackingMidOfficePlatformRepository.GetAllPriceTrackingMidOfficePlatforms().ToList(), "PriceTrackingMidOfficePlatformId", "PriceTrackingMidOfficePlatformName");

            ViewData["PriceTrackingMidOfficePlatforms"] = priceTrackingMidOfficePlatforms;

            ViewData["SharedPseudoCityOrOfficeList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text");

            ViewData["MidOfficeUsedForQCTicketingList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", priceTrackingSetupGroup.MidOfficeUsedForQCTicketingFlag);

            ViewData["USGovernmentContractorList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text");

            ViewData["PriceTrackingSetupGroupAdditionalPseudoCityOrOfficeIdList"] = new SelectList(commonRepository.GetTrueFalseList().ToList(), "Value", "Text", "false");

            PriceTrackingItinerarySolutionRepository priceTrackingItinerarySolutionRepository = new PriceTrackingItinerarySolutionRepository();
            SelectList priceTrackingItinerarySolutions = new SelectList(priceTrackingItinerarySolutionRepository.GetAllPriceTrackingItinerarySolutions().ToList(), "PriceTrackingItinerarySolutionId", "PriceTrackingItinerarySolutionName");

            ViewData["PriceTrackingItinerarySolutions"] = priceTrackingItinerarySolutions;

            PriceTrackingSystemRuleRepository priceTrackingSystemRuleRepository = new PriceTrackingSystemRuleRepository();
            SelectList priceTrackingSystemRules = new SelectList(priceTrackingSystemRuleRepository.GetAllPriceTrackingSystemRules().ToList(), "PriceTrackingSystemRuleId", "PriceTrackingSystemRuleName");

            ViewData["PriceTrackingSystemRules"] = priceTrackingSystemRules;

            BackOfficeSystemRepository backOfficeSystemRepository = new BackOfficeSystemRepository();
            SelectList backOfficeSystems = new SelectList(backOfficeSystemRepository.GetAllBackOfficeSystems().ToList(), "BackOfficeSytemId", "BackOfficeSystemDescription");

            ViewData["BackOfficeSystems"] = backOfficeSystems;

            PriceTrackingBillingModelRepository priceTrackingBillingModelRepository = new PriceTrackingBillingModelRepository();
            List <PriceTrackingBillingModel>    priceTrackingBillingModels          = priceTrackingBillingModelRepository.GetAllPriceTrackingBillingModels().ToList();
            SelectList priceTrackingBillingModelsList = new SelectList(priceTrackingBillingModels, "PriceTrackingBillingModelId", "PriceTrackingBillingModelName");

            ViewData["AirPriceTrackingBillingModels"]       = priceTrackingBillingModelsList;
            ViewData["HotelPriceTrackingBillingModels"]     = priceTrackingBillingModelsList;
            ViewData["PreTicketPriceTrackingBillingModels"] = priceTrackingBillingModelsList;

            return(View(priceTrackingSetupGroup));
        }
        public ActionResult Edit(int id, FormCollection collection)
        {
            //Get Item From Database
            PriceTrackingSetupGroup group = new PriceTrackingSetupGroup();

            group = priceTrackingSetupGroupRepository.GetPriceTrackingSetupGroup(id);

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

            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

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

            //Capture XML from multiple fields
            group.PriceTrackingSetupGroupAdditionalPseudoCityOrOfficeIdsXML = GetAdditionalPseudoCityOrOfficeIdsXML(collection);
            group.PriceTrackingSetupGroupExcludedTravelerTypesXML           = GetPriceTrackingSetupGroupExcludedTravelerTypesXML(collection);

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel(group);
            }
            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"));
            }

            //Dont check for multiple as We are not editing Hierarchy, we have alrady checked access to the item itself
            if (group.HierarchyType != "Multiple")
            {
                //ClientSubUnitTravelerType has extra field
                string hierarchyCode = group.HierarchyCode;
                if (group.HierarchyType == "ClientSubUnitTravelerType")
                {
                    group.ClientSubUnitGuid = hierarchyCode;  //ClientSubUnitTravelerType has 2 primarykeys
                }

                //Check Access Rights
                HierarchyRepository hierarchyRepository = new HierarchyRepository();
                if (!hierarchyRepository.AdminHasDomainHierarchyWriteAccess(group.HierarchyType, hierarchyCode, group.SourceSystemCode, groupName))
                {
                    ViewData["Message"] = "You cannot add to this hierarchy item";
                    return(View("Error"));
                }
            }

            //Database Update
            try
            {
                priceTrackingSetupGroupRepository.Update(group);
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PriceTrackingSetupGroup.mvc/Edit/" + group.PriceTrackingSetupGroupId.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("ListUnDeleted"));
        }