Beispiel #1
0
        public async Task <IActionResult> Put([FromBody] CityDTO cityData)
        {
            try
            {
                var city = await _repository.GetByIdAsync((int)cityData.Id);

                if (city == null)
                {
                    return(NotFound(_errorHandler.JsonErrorMessage((int)HttpStatusCode.NotFound)));
                }
                if (ModelState.IsValid)
                {
                    var updatedcity = _mapper.Map <CityDTO, City>(cityData, city);
                    updatedcity.ModifiedDate = DateTimeOffset.UtcNow;
                    await _repository.UpdateAsync(updatedcity);

                    return(Ok(CityDTO.FromCity(updatedcity)));
                }
                return(Json(ModelState));
            }
            catch (Exception ex)
            {
                return(BadRequest(_errorHandler.JsonErrorMessage((int)HttpStatusCode.BadRequest, ex.Message)));
            }
        }
        public async Task <CityDTO> FindById(Guid id)
        {
            var entity = await CityRepository.FindById(id);

            return(CityDTO.FromCity(entity));
        }
 public async Task <List <CityDTO> > FindAll()
 {
     return((await CityRepository.FindAll())
            .Select(x => CityDTO.FromCity(x))
            .ToList());
 }