Beispiel #1
0
        public async Task <List <OfferDto> > GetAllOffersForAgent(OfferListFilter filter)
        {
            var agent = await _authenticationService.GetCurrentUserAsync();

            var offers = await GetFilteredOffersForAgent(filter, agent.Id) ?? throw new NotFoundException("Offers");

            var offerDtos = new List <OfferDto>();

            foreach (var offer in offers)
            {
                var offerDto = _mapper.Map <OfferDto>(offer);
                var answers  = await _unitOfWork.Repository <Answer>().GetAllAsync(a => a.OfferId == offer.Id);

                if (answers != null)
                {
                    foreach (var answer in answers)
                    {
                        var answerDto = _mapper.Map <AnswerDto>(answer);
                        offerDto.Answers.Add(answerDto);
                    }
                }
                offerDtos.Add(offerDto);
            }
            return(offerDtos);
        }
Beispiel #2
0
        public async Task <List <OfferDto> > GetPropertyOffers(int id, OfferListFilter offerFilter)
        {
            var user = await _authentication.GetCurrentUserAsync();

            var propepty = await _unitOfWork.Repository <Property>().GetAsync(p => p.Id == id) ?? throw new NotFoundException("Property");

            if (propepty.UserId != user.Id)
            {
                throw new FieldAccessException();
            }

            var offers = await GetFilteredOffersForUser(offerFilter, id);

            var offerDtos = new List <OfferDto>();

            foreach (var offer in offers)
            {
                var agent = await _unitOfWork.Repository <User>().GetAsync(a => a.Id == offer.AgentProfileId);

                var offerDto = _mapper.Map <OfferDto>(offer);
                offerDto.Image          = agent.ImagePath;
                offerDto.FirstName      = agent.FirstName;
                offerDto.LastName       = agent.LastName;
                offerDto.AgentProfileId = agent.Id;
                var answers = await _unitOfWork.Repository <Answer>().GetAllAsync(a => a.OfferId == offer.Id);

                foreach (var answer in answers)
                {
                    var answerDto = _mapper.Map <AnswerDto>(answer);
                    offerDto.Answers.Add(answerDto);
                }
                offerDtos.Add(offerDto);
            }
            return(offerDtos);
        }
Beispiel #3
0
        private async Task <List <Offer> > GetFilteredOffersForUser(OfferListFilter filter, int propertyId)
        {
            var offers = await _unitOfWork.Repository <Offer>().GetAllAsync(o => o.PropertyId == propertyId);

            if (filter.OfferStatus != null)
            {
                offers = offers.Where(p => p.Status == filter.OfferStatus);
            }

            return(await offers.Skip(filter.Skip).Take(filter.Take).ToListAsync());
        }
Beispiel #4
0
        public async Task <IActionResult> GetOffersForAgent([FromQuery] OfferListFilter filter)
        {
            var offers = await _offerService.GetAllOffersForAgent(filter);

            var offersVm = new List <OfferViewModel>();

            foreach (var offer in offers)
            {
                var offerVm = _mapper.Map <OfferViewModel>(offer);
                offersVm.Add(offerVm);
            }
            return(Ok(offersVm));
        }
Beispiel #5
0
        private async Task <List <Offer> > GetFilteredOffersForAgent(OfferListFilter filter, string agentId)
        {
            var offers = await _unitOfWork.Repository <Offer>().GetAllAsync();

            if (filter.OfferStatus != null && agentId != null)
            {
                offers = await _unitOfWork.Repository <Offer>().GetAllAsync(p => p.Status == filter.OfferStatus && p.AgentProfileId == agentId);
            }

            else if (agentId != null)
            {
                offers = await _unitOfWork.Repository <Offer>().GetAllAsync(o => o.AgentProfileId == agentId);
            }

            return(await offers.Skip(filter.Skip).Take(filter.Take).ToListAsync());
        }
        public async Task <IActionResult> GetOffersForProperty(int id, [FromQuery] OfferListFilter listFilter)
        {
            var offers = await _propertyService.GetPropertyOffers(id, listFilter);

            return(Ok(offers));
        }