public ActionResult UnDelete(int id)
        {
            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(id);

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

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

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

            ThirdPartyUserVM thirdPartyUserVM = new ThirdPartyUserVM();

            thirdPartyUserRepository.EditForDisplay(thirdPartyUser);
            thirdPartyUserVM.ThirdPartyUser = thirdPartyUser;

            return(View(thirdPartyUserVM));
        }
        public ActionResult View(int id)
        {
            ThirdPartyUserGDSAccessRight thirdPartyUserGDSAccessRight = new ThirdPartyUserGDSAccessRight();

            thirdPartyUserGDSAccessRight = thirdPartyUserGDSAccessRightRepository.GetThirdPartyUserGDSAccessRight(id);

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

            ThirdPartyUserGDSAccessRightVM thirdPartyUserGDSAccessRightVM = new ThirdPartyUserGDSAccessRightVM();

            //System User
            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(thirdPartyUserGDSAccessRight.ThirdPartyUserId);
            if (thirdPartyUser != null)
            {
                thirdPartyUserGDSAccessRightVM.ThirdPartyUser = thirdPartyUser;
            }

            thirdPartyUserGDSAccessRightVM.ThirdPartyUserGDSAccessRight = thirdPartyUserGDSAccessRight;

            return(View(thirdPartyUserGDSAccessRightVM));
        }
        public ActionResult Create(int id)
        {
            //Set Access Rights
            ViewData["Access"] = "";
            if (rolesRepository.HasWriteAccessToThirdPartyGDSAccessRights(id))
            {
                ViewData["Access"] = "WriteAccess";
            }

            ThirdPartyUserGDSAccessRightVM thirdPartyUserGDSAccessRightVM = new ThirdPartyUserGDSAccessRightVM();

            ThirdPartyUserGDSAccessRight thirdPartyUserGDSAccessRight = new ThirdPartyUserGDSAccessRight();

            thirdPartyUserGDSAccessRightVM.ThirdPartyUserGDSAccessRight = thirdPartyUserGDSAccessRight;

            //GDS
            thirdPartyUserGDSAccessRightVM.GDSs = new SelectList(gdsRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName");

            //GDSAccessTypes
            thirdPartyUserGDSAccessRightVM.GDSAccessTypes = new SelectList(gdsAccessTypeRepository.GetAllGDSAccessTypes().ToList(), "GDSAccessTypeId", "GDSAccessTypeName");

            //ThirdPartyUser
            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(id);
            if (thirdPartyUser != null)
            {
                thirdPartyUserRepository.EditForDisplay(thirdPartyUser);
                thirdPartyUserGDSAccessRightVM.ThirdPartyUser = thirdPartyUser;
                thirdPartyUserGDSAccessRightVM.ThirdPartyUserGDSAccessRight.ThirdPartyUserId = thirdPartyUser.ThirdPartyUserId;
            }

            return(View(thirdPartyUserGDSAccessRightVM));
        }
        public ActionResult Edit(ThirdPartyUserGDSAccessRightVM thirdPartyUserGDSAccessRightVM)
        {
            RolesRepository rolesRepository = new RolesRepository();

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

            //Add in ThirdPartyUser
            if (thirdPartyUserGDSAccessRightVM.ThirdPartyUserGDSAccessRight.ThirdPartyUserId > 0)
            {
                ThirdPartyUserRepository thirdPartyUserRepository = new ThirdPartyUserRepository();
                ThirdPartyUser           thirdPartyUser           = thirdPartyUserRepository.GetThirdPartyUser(thirdPartyUserGDSAccessRightVM.ThirdPartyUserGDSAccessRight.ThirdPartyUserId);
                if (thirdPartyUser != null)
                {
                    thirdPartyUserGDSAccessRightVM.ThirdPartyUser = thirdPartyUser;
                }
            }

            //Update  Model from Form
            try
            {
                TryUpdateModel <ThirdPartyUserGDSAccessRight>(thirdPartyUserGDSAccessRightVM.ThirdPartyUserGDSAccessRight, "ThirdPartyUserGDSAccessRight");
            }
            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
            {
                thirdPartyUserGDSAccessRightRepository.Update(thirdPartyUserGDSAccessRightVM);
            }
            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("ListUnDeleted", new { id = thirdPartyUserGDSAccessRightVM.ThirdPartyUserGDSAccessRight.ThirdPartyUserId }));
        }
        public ActionResult UnDelete(int id, int thirdPartyUserId)
        {
            ThirdPartyUserGDSAccessRight thirdPartyUserGDSAccessRight = new ThirdPartyUserGDSAccessRight();

            thirdPartyUserGDSAccessRight = thirdPartyUserGDSAccessRightRepository.GetThirdPartyUserGDSAccessRight(id);

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

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

            ThirdPartyUserGDSAccessRightVM thirdPartyUserGDSAccessRightVM = new ThirdPartyUserGDSAccessRightVM();

            //System User
            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(thirdPartyUserGDSAccessRight.ThirdPartyUserId);
            if (thirdPartyUser != null)
            {
                thirdPartyUserRepository.EditForDisplay(thirdPartyUser);
                thirdPartyUserGDSAccessRightVM.ThirdPartyUser = thirdPartyUser;
            }

            //Entitlements (All but this one)
            if (thirdPartyUser.ThirdPartyUserGDSAccessRights != null && thirdPartyUser.ThirdPartyUserGDSAccessRights.Count() > 0)
            {
                List <Entitlement> entitlements = new List <Entitlement>();
                foreach (ThirdPartyUserGDSAccessRight item in thirdPartyUser.ThirdPartyUserGDSAccessRights.Where(x => x.ThirdPartyUserGDSAccessRightId != thirdPartyUserGDSAccessRight.ThirdPartyUserGDSAccessRightId))
                {
                    Entitlement entitlement = new Entitlement()
                    {
                        tpAgentID        = item.GDSSignOnID,
                        tpPCC            = item.PseudoCityOrOfficeId,
                        tpServiceID      = item.GDS.GDSName,
                        DeletedFlag      = item.DeletedFlag == true ? true : false,
                        DeletedTimestamp = item.DeletedDateTime
                    };
                    entitlements.Add(entitlement);
                }
                thirdPartyUserGDSAccessRightVM.Entitlements = entitlements;
            }

            thirdPartyUserGDSAccessRightVM.ThirdPartyUserGDSAccessRight = thirdPartyUserGDSAccessRight;

            return(View(thirdPartyUserGDSAccessRightVM));
        }
        AccountModifyByThirdId(string thirdPartyUserId, ThirdPartyUser request)
        {
            var result = await Http.PostAsync <
                AccountModifyResponse,
                ThirdPartyUser>(
                $"{Option.BaseUrl}/v1/accounts/updateByThirdId?thirdPartyUserId={thirdPartyUserId}",
                request
                );

            return(result);
        }
        //Add Data From Linked Tables for Display
        public void EditForDisplay(ThirdPartyUser thirdPartyUser)
        {
            //Flags
            thirdPartyUser.IsActiveFlagNonNullable    = (thirdPartyUser.IsActiveFlag.HasValue) ? thirdPartyUser.IsActiveFlag.Value : false;
            thirdPartyUser.RoboticUserFlagNonNullable = (thirdPartyUser.RoboticUserFlag.HasValue) ? thirdPartyUser.RoboticUserFlag.Value : false;
            thirdPartyUser.CubaBookingAllowanceIndicatorNonNullable = (thirdPartyUser.CubaBookingAllowanceIndicator.HasValue) ? thirdPartyUser.CubaBookingAllowanceIndicator.Value : false;
            thirdPartyUser.MilitaryAndGovernmentUserFlagNonNullable = (thirdPartyUser.MilitaryAndGovernmentUserFlag.HasValue) ? thirdPartyUser.MilitaryAndGovernmentUserFlag.Value : false;

            if (thirdPartyUser.Partner != null)
            {
                thirdPartyUser.PartnerName = thirdPartyUser.Partner.PartnerName;
            }

            if (thirdPartyUser.Country != null)
            {
                thirdPartyUser.CountryName = thirdPartyUser.Country.CountryName;
            }

            if (thirdPartyUser.ClientTopUnit != null)
            {
                thirdPartyUser.ClientTopUnitName = thirdPartyUser.ClientTopUnit.ClientTopUnitName;
            }

            if (thirdPartyUser.ClientSubUnit != null)
            {
                thirdPartyUser.ClientSubUnitName = thirdPartyUser.ClientSubUnit.ClientSubUnitName;
            }

            if (thirdPartyUser.StateProvinceCode != null)
            {
                StateProvinceRepository stateProvinceRepository = new StateProvinceRepository();
                thirdPartyUser.StateProvince = stateProvinceRepository.GetStateProvinceByCountry(thirdPartyUser.CountryCode, thirdPartyUser.StateProvinceCode);
            }

            //ThirdPartyUserGDSAccessRights
            if (thirdPartyUser.ThirdPartyUserGDSAccessRights != null && thirdPartyUser.ThirdPartyUserGDSAccessRights.Count() > 0)
            {
                List <Entitlement> entitlements = new List <Entitlement>();
                foreach (ThirdPartyUserGDSAccessRight thirdPartyUserGDSAccessRight in thirdPartyUser.ThirdPartyUserGDSAccessRights)
                {
                    Entitlement entitlement = new Entitlement()
                    {
                        tpAgentID        = thirdPartyUserGDSAccessRight.GDSSignOnID,
                        tpPCC            = thirdPartyUserGDSAccessRight.PseudoCityOrOfficeId,
                        tpServiceID      = thirdPartyUserGDSAccessRight.GDS.GDSName,
                        DeletedFlag      = thirdPartyUserGDSAccessRight.DeletedFlag == true ? true : false,
                        DeletedTimestamp = thirdPartyUserGDSAccessRight.DeletedDateTime
                    };
                    entitlements.Add(entitlement);
                }
                thirdPartyUser.Entitlements = entitlements;
            }
        }
        public void EditForDisplay(ThirdPartyUserGDSAccessRight gdsAccessRight)
        {
            //System User
            ThirdPartyUser           systemUser           = new ThirdPartyUser();
            ThirdPartyUserRepository systemUserRepository = new ThirdPartyUserRepository();

            systemUser = systemUserRepository.GetThirdPartyUser(gdsAccessRight.ThirdPartyUserId);
            if (systemUser != null)
            {
                gdsAccessRight.ThirdPartyUser = systemUser;
            }
        }
        public async static ETTask LinkByFaceBook(Player player, LinkInfo info, L2C_Link response)
        {
            string fbToken      = info.Secret;
            bool   isValidToken = await FacebookHelper.ValidateFacebookToken(fbToken);

            if (!isValidToken)
            {
                response.Error = ErrorCode.ERR_LinkFailed;
                return;
            }
            ThirdPartyInfo fbInfo = await FacebookHelper.GetFacebookUserInfo(fbToken);

            if (fbInfo == null)
            {
                response.Error = ErrorCode.ERR_LinkFailed;
                return;
            }
            long           now            = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(fbInfo.id, UserDataHelper.tagFB);

            if (thirdPartyUser == null)
            {
                long uid  = player.uid;
                User user = await UserDataHelper.FindOneUser(uid);

                if (user == null)
                {
                    response.Error = ErrorCode.ERR_LinkFailed;
                    return;
                }

                //綁定第三方-FB
                thirdPartyUser          = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId());
                thirdPartyUser.uid      = user.Id;
                thirdPartyUser.party    = UserDataHelper.tagFB;
                thirdPartyUser.userId   = fbInfo.id;
                thirdPartyUser.gender   = fbInfo.gender;
                thirdPartyUser.location = fbInfo.location;
                thirdPartyUser.email    = fbInfo.email;
                thirdPartyUser.name     = fbInfo.name;
                thirdPartyUser.birthday = fbInfo.birthday;
                thirdPartyUser.createAt = now;
                await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser);

                //取得新的第三方列表
                response.LinkTypes.Clear();
                response.LinkTypes.AddRange(await GetAllLinkType(user.Id));
            }
            else
            {
                response.Error = ErrorCode.ERR_LinkIsExist;
            }
        }
        // GET: /List
        public ActionResult ListDeleted(int id, int?page, string filter, string sortField, int?sortOrder)
        {
            //Set Access Rights
            ViewData["Access"] = "";
            if (rolesRepository.HasWriteAccessToThirdPartyGDSAccessRights(id))
            {
                ViewData["Access"] = "WriteAccess";
            }

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

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

            //Populate View Model
            ThirdPartyUserGDSAccessRightsVM thirdPartyUserGDSAccessRightsVM = new ThirdPartyUserGDSAccessRightsVM();

            var getThirdPartyUserGDSAccessRights = thirdPartyUserGDSAccessRightRepository.PageThirdPartyUserGDSAccessRights(id, filter ?? "", sortField, sortOrder ?? 0, page ?? 1, true);

            if (getThirdPartyUserGDSAccessRights != null)
            {
                thirdPartyUserGDSAccessRightsVM.ThirdPartyUserGDSAccessRights = getThirdPartyUserGDSAccessRights;
            }

            //ThirdPartyUser
            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(id);
            if (thirdPartyUser != null)
            {
                thirdPartyUserGDSAccessRightsVM.ThirdPartyUser = thirdPartyUser;
            }

            return(View(thirdPartyUserGDSAccessRightsVM));
        }
        // GET: /View
        public ActionResult View(int id)
        {
            //Check Exists
            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(id);
            if (thirdPartyUser == null)
            {
                ViewData["ActionMethod"] = "ViewGet";
                return(View("RecordDoesNotExistError"));
            }

            thirdPartyUserRepository.EditForDisplay(thirdPartyUser);

            return(View(thirdPartyUser));
        }
        public ActionResult UnDelete(ThirdPartyUserVM thirdPartyUserVM, FormCollection collection)
        {
            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

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

            //Get Item From Database
            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(thirdPartyUserVM.ThirdPartyUser.ThirdPartyUserId);

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

            //Delete Item
            try
            {
                thirdPartyUserVM.ThirdPartyUser.DeletedFlag = false;
                thirdPartyUserRepository.UpdateDeletedStatus(thirdPartyUserVM);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/ThirdPartyUser.mvc/Delete/" + thirdPartyUser.ThirdPartyUserId;
                    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"));
        }
        public async static ETTask <int> AuthenticationByBot(string deviceUniqueIdentifier)
        {
            long           now            = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(deviceUniqueIdentifier, UserDataHelper.tagGuest);

            User user = null;

            if (thirdPartyUser == null)
            {
                user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId());
                string salt         = CryptographyHelper.GenerateRandomId();
                string password     = CryptographyHelper.GenerateRandomId(16);
                string hashPassword = CryptographyHelper.MD5Encoding(password, salt);
                user.salt                          = salt;
                user.hashPassword                  = hashPassword;
                user.createAt                      = now;
                user.name                          = $"{user.Id}";
                user.playerCharSetting             = new PlayerCharSetting();
                user.playerCharSetting.CharacterId = 1L;
                user.playerRideTotalInfo           = new RideTotalInfo();
                user.language                      = 10;
                user.identity                      = (int)User.Identity.TestPlayer;
                user.userBagCapacity               = EquipmentDataHelper.GetDefaultUserBag();
                await UserDataHelper.SinUserUp(user);

                //註冊第三方-Guest
                thirdPartyUser          = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId());
                thirdPartyUser.uid      = user.Id;
                thirdPartyUser.party    = UserDataHelper.tagGuest;
                thirdPartyUser.userId   = deviceUniqueIdentifier;
                thirdPartyUser.name     = "";
                thirdPartyUser.gender   = "";
                thirdPartyUser.location = "";
                thirdPartyUser.email    = "";
                thirdPartyUser.birthday = "";
                thirdPartyUser.createAt = now;
                await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser);

                return(ErrorCode.ERR_Success);
            }
            else
            {
                return(ErrorCode.ERR_DeviceUniqueIdentifierIsExist);
            }
        }
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(id);

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

            ThirdPartyUserVM thirdPartyUserVM = new ThirdPartyUserVM();

            //CubaPseudoCityOrOfficeFlag
            //Only a user with the Compliance Administrator for Global can check or uncheck this box
            ViewData["ComplianceAdministratorAccess"] = "";
            if (rolesRepository.HasWriteAccessToThirdPartyUserCubaBookingAllowanceIndicator())
            {
                ViewData["ComplianceAdministratorAccess"] = "WriteAccess";
            }

            //GovernmentPseudoCityOrOfficeFlag
            //Only a user with the GDS Government Administrator role for Global can check or uncheck this box
            ViewData["GDSGovernmentAdministratorAccess"] = "";
            if (rolesRepository.HasWriteAccessToThirdPartyUserMilitaryAndGovernmentUserFlag())
            {
                ViewData["GDSGovernmentAdministratorAccess"] = "WriteAccess";
            }

            //ThirdPartyUserTypes
            thirdPartyUserVM.ThirdPartyUserTypes = new SelectList(thirdPartyUserTypeRepository.GetAllThirdPartyUserTypes().ToList(), "ThirdPartyUserTypeId", "ThirdPartyUserTypeName", thirdPartyUser.ThirdPartyUserTypeId);

            //GDSThirdPartyVendors
            thirdPartyUserVM.GDSThirdPartyVendors = new SelectList(gdsThirdPartyVendorRepository.GetAllGDSThirdPartyVendors().ToList(), "GDSThirdPartyVendorId", "GDSThirdPartyVendorName", thirdPartyUser.GDSThirdPartyVendorId);

            //StateProvinces
            thirdPartyUserVM.StateProvinces = new SelectList(stateProvinceRepository.GetStateProvincesByCountryCode(thirdPartyUser.CountryCode).ToList(), "StateProvinceCode", "Name", thirdPartyUser.StateProvinceCode);

            thirdPartyUserRepository.EditForDisplay(thirdPartyUser);
            thirdPartyUserVM.ThirdPartyUser = thirdPartyUser;

            return(View(thirdPartyUserVM));
        }
        public ActionResult Create()
        {
            //Set Access Rights
            ViewData["Access"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess(thirdPartyGroupName) || hierarchyRepository.AdminHasDomainWriteAccess(governmentGroupName))
            {
                ViewData["Access"] = "WriteAccess";
            }

            ThirdPartyUserVM thirdPartyUserVM = new ThirdPartyUserVM();

            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser.IsActiveFlagNonNullable    = true;
            thirdPartyUser.RoboticUserFlagNonNullable = false;
            thirdPartyUserVM.ThirdPartyUser           = thirdPartyUser;

            //CubaPseudoCityOrOfficeFlag
            //Only a user with the Compliance Administrator for Global can check or uncheck this box
            ViewData["ComplianceAdministratorAccess"] = "";
            if (rolesRepository.HasWriteAccessToThirdPartyUserCubaBookingAllowanceIndicator())
            {
                ViewData["ComplianceAdministratorAccess"] = "WriteAccess";
            }

            //GovernmentPseudoCityOrOfficeFlag
            //Only a user with the GDS Government Administrator role for Global can check or uncheck this box
            ViewData["GDSGovernmentAdministratorAccess"] = "";
            if (rolesRepository.HasWriteAccessToThirdPartyUserMilitaryAndGovernmentUserFlag())
            {
                ViewData["GDSGovernmentAdministratorAccess"] = "WriteAccess";
            }

            //ThirdPartyUserTypes
            thirdPartyUserVM.ThirdPartyUserTypes = new SelectList(thirdPartyUserTypeRepository.GetAllThirdPartyUserTypes().ToList(), "ThirdPartyUserTypeId", "ThirdPartyUserTypeName");

            //GDSThirdPartyVendors
            thirdPartyUserVM.GDSThirdPartyVendors = new SelectList(gdsThirdPartyVendorRepository.GetAllGDSThirdPartyVendors().ToList(), "GDSThirdPartyVendorId", "GDSThirdPartyVendorName");

            //StateProvinces
            thirdPartyUserVM.StateProvinces = new SelectList(stateProvinceRepository.GetStateProvincesByCountryCode(thirdPartyUser.CountryCode).ToList(), "StateProvinceCode", "Name");

            return(View(thirdPartyUserVM));
        }
        public async static ETTask LinkByAppleId(Player player, LinkInfo info, L2C_Link response)
        {
            string         appleId   = CryptographyHelper.AESDecrypt(info.Secret);
            ThirdPartyInfo appleInfo = new ThirdPartyInfo
            {
                id = appleId,
            };
            long           now            = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(appleInfo.id, UserDataHelper.tagAppleId);

            if (thirdPartyUser == null)
            {
                long uid  = player.uid;
                User user = await UserDataHelper.FindOneUser(uid);

                if (user == null)
                {
                    response.Error = ErrorCode.ERR_LinkFailed;
                    return;
                }

                // 綁定第三方-Apple
                thirdPartyUser          = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId());
                thirdPartyUser.uid      = user.Id;
                thirdPartyUser.party    = UserDataHelper.tagAppleId;
                thirdPartyUser.userId   = appleInfo.id;
                thirdPartyUser.gender   = appleInfo.gender;
                thirdPartyUser.location = appleInfo.location;
                thirdPartyUser.email    = appleInfo.email;
                thirdPartyUser.name     = appleInfo.name;
                thirdPartyUser.birthday = appleInfo.birthday;
                thirdPartyUser.createAt = now;
                await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser);

                // 取得新的第三方列表
                response.LinkTypes.Clear();
                response.LinkTypes.AddRange(await GetAllLinkType(user.Id));
            }
            else
            {
                response.Error = ErrorCode.ERR_LinkIsExist;
            }
        }
Example #17
0
        /// <summary>
        /// 使用帳號密碼註冊
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static async ETTask <int> SignUp(string email, string password, User.Identity identity = User.Identity.Player)
        {
            ThirdPartyUser thirdPartyUser = await FindOneThirdPartyUser(email, tagJPlay);

            if (thirdPartyUser != null)
            {
                return(ErrorCode.ERR_SignUpFailed);
            }
            else
            {
                long   now          = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                string salt         = CryptographyHelper.GenerateRandomId();
                string hashPassword = CryptographyHelper.MD5Encoding(password, salt);
                User   user         = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId());
                user.salt                          = salt;
                user.email                         = email;
                user.hashPassword                  = hashPassword;
                user.createAt                      = now;
                user.name                          = $"{user.Id}";
                user.playerCharSetting             = new PlayerCharSetting();
                user.playerCharSetting.CharacterId = 1L;
                user.playerRideTotalInfo           = new RideTotalInfo();
                user.identity                      = (int)identity;
                await SinUserUp(user);

                thirdPartyUser          = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId());
                thirdPartyUser.uid      = user.Id;
                thirdPartyUser.party    = tagJPlay;
                thirdPartyUser.userId   = user.email;
                thirdPartyUser.name     = "";
                thirdPartyUser.gender   = "";
                thirdPartyUser.location = "";
                thirdPartyUser.email    = email;
                thirdPartyUser.birthday = "";
                thirdPartyUser.createAt = now;
                await UpsertThirdPartyUser(thirdPartyUser);

                return(ErrorCode.ERR_Success);
            }
        }
        /// <summary>
        /// ¸öÈËÕ˺ÅÐÞ¸Ä
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <AccountModifyResponse> > AccountModify(string accountId, ThirdPartyUser request)
        {
            var result = await Http.PutAsync <
                AccountModifyResponse,
                ThirdPartyUser>(
                $"{Option.BaseUrl}/v1/accounts/{accountId}",
                request
                );

            return(result);
        }
Example #19
0
        /// <summary>
        /// 更新或插入一位第三方使用者
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static async ETTask UpsertThirdPartyUser(ThirdPartyUser user)
        {
            await dbProxy.Save(user);

            await dbProxy.SaveLog(user.Id, DBLog.LogType.BindThirdPartyUser, user);
        }
 public ThirdPartyUserVM(ThirdPartyUser thirdPartyUser)
 {
     ThirdPartyUser = thirdPartyUser;
 }
        /// <summary>
        /// 使用AppleID登入
        /// </summary>
        /// <param name="session"></param>
        /// <param name="info"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        public async static ETTask AuthenticationByAppleId(Session session, AuthenticationInfo info, R2C_Authentication response)
        {
            string         appleId   = CryptographyHelper.AESDecrypt(info.Secret);
            ThirdPartyInfo appleInfo = new ThirdPartyInfo
            {
                id = appleId,
            };
            long           now            = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(appleInfo.id, UserDataHelper.tagAppleId);

            User user = null;

            if (thirdPartyUser == null)
            {
                // 用AppleId註冊帳號
                user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId());
                string salt         = CryptographyHelper.GenerateRandomId();
                string password     = CryptographyHelper.GenerateRandomId(16);
                string hashPassword = CryptographyHelper.MD5Encoding(password, salt);
                user.salt                          = salt;
                user.hashPassword                  = hashPassword;
                user.email                         = appleInfo.email;
                user.name                          = user.Id.ToString();
                user.gender                        = appleInfo.genderCode;
                user.location                      = appleInfo.locationCode;
                user.birthday                      = appleInfo.birthdayCode;
                user.createAt                      = now;
                user.playerCharSetting             = new PlayerCharSetting();
                user.playerCharSetting.CharacterId = 1L;
                user.playerRideTotalInfo           = new RideTotalInfo();
                user.language                      = info.Language;
                user.identity                      = (int)User.Identity.Player;
                user.userBagCapacity               = EquipmentDataHelper.GetDefaultUserBag();
                await UserDataHelper.SinUserUp(user);

                // 註冊第三方-AppleId
                thirdPartyUser          = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId());
                thirdPartyUser.uid      = user.Id;
                thirdPartyUser.party    = UserDataHelper.tagAppleId;
                thirdPartyUser.userId   = appleInfo.id;
                thirdPartyUser.gender   = appleInfo.gender;
                thirdPartyUser.location = appleInfo.location;
                thirdPartyUser.email    = appleInfo.email;
                thirdPartyUser.name     = appleInfo.name;
                thirdPartyUser.birthday = appleInfo.birthday;
                thirdPartyUser.createAt = now;
                await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser);

                // 註冊第三方-Guest
                thirdPartyUser          = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId());
                thirdPartyUser.uid      = user.Id;
                thirdPartyUser.party    = UserDataHelper.tagGuest;
                thirdPartyUser.userId   = info.DeviceId;
                thirdPartyUser.name     = "";
                thirdPartyUser.gender   = "";
                thirdPartyUser.location = "";
                thirdPartyUser.email    = "";
                thirdPartyUser.birthday = "";
                thirdPartyUser.createAt = now;
                await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser);
            }
            else
            {
                user = await UserDataHelper.FindOneUser(thirdPartyUser.uid);
            }

            await SignInByUid(session, user, response, info.FirebaseDeviceToken, true, UserDataHelper.tagAppleId);
        }
        public async static ETTask AuthenticationByFaceBook(Session session, AuthenticationInfo info, R2C_Authentication response)
        {
            string fbToken      = info.Secret;
            bool   isValidToken = await FacebookHelper.ValidateFacebookToken(fbToken);

            if (!isValidToken)
            {
                response.Error = ErrorCode.ERR_FBSignInFailed;
                return;
            }
            ThirdPartyInfo fbInfo = await FacebookHelper.GetFacebookUserInfo(fbToken);

            if (fbInfo == null)
            {
                response.Error = ErrorCode.ERR_FBSignInFailed;
                return;
            }
            long           now            = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(fbInfo.id, UserDataHelper.tagFB);

            User user = null;

            if (thirdPartyUser == null)
            {
                // 用FB註冊帳號
                user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId());
                string salt         = CryptographyHelper.GenerateRandomId();
                string password     = CryptographyHelper.GenerateRandomId(16);
                string hashPassword = CryptographyHelper.MD5Encoding(password, salt);
                user.salt                          = salt;
                user.hashPassword                  = hashPassword;
                user.email                         = fbInfo.email;
                user.name                          = fbInfo.name;
                user.gender                        = fbInfo.genderCode;
                user.location                      = fbInfo.locationCode;
                user.birthday                      = fbInfo.birthdayCode;
                user.createAt                      = now;
                user.playerCharSetting             = new PlayerCharSetting();
                user.playerCharSetting.CharacterId = 1L;
                user.playerRideTotalInfo           = new RideTotalInfo();
                user.language                      = info.Language;
                user.identity                      = (int)User.Identity.Player;
                user.userBagCapacity               = EquipmentDataHelper.GetDefaultUserBag();
                await UserDataHelper.SinUserUp(user);

                //註冊第三方-FB
                thirdPartyUser          = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId());
                thirdPartyUser.uid      = user.Id;
                thirdPartyUser.party    = UserDataHelper.tagFB;
                thirdPartyUser.userId   = fbInfo.id;
                thirdPartyUser.gender   = fbInfo.gender;
                thirdPartyUser.location = fbInfo.location;
                thirdPartyUser.email    = fbInfo.email;
                thirdPartyUser.name     = fbInfo.name;
                thirdPartyUser.birthday = fbInfo.birthday;
                thirdPartyUser.createAt = now;
                await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser);

                //註冊第三方-Guest
                thirdPartyUser          = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId());
                thirdPartyUser.uid      = user.Id;
                thirdPartyUser.party    = UserDataHelper.tagGuest;
                thirdPartyUser.userId   = info.DeviceId;
                thirdPartyUser.name     = "";
                thirdPartyUser.gender   = "";
                thirdPartyUser.location = "";
                thirdPartyUser.email    = "";
                thirdPartyUser.birthday = "";
                thirdPartyUser.createAt = now;
                await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser);
            }
            else
            {
                user = await UserDataHelper.FindOneUser(thirdPartyUser.uid);
            }

            await SignInByUid(session, user, response, info.FirebaseDeviceToken, true, UserDataHelper.tagFB);
        }
        public async static ETTask AuthenticationByGuest(Session session, AuthenticationInfo info, R2C_Authentication response)
        {
            string deviceUniqueIdentifier = string.Empty;

            try
            {
                deviceUniqueIdentifier = CryptographyHelper.AESDecrypt(info.Secret);
            }
            catch (Exception)
            {
                response.Error = ErrorCode.ERR_InvalidDeviceUniqueIdentifier;
                return;
            }

            if (string.IsNullOrEmpty(deviceUniqueIdentifier))
            {
                response.Error = ErrorCode.ERR_DeviceUniqueIdentifierIsNull;
                return;
            }

            long           now            = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(deviceUniqueIdentifier, UserDataHelper.tagGuest);

            User user = null;

            if (thirdPartyUser == null)
            {
                user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId());
                string salt         = CryptographyHelper.GenerateRandomId();
                string password     = CryptographyHelper.GenerateRandomId(16);
                string hashPassword = CryptographyHelper.MD5Encoding(password, salt);
                user.salt                          = salt;
                user.hashPassword                  = hashPassword;
                user.createAt                      = now;
                user.name                          = $"{user.Id}";
                user.email                         = "";
                user.playerCharSetting             = new PlayerCharSetting();
                user.playerCharSetting.CharacterId = 1L;
                user.playerRideTotalInfo           = new RideTotalInfo();
                user.language                      = info.Language;
                user.identity                      = (int)User.Identity.Player;
                user.userBagCapacity               = EquipmentDataHelper.GetDefaultUserBag();
                await UserDataHelper.SinUserUp(user);

                //註冊第三方-Guest
                thirdPartyUser          = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId());
                thirdPartyUser.uid      = user.Id;
                thirdPartyUser.party    = UserDataHelper.tagGuest;
                thirdPartyUser.userId   = deviceUniqueIdentifier;
                thirdPartyUser.name     = "";
                thirdPartyUser.gender   = "";
                thirdPartyUser.location = "";
                thirdPartyUser.email    = "";
                thirdPartyUser.birthday = "";
                thirdPartyUser.createAt = now;
                await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser);
            }
            else
            {
                user = await UserDataHelper.FindOneUser(thirdPartyUser.uid);
            }

            await SignInByUid(session, user, response, info.FirebaseDeviceToken, true, UserDataHelper.tagGuest);
        }
Example #24
0
        /// <summary>
        /// 查询顾客
        /// </summary>
        /// <param name="queryCriteria"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public virtual DataTable Query(CustomerQueryFilter queryCriteria, out int totalCount)
        {
            totalCount = 0;
            var customCommand = DataCommandManager.CreateCustomDataCommandFromConfig("Customer_QueryExtend");

            PagingInfoEntity pagingInfo = new PagingInfoEntity();

            pagingInfo.SortField     = queryCriteria.PagingInfo.SortBy;
            pagingInfo.StartRowIndex = queryCriteria.PagingInfo.PageIndex * queryCriteria.PagingInfo.PageSize;
            pagingInfo.MaximumRows   = queryCriteria.PagingInfo.PageSize;

            using (DynamicQuerySqlBuilder sqlBuilder = new DynamicQuerySqlBuilder(customCommand.CommandText, customCommand,
                                                                                  pagingInfo,
                                                                                  "C.RegisterTime DESC"))
            {
                //设置查询条件参数
                AddParameterCustomerList(queryCriteria, customCommand, sqlBuilder);
                EnumColumnList enumColumnList = new EnumColumnList();
                enumColumnList.Add(2, typeof(CustomerStatus));
                enumColumnList.Add(4, typeof(Gender));
                enumColumnList.Add(14, typeof(YNStatus));
                enumColumnList.Add(17, typeof(CustomerRank));
                enumColumnList.Add(19, typeof(VIPRank));
                enumColumnList.Add(30, typeof(CustomerType));
                enumColumnList.Add(31, typeof(YNStatus));
                enumColumnList.Add(34, typeof(YNStatus));
                enumColumnList.Add(36, typeof(AvtarShowStatus));
                DataTable dt = customCommand.ExecuteDataTable(enumColumnList);
                totalCount = int.Parse(customCommand.GetParameterValue("@TotalCount").ToString());

                List <CustomerInfo>   aList             = customCommand.ExecuteEntityList <CustomerInfo>();
                List <int?>           customerSysNoList = aList.Select(p => p.SysNo).ToList();
                List <ThirdPartyUser> thirdPartUserList = GetThirdPartyUserInfo(customerSysNoList);
                if (thirdPartUserList.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        for (int j = 0; j < thirdPartUserList.Count; j++)
                        {
                            if (int.Parse(dt.Rows[i]["SysNo"].ToString()) == thirdPartUserList[j].CustomerSysNo)
                            {
                                ThirdPartyUser thirdPartyUser = thirdPartUserList.FirstOrDefault(p => p.CustomerSysNo == int.Parse(dt.Rows[i]["SysNo"].ToString()));
                                if (thirdPartyUser != null && thirdPartyUser.SubSource != null)
                                {
                                    if (thirdPartyUser.UserSource == "支付宝" && (thirdPartyUser.SubSource.ToUpper() == "VIP" || thirdPartyUser.SubSource.ToUpper() == "IMPERIAL_VIP"))
                                    {
                                        dt.Rows[i]["CustomerID"] = string.Format("{0}\r\n【{1}】", dt.Rows[i]["CustomerID"].ToString(), "金帐户");
                                    }
                                }
                            }
                        }
                    }
                }
                return(dt);
            }
            #region 中蛋逻辑(“金帐户”显示)

            /****
             * (第三方用户(表ThirdPartyUser)来源(字段UserSource)为“支付宝”、“VIP”、“IMPERIAL_VIP”,需要在CustomerID后面用红色显示“金帐户”
             * 原有程序如下,启用时需修改****/


            //aList = CustomerDA.GetCustomerList(queryEntity);
            //List<ThirdPartyUser> thirdPartUserList = GetThirdPartyUserInfo(customerSysNoList);
            //if (thirdPartUserList.Count > 0)
            //{
            //    aList.ForEach( current=>
            //    {
            //        ThirdPartyUser thirdPartyUser = thirdPartUserList.FirstOrDefault(p => p.CustomerSysNo == current.SystemNumber);
            //        if (thirdPartyUser != null && thirdPartyUser.SubSource != null)
            //        {
            //            current.CustomerIDWithAlipayVipIndentity
            //            if (thirdPartyUser.UserSource == "支付宝" && (thirdPartyUser.SubSource.ToUpper() == "VIP" || thirdPartyUser.SubSource.ToUpper() == "IMPERIAL_VIP"))
            //            {
            //                current.CustomerIDWithAlipayVipIndentity = string.Format("{0}{1}",current.CustomerID,"金帐户");
            //                current.CustomerID = string.Format("{0}<br><font color='red'>【{1}】</font>", current.CustomerID, "金帐户");
            //            }
            //        }
            //    });
            //}
            #endregion
        }
        // GET: /Edit
        public ActionResult Edit(int id, int thirdPartyUserId)
        {
            //Set Access Rights
            ViewData["Access"] = "";
            if (rolesRepository.HasWriteAccessToThirdPartyGDSAccessRights(thirdPartyUserId))
            {
                ViewData["Access"] = "WriteAccess";
            }

            ThirdPartyUserGDSAccessRight thirdPartyUserGDSAccessRight = thirdPartyUserGDSAccessRightRepository.GetThirdPartyUserGDSAccessRight(id);

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

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

            ThirdPartyUserGDSAccessRightVM thirdPartyUserGDSAccessRightVM = new ThirdPartyUserGDSAccessRightVM();

            thirdPartyUserGDSAccessRightVM.ThirdPartyUserGDSAccessRight = thirdPartyUserGDSAccessRight;

            //GDS
            thirdPartyUserGDSAccessRightVM.GDSs = new SelectList(gdsRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName", thirdPartyUserGDSAccessRight.GDSCode);

            //GDSAccessTypes
            thirdPartyUserGDSAccessRightVM.GDSAccessTypes = new SelectList(gdsAccessTypeRepository.GetGDSAccessTypesByGDSCode(thirdPartyUserGDSAccessRight.GDSCode).ToList(), "GDSAccessTypeId", "GDSAccessTypeName", thirdPartyUserGDSAccessRight.GDSAccessTypeId);

            //PseudoCityOrOfficeIds
            thirdPartyUserGDSAccessRightVM.PseudoCityOrOfficeIds = new SelectList(
                thirdPartyUserRepository.GetThirdPartyUserPseudoCityOrOfficeIdsByGDSCode(thirdPartyUserGDSAccessRight.GDSCode, thirdPartyUserGDSAccessRight.ThirdPartyUserId).ToList(),
                "PseudoCityOrOfficeId",
                "PseudoCityOrOfficeId",
                thirdPartyUserGDSAccessRight.PseudoCityOrOfficeId
                );

            //ThirdPartyUser
            ThirdPartyUser thirdPartyUser = new ThirdPartyUser();

            thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(thirdPartyUserGDSAccessRight.ThirdPartyUserId);
            if (thirdPartyUser != null)
            {
                thirdPartyUserRepository.EditForDisplay(thirdPartyUser);
                thirdPartyUserGDSAccessRightVM.ThirdPartyUser = thirdPartyUser;
            }

            //Entitlements (All but this one)
            if (thirdPartyUser.ThirdPartyUserGDSAccessRights != null && thirdPartyUser.ThirdPartyUserGDSAccessRights.Count() > 0)
            {
                List <Entitlement> entitlements = new List <Entitlement>();
                foreach (ThirdPartyUserGDSAccessRight item in thirdPartyUser.ThirdPartyUserGDSAccessRights.Where(x => x.ThirdPartyUserGDSAccessRightId != thirdPartyUserGDSAccessRight.ThirdPartyUserGDSAccessRightId))
                {
                    Entitlement entitlement = new Entitlement()
                    {
                        tpAgentID        = item.GDSSignOnID,
                        tpPCC            = item.PseudoCityOrOfficeId,
                        tpServiceID      = item.GDS.GDSName,
                        DeletedFlag      = item.DeletedFlag == true ? true : false,
                        DeletedTimestamp = item.DeletedDateTime
                    };
                    entitlements.Add(entitlement);
                }
                thirdPartyUserGDSAccessRightVM.Entitlements = entitlements;
            }

            return(View(thirdPartyUserGDSAccessRightVM));
        }
        //Export Items to CSV
        public byte[] Export(
            string filterField_1 = "",
            string filterValue_1 = "",
            string filterField_2 = "",
            string filterValue_2 = "",
            string filterField_3 = "",
            string filterValue_3 = ""
            )
        {
            StringBuilder sb = new StringBuilder();

            //Add Headers
            List <string> headers = new List <string>();

            headers.Add("Third Party User ID");
            headers.Add("Third Party Name");
            headers.Add("Last Name");
            headers.Add("First Name");
            headers.Add("Email");
            headers.Add("Is Active Flag");
            headers.Add("Cuba Booking Allowance Indicator");
            headers.Add("Military and Government User");
            headers.Add("Robotic User Flag");
            headers.Add("CWT Manager");
            headers.Add("User Type");
            headers.Add("Client SubUnit Name");
            headers.Add("Client SubUnit Guid");
            headers.Add("Partner Name");
            headers.Add("Vendor Name");
            headers.Add("First Address line");
            headers.Add("Second Address line");
            headers.Add("Postal Code");
            headers.Add("State/Province");
            headers.Add("Country");
            headers.Add("Phone Number");
            headers.Add("Internal Remarks");
            headers.Add("Deleted Flag");
            headers.Add("Deleted Date Time");
            headers.Add("Creation Time Stamp");
            headers.Add("Creation User Identifier");
            headers.Add("LastUpdate TimeStamp");
            headers.Add("LastUpdate UserIdentifier");

            sb.AppendLine(String.Join(",", headers.Select(x => x.ToString()).ToArray()));

            //Add Items
            List <ThirdPartyUserExport> thirdPartyUsers = GetThirdPartyUserExports(
                filterField_1,
                filterValue_1,
                filterField_2,
                filterValue_2,
                filterField_3,
                filterValue_3
                );

            foreach (ThirdPartyUserExport item in thirdPartyUsers)
            {
                string date_format = "MM/dd/yy HH:mm";

                EditForDisplay(item);

                //ThirdPartyUserInternalRemarks
                StringBuilder  remarksList    = new StringBuilder();
                ThirdPartyUser thirdPartyUser = GetThirdPartyUser(item.ThirdPartyUserId);
                if (thirdPartyUser.ThirdPartyUserInternalRemarks != null && thirdPartyUser.ThirdPartyUserInternalRemarks.Count > 0)
                {
                    foreach (ThirdPartyUserInternalRemark thirdPartyUserInternalRemark in thirdPartyUser.ThirdPartyUserInternalRemarks)
                    {
                        remarksList.AppendFormat("{0} - {1}; ", thirdPartyUserInternalRemark.CreationTimestamp.Value.ToString(date_format), thirdPartyUserInternalRemark.InternalRemark);
                    }
                }

                sb.AppendFormat(
                    "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27}",
                    !string.IsNullOrEmpty(item.TISUserId) ? item.TISUserId : " ",
                    !string.IsNullOrEmpty(item.ThirdPartyName) ? item.ThirdPartyName : " ",
                    !string.IsNullOrEmpty(item.LastName) ? item.LastName : " ",
                    !string.IsNullOrEmpty(item.FirstName) ? item.FirstName : " ",
                    !string.IsNullOrEmpty(item.Email) ? item.Email : " ",
                    item.IsActiveFlag == true ? "True" : "False",
                    item.CubaBookingAllowanceIndicator == true ? "True" : "False",
                    item.MilitaryAndGovernmentUserFlag == true ? "True" : "False",
                    item.RoboticUserFlag == true ? "True" : "False",
                    !string.IsNullOrEmpty(item.CWTManager) ? item.CWTManager : " ",
                    !string.IsNullOrEmpty(item.ThirdPartyUserTypeName) ? item.ThirdPartyUserTypeName : " ",
                    !string.IsNullOrEmpty(item.ClientSubUnitName) ? item.ClientSubUnitName : " ",
                    !string.IsNullOrEmpty(item.ClientSubUnitGuid) ? item.ClientSubUnitGuid : " ",
                    !string.IsNullOrEmpty(item.PartnerName) ? item.PartnerName : " ",
                    !string.IsNullOrEmpty(item.GDSThirdPartyVendorName) ? item.GDSThirdPartyVendorName : " ",
                    !string.IsNullOrEmpty(item.FirstAddressLine) ? item.FirstAddressLine : " ",
                    !string.IsNullOrEmpty(item.SecondAddressLine) ? item.SecondAddressLine : " ",
                    !string.IsNullOrEmpty(item.PostalCode) ? item.PostalCode : " ",
                    !string.IsNullOrEmpty(item.StateProvinceCode) ? item.StateProvinceCode : " ",
                    !string.IsNullOrEmpty(item.CountryName) ? item.CountryName : " ",
                    !string.IsNullOrEmpty(item.Phone) ? item.Phone : " ",
                    remarksList != null && !string.IsNullOrEmpty(remarksList.ToString()) ? string.Format("\"{0}\"", remarksList) : " ",
                    item.DeletedFlag == true ? "True" : "False",
                    item.DeletedDateTime.HasValue ? item.DeletedDateTime.Value.ToString(date_format) : " ",
                    item.CreationTimeStamp.HasValue ? item.CreationTimeStamp.Value.ToString(date_format) : " ",
                    !string.IsNullOrEmpty(item.CreationUserIdentifier) ? item.CreationUserIdentifier : " ",
                    item.LastUpdateTimeStamp.HasValue ? item.LastUpdateTimeStamp.Value.ToString(date_format) : " ",
                    !string.IsNullOrEmpty(item.LastUpdateUserIdentifier) ? item.LastUpdateUserIdentifier : " "
                    );

                sb.Append(Environment.NewLine);
            }

            return(Encoding.ASCII.GetBytes(sb.ToString()));
        }
        public ActionResult Edit(ThirdPartyUserVM thirdPartyUserVM)
        {
            //Set Access Rights
            RolesRepository rolesRepository = new RolesRepository();

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

            //Only a user with the correct roles can change these options
            if (!rolesRepository.HasWriteAccessToThirdPartyUserCubaBookingAllowanceIndicator() || !rolesRepository.HasWriteAccessToThirdPartyUserMilitaryAndGovernmentUserFlag())
            {
                ThirdPartyUser thirdPartyUser = new ThirdPartyUser();
                thirdPartyUser = thirdPartyUserRepository.GetThirdPartyUser(thirdPartyUserVM.ThirdPartyUser.ThirdPartyUserId);

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

                thirdPartyUserRepository.EditForDisplay(thirdPartyUser);

                //CubaPseudoCityOrOfficeFlag
                //Only a user with the Compliance Administrator for Global can check or uncheck this box
                if (!rolesRepository.HasWriteAccessToThirdPartyUserCubaBookingAllowanceIndicator())
                {
                    thirdPartyUserVM.ThirdPartyUser.CubaBookingAllowanceIndicatorNonNullable = thirdPartyUser.CubaBookingAllowanceIndicatorNonNullable;
                }

                //GovernmentPseudoCityOrOfficeFlag
                //Only a user with the GDS Government Administrator role for Global can check or uncheck this box
                if (!rolesRepository.HasWriteAccessToThirdPartyUserMilitaryAndGovernmentUserFlag())
                {
                    thirdPartyUserVM.ThirdPartyUser.MilitaryAndGovernmentUserFlagNonNullable = thirdPartyUser.MilitaryAndGovernmentUserFlagNonNullable;
                }
            }

            //Update  Model from Form
            try
            {
                TryUpdateModel <ThirdPartyUser>(thirdPartyUserVM.ThirdPartyUser, "ThirdPartyUser");
            }
            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
            {
                thirdPartyUserRepository.Update(thirdPartyUserVM);
            }
            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"));
            }

            string redirectAction = (thirdPartyUserVM.ThirdPartyUser.DeletedFlag == true) ? "ListDeleted" : "ListUnDeleted";

            return(RedirectToAction(redirectAction));
        }