コード例 #1
0
            public async Task <CreateApartmentAdOutputModel> Handle(
                CreateApartmentAdCommand request,
                CancellationToken cancellationToken)
            {
                var userId = currentUser.UserId;
                var broker = await brokerRepository.FindByUser(userId, cancellationToken);

                var category = await apartmentAdRepository.GetCategory(request.Category, cancellationToken);

                var neighborhood = await apartmentAdRepository.GetNeighborhood(request.Neighborhood, cancellationToken);

                var factory = neighborhood == null
                    ? apartmentAdFactory.WithNeighborhood(request.Neighborhood)
                    : apartmentAdFactory.WithNeighborhood(neighborhood);

                var ApartmentAd = factory
                                  .WithFloor(request.Floor)
                                  .WithCategory(category)
                                  .WithImageUrl(request.ImageUrl)
                                  .WithPricePerMonth(request.PricePerMonth)
                                  .WithOptions(
                    request.HasParking,
                    request.HasBasement,
                    Enumeration.FromValue <HeatingType>(request.HeatingType))
                                  .Build();

                broker.AddApartmentAd(ApartmentAd);

                await apartmentAdRepository.Save(ApartmentAd, cancellationToken);

                return(new CreateApartmentAdOutputModel(ApartmentAd.Id));
            }