public async Task <IList <Branch> > GetAllBranches()
        {
            var current = Connectivity.NetworkAccess;

            if (current == NetworkAccess.Internet)
            {
                // Connection to internet is available
                await _syncService.SyncRemoteBranchesAsync();
            }

            var allBranches = await _branchRepository.ReadAllAsync();

            if (current != NetworkAccess.Internet)
            {
                return(allBranches);
            }

            var federatedUserName = AuthService.CurrentUser.FederatedUserName;
            var homeBranch        = await BranchSecurityClient.GetUserHomeBranch(federatedUserName);

            // ReSharper disable once ConvertIfStatementToReturnStatement
            if (homeBranch?.ToLower().Equals(Config.CorporateSalesBranchId) == true)
            {
                return(allBranches);
            }

#if DEBUG
            return(allBranches);
#endif

            var allowedBranches = await BranchSecurityClient.GetAllUserBranches(federatedUserName);

            return(allBranches.Where(branch => allowedBranches.Contains(branch.BranchId)).ToList());
        }
Beispiel #2
0
        /// <summary>
        ///     This method sets the Branch Id, it should only be called if there is no branch Id set already.
        /// </summary>
        /// <returns>An asynchronous Task. </returns>
        public async Task SetDefaultBranch()
        {
            try
            {
                var federatedUserName = AuthService.CurrentUser.FederatedUserName;
                var homeBranch        = await BranchSecurityClient.GetUserHomeBranch(federatedUserName).ConfigureAwait(false);

                if (homeBranch == null)
                {
                    homeBranch = (await BranchSecurityClient.GetAllUserBranches(federatedUserName).ConfigureAwait(false))?.First();
                }
                if (homeBranch != null)
                {
                    _configurationService.SetString(Config.BranchId, homeBranch);
                    await TrySyncWithCrescoAndAzure().ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                ex.Report();
            }
        }