Exemple #1
0
        public async Task <IResponseModel <CampaignCreateResponse> > Handle(CampaignCreateCommand request,
                                                                            CancellationToken cancellationToken)
        {
            // TODO: Logs
            var fromBuilding = await _buildingQueryService.FindAsync(request.FromIdBuilding);

            var toBuilding = await _buildingQueryService.FindAsync(request.ToIdBuilding);

            if (fromBuilding.City != toBuilding.City)
            {
                return(new BadRequestResponse <CampaignCreateResponse>("The buildings must be in the same city."));
            }

            if (fromBuilding.Street != toBuilding.Street)
            {
                return(new BadRequestResponse <CampaignCreateResponse>("The buildings must be on the same street."));
            }

            if (toBuilding.StreetNumber % 2 == 0 != (fromBuilding.StreetNumber % 2 == 0))
            {
                return(new BadRequestResponse <CampaignCreateResponse>(
                           "The buildings must be on the same side of the road."));
            }

            if (fromBuilding.StreetNumber > toBuilding.StreetNumber)
            {
                return(new BadRequestResponse <CampaignCreateResponse>(
                           "FromIdBuilding must have smaller street number than ToIdBuilding."));
            }

            if (fromBuilding.StreetNumber == toBuilding.StreetNumber)
            {
                return(new BadRequestResponse <CampaignCreateResponse>(
                           "The buildings must have different street number."));
            }

            var buildings = _buildingQueryService.GetAll(fromBuilding.City, fromBuilding.Street,
                                                         fromBuilding.IdBuilding, toBuilding.IdBuilding,
                                                         toBuilding.StreetNumber % 2 == 0);

            var calculation =
                await _bannerCalculateService.CalculateAsync(buildings.ToList(), request.PricePerSquareMeter);

            if (calculation == null)
            {
                return(new InternalError <CampaignCreateResponse>("The calculation task could not be completed."));
            }

            var result = await _campaignCreateService.CreateAsync(request, calculation);

            if (result == null)
            {
                return(new InternalError <CampaignCreateResponse>("The campaign could not be created."));
            }

            return(new SuccessResponse <CampaignCreateResponse>("Campaign has been created.", calculation));
        }
        public async Task <IResponseModel <BuildingResponse> > Handle(BuildingGetQuery request,
                                                                      CancellationToken cancellationToken)
        {
            var building = await _buildingQueryService.FindAsync(request.BuildingId);

            if (building == null)
            {
                return(new NotFoundResponse <BuildingResponse>("No buildings could be found with this id"));
            }

            return(new SuccessResponse <BuildingResponse>(_mapper.Map <BuildingResponse>(building)));
        }