public IEnumerable <Apartment> GetBetterApartments(ApartmentSpecsDto apartmentSpecs)
        {
            var apartmentsByPhysicalSpecs = SelectApartmentsByPhysicalsSpecs(apartmentSpecs);
            var betterApartments          = SelectApartmentsByPriceSpecs(apartmentsByPhysicalSpecs, apartmentSpecs);

            return(betterApartments);
        }
Ejemplo n.º 2
0
        private Mock <ApartmentRepository> MockApartmentRepository(ApartmentSpecsDto apartmentSpecsDto, IEnumerable <Apartment> apartmentsByPhysicalSpecs)
        {
            var apartmentRepositoryMock = new Mock <ApartmentRepository>(null);

            apartmentRepositoryMock
            .Setup(repository => repository.GetApartments(apartmentSpecsDto))
            .Returns(apartmentsByPhysicalSpecs);

            return(apartmentRepositoryMock);
        }
        public virtual IEnumerable <Apartment> GetApartments(ApartmentSpecsDto apartmentSpecs)
        {
            var apartments = _applicationContext.Apartments
                             .Where(apartment => apartmentSpecs.City == apartment.Complex.CityName)
                             .Where(apartment => apartmentSpecs.NumberOfRooms == apartment.NumberOfRooms)
                             .Where(apartment => apartmentSpecs.HasMultipleFloors == apartment.HasMultipleFloors)
                             .Where(apartment => (apartmentSpecs.DwellingSpace >= apartment.DwellingSpaceMin &&
                                                  apartmentSpecs.DwellingSpace <= apartment.DwellingSpaceMax));

            return(apartments);
        }
        public IActionResult ProposeBetterApartments(ApartmentSpecsDto apartmentSpecs)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var betterApartments = _realEstateService
                                   .GetBetterApartments(apartmentSpecs)
                                   .Select(apartment => _mapper.Map <ApartmentDto>(apartment));

            return(Ok(betterApartments));
        }
        private IEnumerable <Apartment> SelectApartmentsByPriceSpecs(IEnumerable <Apartment> comparableApartments, ApartmentSpecsDto apartmentSpecs)
        {
            try
            {
                int generalRenovationPrice = apartmentSpecs.DwellingSpace * apartmentSpecs.RenovationPricePerMeter;

                var apartments = comparableApartments
                                 .Where(delegate(Apartment apartment)
                {
                    var apartPriceWithoutRenovation = CalculateApartmentPrice(apartment, apartmentSpecs.DwellingSpace);
                    var apartPriceWithRenovation    = apartPriceWithoutRenovation + generalRenovationPrice;

                    var isItProfitable = apartPriceWithRenovation < apartmentSpecs.OverallPrice;
                    return(isItProfitable);
                });

                return(apartments);
            }
            catch (Exception ex)
            {
                // Log
            }

            return(null);
        }
 private IEnumerable <Apartment> SelectApartmentsByPhysicalsSpecs(ApartmentSpecsDto apartmentSpecs)
 {
     return(_apartmentRepository.GetApartments(apartmentSpecs));
 }