Ejemplo n.º 1
0
        public async Task <ActionResult> Put(int id, AddCitiesDto addCitiesDto)
        {
            var city = await _projectRepository.GetCityByIdAsync(id);

            // country = _mapper.Map<Countries>(addCountryDto);
            var updatecity = _mapper.Map <UpdateCitiesDto>(addCitiesDto);

            _mapper.Map(updatecity, city);
            // await _projectRepository.SaveAllAsync();

            if (await _projectRepository.SaveAllAsync())
            {
                return(NoContent());
            }

            throw new Exception($"Updating user {id} failed on save");
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Cities> > AddCity(AddCitiesDto addCitiesDto)
        {
            var country = await _projectRepository.GetCountryByIdAsync(addCitiesDto.CountryId);

            var newcity = _mapper.Map <Cities>(addCitiesDto);

            newcity.Country = country;
            _projectRepository.Add(newcity);

            if (await _projectRepository.SaveAllAsync())
            {
                var messageToReturn = _mapper.Map <AddCitiesDto>(newcity);
                return(CreatedAtRoute("GetCity",
                                      new { cityid = newcity.Id }, newcity));
            }
            throw new Exception("Creating the City failed on save");
        }