public ICompany Find(IUser user)
        {
            if (string.IsNullOrEmpty(user?.Username))
            {
                return(null);
            }

            var response = Service.Execute(s => s.queryAccountByUsername(user.Username));

            if (!response.IsSuccess())
            {
                return(null);
            }

            var companyType    = CompanyType.SiteLicenseIP;
            var companyAccount = response.accounts.FirstOrDefault(a => CompanyTypeParser.Parse(a.accountType) == companyType);

            if (companyAccount == null)
            {
                return(null);
            }

            return(new SalesforceCompany
            {
                Id = companyAccount.accountId,
                Name = companyAccount.company,
                Type = companyType
            });
        }
Example #2
0
        public IMasterCompany Find(string masterid, string masterPassword)
        {
            var response = Service.Execute(s => s.queryAccountByMasterId(masterid, masterPassword));

            if (!response.IsSuccess())
            {
                if (response.errors.Any(e => string.Equals(e.statusCode, "EXPIRED_MASTERID", StringComparison.InvariantCultureIgnoreCase)))
                {
                    return(new SalesforceMasterCompany
                    {
                        IsExpired = true
                    });
                }

                return(null);
            }

            var account = response.account;

            return(new SalesforceMasterCompany
            {
                Id = account?.accountId,
                Name = account?.company,
                Type = CompanyTypeParser.Parse(account?.accountType),
                IsExpired = response.isMasterIdExpiredSpecified && response.isMasterIdExpired != null ? response.isMasterIdExpired.Value : false
            });
        }