Exemplo n.º 1
0
        public async Task <ActionResult> RealEstates()
        {
            string userId = HttpContext.User.Identity.GetUserId();
            await _realtorService.SetInitialData(userId);

            ChoosenSearchParametersForRealtorView searchParameters = new ChoosenSearchParametersForRealtorView();
            DataAboutRealEstatesForRealtorView    dataForRealtor   = await PreparedDataAboutRealEstates(searchParameters);

            return(View(dataForRealtor));
        }
Exemplo n.º 2
0
        private async Task <DataAboutRealEstatesForRealtorView> PreparedRealEstates(ChoosenSearchParametrsForRealtorView choosenSearchParameters)
        {
            ChoosenSearchParametersForRealtorDTO choosenSearchParametersDTO = _mapper.Map <ChoosenSearchParametrsForRealtorView, ChoosenSearchParametersForRealtorDTO>
                                                                                  (choosenSearchParameters);
            string userId = HttpContext.User.Identity.GetUserId();
            var    users  = await _identityService.GetUsers().ProjectTo <UserViewModel>(_mapper.ConfigurationProvider).ToListAsync();

            List <RealEstateForRealtorDTO> realEstatesDTO = await _realtorService.GetRealEstatesForRealtor(userId, choosenSearchParametersDTO)
                                                            .Skip((choosenSearchParameters.Page - 1) * _pageSize)
                                                            .Take(_pageSize).ToListAsync();

            List <RealEstateForRealtorView> realEstates =
                _mapper.Map <List <RealEstateForRealtorDTO>, List <RealEstateForRealtorView> >(realEstatesDTO);

            realEstates = realEstates.Join(users, r => r.RealtorId, u => u.Id, (r, u) =>
            {
                r.RealtorName  = u.Name;
                r.RealtorEmail = u.Email;
                return(r);
            }).ToList();

            DataAboutRealEstatesForRealtorView dataForRealtor = new DataAboutRealEstatesForRealtorView
            {
                ChoosenSearchParametersForRealtor = choosenSearchParameters,
                RealEstates      = realEstates,
                SearchParameters = _mapper.Map <DataForSearchParametersDTO, DataForSearchParametersRealtorView>(await _realtorService.InitiateSearchParameters()),
                PagingInfo       = new PagingInfo
                {
                    CurrentPage  = choosenSearchParameters.Page,
                    ItemsPerPage = _pageSize,
                    TotalItems   = await _realtorService.GetRealEstatesForRealtor(userId, choosenSearchParametersDTO).CountAsync()
                }
            };

            return(dataForRealtor);
        }