コード例 #1
0
        public async Task <ResultListDto> GetBranchesBaseOnRoleAsync(BranchFilterDto branchFilterDto)
        {
            List <int>    branchList    = new List <int>();
            ResultListDto resultListDto = new ResultListDto();

            var userRoles = await _userService.GetUserRolesAsync(branchFilterDto.UserBranchDto.BranchId, branchFilterDto.UserBranchDto.UserId);

            foreach (var item in userRoles)
            {
                if (item.RoleId == ConstRoles.Admin)
                {
                    var branchFilter = _mapper.Map <BranchFilter>(branchFilterDto);
                    var resultdto    = await _branchService.GetBranchesAsync(branchFilter);

                    resultListDto = _mapper.Map <ResultListDto>(resultdto);
                    return(resultListDto);
                }
                else if (item.RoleId == ConstRoles.User)
                {
                    var branches = await _branchService.GetUserBranches(branchFilterDto.UserBranchDto.UserId);

                    resultListDto.Results = branches;
                    return(resultListDto);
                }
                else if (item.RoleId == ConstRoles.SuperViser)
                {
                    var branch = await _branchService.GetBranchAsync(branchFilterDto.UserBranchDto.BranchId);

                    var zone = await _zoneService.GetZoneInfoByZoneIDAsync(branch.ZoneID);

                    resultListDto.Results = await _zoneService.GetProvinceBranchesByProvinceCode(zone.OSTANCode);

                    return(resultListDto);
                }
                //else if (item.RoleId == ConstRoles.Customer)
                //{
                //    //var customer = await _customerAppService.GetCustomerByUserIDAsync(branchFilterDto.UserBranchDto.UserId);
                //    //((DepositFilterDto)branchFilterDto).CustomerHeadSerial = customer.Serial;
                //}
                //else
                //{
                //    branchList.Add(branchFilterDto.UserBranchDto.BranchId);
                //    return branchList;
                //}
            }
            resultListDto.Results = await _branchService.GetBranchAsync(branchFilterDto.UserBranchDto.BranchId);

            resultListDto.ServerErrors = null;
            return(resultListDto);
        }