public async Task <IActionResult> Get(int id)
        {
            try
            {
                var house = await _houseRepository.GetByIdAsync(id);

                if (house == null)
                {
                    return(NotFound());
                }

                return(Ok(new HouseConverter().Convert(house)));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Example #2
0
        public async Task <House.Models.House> Handle(HouseQueryCommand request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(request.HouseId))
            {
                return(null);
            }

            return(await _houseRepository.GetByIdAsync(request.HouseId));
        }
Example #3
0
        public async Task Handle(HouseTradedEvent notification, CancellationToken cancellationToken)
        {
            House.Models.House house = await _houseRepository.GetByIdAsync(notification.HouseId);

            if (house != null)
            {
                house.TradeTo(notification.BuyerId);
                _houseRepository.Update(house);
                await _unitOfWork.CommitAsync();
            }
        }
Example #4
0
        public async Task <Result> UpdateNameAsync(string houseId, string name)
        {
            if (string.IsNullOrEmpty(houseId))
            {
                throw new ArgumentNullException(nameof(houseId));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            Models.House house = await _houseRepository.GetByIdAsync(houseId);

            if (house == null)
            {
                return(Result.Fail("Production not exist."));
            }

            house.UpdateName(name);
            _houseRepository.Update(house);

            return(Result.Success());
        }
Example #5
0
        [HttpGet("{id}")] //api/house/id
        public async Task <House> GetHouse(string id)

        {
            return(await _houseRepository.GetByIdAsync(id));
        }
Example #6
0
        public async Task <HouseDto> GetHouseAsync(string houseId)
        {
            House house = await _houseRepository.GetByIdAsync(houseId);

            return(_mapper.Map <HouseDto>(house));
        }
        public async Task <HouseToUpdate> GetByIdAsync(int id)
        {
            var entity = await _repository.GetByIdAsync(id);

            return(_mapper.Map <HouseToUpdate>(entity));
        }