public IActionResult AddCity([FromBody] AddCityModel addCityModel) { if (addCityModel == null) { return(BadRequest()); } if (_dataStore.Cities.FirstOrDefault(c => c.Name == addCityModel.Name) != null) { return(Conflict("The city with name specified already exists")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int newId = _dataStore.GetNewId(); var city = new City(newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); _dataStore.Cities.Add(city); var getCityModel = new GetCityModel(newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); return(CreatedAtAction("GetCity", new { id = newId }, getCityModel)); } //добавить город
public IActionResult AddCity([FromBody] AddCityModel addCityModel) { if (addCityModel == null) { return(BadRequest()); } int newId = _dataStore.GetNewId(); var city = new City( newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); _dataStore.Cities.Add(city); var getCityModel = new GetCityModel( newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); return(CreatedAtAction( "GetCity", new { id = newId }, getCityModel)); }
public ActionResult AddCity(int id) { var model = new AddCityModel() { CountyId = id }; return(View(model)); }
public ActionResult AddCity(AddCityModel model) { if (ModelState.IsValid) { var newCity = new City() { IdCounty = model.CountyId, Name = model.Name, }; Services.LocalitiesService.AddCity(newCity); } return(RedirectToAction("EditCounty", new { id = model.CountyId })); }
public IActionResult AddCity([FromBody] AddCityModel addCityModel) { _logger.LogInformation($"{nameof(AddCity)}, {nameof(addCityModel)} called"); if (addCityModel == null) { return(BadRequest()); } if (_dataStore.Cities.FirstOrDefault(c => c.Name == addCityModel.Name) != null) { return(Conflict("The city with name specified already exists")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); //передаем в badrequest ошибку } int newId = _dataStore.GetNewId(); var city = new City( newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); _dataStore.Cities.Add(city); var getCityModel = new GetCityModel( newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); return(CreatedAtAction( "GetCity", new { id = newId }, getCityModel)); }
public async Task <IActionResult> Post(AddCityModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (model.CommandId == Guid.Empty) { model.CommandId = NewId.NextGuid(); } var command = new AddCityCommand(model); await Send(command); return(Accepted(new PostResult <AddCityCommand>() { CommandId = model.Id, Timestamp = command.Timestamp })); }
public AddCityCommand(AddCityModel model) { _model = model; Timestamp = DateTime.UtcNow; }