Пример #1
0
        public async Task <ResultListDto> GetBranchesAsync(BranchFilterDto branchFilterDto)
        {
            if (branchFilterDto != null && branchFilterDto.UserBranchDto != null)
            {
                UserBranches userBranches = new UserBranches();
                userBranches = _mapper.Map <UserBranches>(branchFilterDto.UserBranchDto);
                if (branchFilterDto.Branches == null || branchFilterDto.Branches.Count == 0)
                {
                    branchFilterDto.Branches = await _branchService.GetBranchesForFiltersAsync(userBranches);
                }
            }
            var branchFilter = _mapper.Map <BranchFilter>(branchFilterDto);

            var branchList = await _branchService.GetBranchesAsync(branchFilter);

            var branchDtoList = _mapper.Map <IEnumerable <BranchDto> >(branchList.Results);

            ResultListDto finalResult = new ResultListDto()
            {
                MaxPageRows = branchList.MaxPageRows,
                TotalRows   = branchList.TotalRows,
                Results     = branchDtoList
            };

            return(finalResult);
        }
        public async Task <ResultListDto> GetUsersAsync(UserFilterDto userFilterDto)
        {
            var userBranch = _mapper.Map <UserBranches>(userFilterDto.UserBranchDto);

            if (userFilterDto.Branches == null || userFilterDto.Branches.Count == 0)
            {
                userFilterDto.Branches = await _branchService.GetBranchesForFiltersAsync(userBranch);
            }

            var userFilter = _mapper.Map <UserFilter>(userFilterDto);
            var userList   = await _userService.GetUsersAsync(userFilter);

            var           userDtoList = _mapper.Map <IEnumerable <UserDto> >(userList.Results);
            ResultListDto finalResult = new ResultListDto()
            {
                MaxPageRows = userList.MaxPageRows,
                TotalRows   = userList.TotalRows,
                Results     = userDtoList
            };

            return(finalResult);
        }
        public async Task <ResultListDto> GetCustomersByFilterAsync(CustomerFilterDto customerFilterDto)
        {
            var userBranches = _mapper.Map <UserBranches>(customerFilterDto.UserBranchDto);

            if (customerFilterDto.Branches == null || customerFilterDto.Branches.Count == 0)
            {
                customerFilterDto.Branches = await _branchService.GetBranchesForFiltersAsync(userBranches);
            }

            var customerFilter = _mapper.Map <CustomerFilter>(customerFilterDto);
            var customerList   = await _customerService.GetCustomersByFilterAsync(customerFilter);

            var customerDtoList = _mapper.Map <List <CustomerHeadDto> >(customerList.Results);

            customerDtoList.ForEach(x =>
            {
                x.CustomerDetails.ForEach(d =>
                {
                    if (d.CustomerDetailTypeID == ConstCustomerDetailsTypes.Mobile)
                    {
                        x.MobileCustomerDetail = d;
                    }

                    if (d.CustomerDetailTypeID == ConstCustomerDetailsTypes.HomePhone)
                    {
                        x.HomePhoneCustomerDetail = d;
                    }

                    if (d.CustomerDetailTypeID == ConstCustomerDetailsTypes.HomeAddress)
                    {
                        x.HomeAddressCustomerDetail = d;
                    }

                    if (d.CustomerDetailTypeID == ConstCustomerDetailsTypes.WorkPhone)
                    {
                        x.WorkPhoneCustomerDetail = d;
                    }

                    if (d.CustomerDetailTypeID == ConstCustomerDetailsTypes.WorkAddress)
                    {
                        x.WorkAddressCustomerDetail = d;
                    }

                    //if (d.CustomerDetailTypeID == ConstCustomerDetailsTypes.CertificateImage)
                    //    x.CertificateImageCustomerDetail = d;

                    //if (d.CustomerDetailTypeID == ConstCustomerDetailsTypes.PersonalImage)
                    //    x.PersonalImageCustomerDetail = d;

                    //if (d.CustomerDetailTypeID == ConstCustomerDetailsTypes.SignatureImage)
                    //    x.SignatureImageCustomerDetail = d;
                });

                x.CustomerDetails = new List <CustomerDetailDto>();
            });

            foreach (var item in customerDtoList)
            {
                foreach (var item2 in item.CustomerSkills)
                {
                    item.Skills.Add(item2.SkillID);
                }
            }

            ResultListDto finalResult = new ResultListDto()
            {
                MaxPageRows = customerList.MaxPageRows,
                TotalRows   = customerList.TotalRows,
                Results     = customerDtoList
            };

            return(finalResult);
        }