public IActionResult AddCity([FromBody] CityAddModel cityAddModel) //[FromBody] -- { if (cityAddModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_store.Cities.FirstOrDefault(x => cityAddModel.Name == x.Name) != null) { return(Conflict()); } int id = _store.GetNextId(); City city = cityAddModel.ToCity(id); _store.Cities.Add(city); return(CreatedAtRoute("GetCity", new { id }, city)); }
public async Task <bool> Add(CityAddModel model) { _repository.Create(new City { Name = model.Name }); await _repository.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Add([FromBody] CityAddModel model) { return(await MakeActionCallAsync(async() => await _cityService.Add(model))); }