Пример #1
0
        public async Task <IActionResult> CreateTourist(int hotelId, TouristForUpdateDto touristForUpdateDto)
        {
            if (touristForUpdateDto == null)
            {
                return(BadRequest());
            }

            var touristEntity = _mapper.Map <Tourist>(touristForUpdateDto);

            touristEntity.HotelId = hotelId;

            _hotelrepo.Add(touristEntity);

            if (await _unitOfWork.CompleteAsync())
            {
                var touristToReturn = _mapper.Map <TouristForUpdateDto>(touristEntity);
                return(CreatedAtRoute("GetTourist", new { id = touristToReturn.Id }, touristToReturn));
            }

            throw new Exception("Creating the torist guide failed on save");
        }
Пример #2
0
        public async Task <IActionResult> UpdateTourist(int id, [FromBody] TouristForUpdateDto touristForUpdateDto)
        {
            if (touristForUpdateDto == null)
            {
                return(BadRequest());
            }

            var touristFromRepo = await _hotelrepo.GetTourist(id);

            if (touristFromRepo == null)
            {
                return(NotFound($"Could not find tourist guide with an ID of {id}"));
            }

            _mapper.Map <TouristForUpdateDto, Tourist>(touristForUpdateDto, touristFromRepo);

            if (await _unitOfWork.CompleteAsync())
            {
                return(NoContent());
            }

            throw new Exception($"Updating tourist guide {id} failed on save");
        }