Exemplo n.º 1
0
        public async Task UserResponse(int id, OfferResponseDto response)
        {
            var offer = await _unitOfWork.Repository <Offer>().GetAsync(o => o.Id == id) ?? throw new NotFoundException("Offer");

            var user = await _authenticationService.GetCurrentUserAsync();

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

            var agent = await _unitOfWork.Repository <AgentProfile>().GetAsync(a => a.Id == offer.AgentProfileId) ?? throw new NotFoundException("Agent");

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

            offer.Status         = response.Response;
            offer.UpdatedById    = user.Id;
            offer.UpdatedDateUtc = DateTime.Now;

            if (offer.Status == (int)OfferStatus.Confirmed)
            {
                property.Status = (int)PropertyStatus.FoundAgent;
                await _unitOfWork.Repository <Property>().UpdateAsync(property);
            }

            if (offer.Status == (int)OfferStatus.Failed)
            {
                property.Status = (int)PropertyStatus.LookingForAgent;
                await _unitOfWork.Repository <Property>().UpdateAsync(property);

                agent.FailedSales++;
            }

            if (offer.Status == (int)OfferStatus.Sold)
            {
                property.Status = (int)PropertyStatus.Sold;
                await _unitOfWork.Repository <Property>().UpdateAsync(property);

                agent.SuccessSales++;
            }

            await _unitOfWork.Repository <Offer>().UpdateAsync(offer);

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public IActionResult SendResponse([FromBody] OfferResponseDto offerResponse)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var sendStatus = offerService.SendResponseToOffer(offerResponse).Status;

            switch (sendStatus)
            {
            case SendOfferResponseStatus.Ok:
                return(NoContent());

            default:
                return(StatusCode(500));
            }
        }
Exemplo n.º 3
0
        // Przesyła odpowiedź administratora do oferty sprzedaży książki.
        public StatusResult <SendOfferResponseStatus> SendResponseToOffer(OfferResponseDto response)
        {
            var offer = context.Offers
                        .Include(x => x.OfferResponse)
                        .SingleOrDefault(x => x.Id == response.OfferId);

            if (offer == null)
            {
                return(new StatusResult <SendOfferResponseStatus>
                {
                    Status = SendOfferResponseStatus.NoOffer
                });
            }

            if (offer.OfferResponse != null)
            {
                return(new StatusResult <SendOfferResponseStatus>
                {
                    Status = SendOfferResponseStatus.OfferHasResponse
                });
            }

            var newOfferStatusId = context.OfferStatuses.Single(x => x.Id == 2).Id;

            offer.OfferStatusId = newOfferStatusId;

            var toAdd = new OfferResponse
            {
                ResponseDate          = System.DateTime.Now,
                ResponseText          = response.ResponseText,
                ProposedPrice         = response.ProposedPrice,
                OfferResponseStatusId = response.OfferResponseStatusId,
            };

            context.OfferResponses.Add(toAdd);
            offer.OfferResponseId = toAdd.Id;

            context.SaveChanges();

            return(new StatusResult <SendOfferResponseStatus>
            {
                Status = SendOfferResponseStatus.Ok
            });
        }