public IActionResult UpdateCity(int id, [FromBody] UpdateCityModel updateCityModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (updateCityModel == null) { return(BadRequest()); } var city = _dataStore.Cities.Where(c => c.Id == id).FirstOrDefault(); if (city == null) { return(NotFound()); } city.Name = updateCityModel.Name; city.Description = updateCityModel.Description; city.NumberOfPoi = updateCityModel.NumberOfPoi; _dataStore.Cities.Remove(city); _dataStore.Cities.Add(city); return(Ok(city)); }
public IActionResult PatchCity(int id, [FromBody] UpdateCityModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (model == null) { return(BadRequest()); } City city = _dataStore.Cities.Where(c => c.Id == id).FirstOrDefault(); if (city == null) { return(NotFound()); } var updateCityModel = new UpdateCityModel(city.Name, city.Description, city.NumberOfPoi); JsonPatchDocument <UpdateCityModel> patchCityDoc = new JsonPatchDocument <UpdateCityModel>(); if (model.ReplaceName == true) { patchCityDoc.Replace(x => x.Name, model.Name); } if (model.ReplaceDescription == true) { patchCityDoc.Replace(x => x.Description, model.Description); } if (model.ReplaceNumberOfPoi == true) { patchCityDoc.Replace(x => x.NumberOfPoi, model.NumberOfPoi); } patchCityDoc.ApplyTo(updateCityModel); if (city.Name != updateCityModel.Name) { city.Name = updateCityModel.Name; } if (city.Description != updateCityModel.Description) { city.Description = updateCityModel.Description; } if (city.NumberOfPoi != updateCityModel.NumberOfPoi) { city.NumberOfPoi = updateCityModel.NumberOfPoi; } _dataStore.Cities.Remove(city); _dataStore.Cities.Add(city); return(Ok(city)); }
public async Task <CityModel> Put(int id, [FromBody] UpdateCityModel requestModel) { var item = await _query.Update(id, requestModel); var model = _mapper.Map <CityModel>(item); return(model); }
public async Task <City> Update(UpdateCityModel model) { try { City city = await this.cities.UpdateAsync(model.Id, model.NewName); return(city); } catch (Exception e) { this.LogError(e); return(null); } }
public async Task <IActionResult> UpdateCity([FromRoute] Guid id, [FromBody] UpdateCityModel updateCityModel) { var city = await _cityService.GetByIdAsync(id).ConfigureAwait(false); if (city == null) { return(NotFound()); } var entity = _mapper.Map <CityEntity>(updateCityModel); entity.Id = id; await _cityService.UpdateAsync(entity).ConfigureAwait(false); return(NoContent()); }
public async Task <City> Update(int id, UpdateCityModel model) { var item = GetQuery().FirstOrDefault(x => x.Id == id); if (item == null) { throw new NotFoundException("City is not found"); } item.Name = model.Name; item.Sort = model.Sort; await _uow.CommitAsync(); return(item); }
public IActionResult UpdateCity(int id, [FromBody] UpdateCityModel updateCityModel) { if (updateCityModel == null) { return(BadRequest()); } City city = _dataStore .Cities .FirstOrDefault(c => c.Id == id); //лямбда, в которой параметро id сравнивается с id в Cities, и выбирает первый попавшийся if (city == null) { return(NotFound()); } city.Name = updateCityModel.Name; city.Description = updateCityModel.Description; city.NumberOfPoi = updateCityModel.NumberOfPoi; return(NoContent()); }
public IActionResult PatchCity(int id, [FromBody] JsonPatchDocument <UpdateCityModel> patchCityDoc) { if (patchCityDoc == null) { return(BadRequest()); } City city = _dataStore.Cities.Where(c => c.Id == id).FirstOrDefault(); if (city == null) { return(NotFound()); } var updateCityModel = new UpdateCityModel(city.Name, city.Description, city.NumberOfPoi); patchCityDoc.ApplyTo(updateCityModel); //ToDo: reflect changes from model back to data if (city.Name != updateCityModel.Name) { city.Name = updateCityModel.Name; } if (city.Description != updateCityModel.Description) { city.Description = updateCityModel.Description; } if (city.NumberOfPoi != updateCityModel.NumberOfPoi) { city.NumberOfPoi = updateCityModel.NumberOfPoi; } _dataStore.Cities.Add(city); return(Ok()); }
public ActionResult Add(UpdateCityModel model, int id = 0) { if (ModelState.IsValid) { var r = YunClient.Instance.Execute(new AddCityRequest { Ext = model.Ext, Name = model.Name, ParentId = model.ParentId, Sort = model.Sort, State = model.State }, Token); if (r.Result > 0) { TempData["success"] = "已成功添加"; return(RedirectToAction("Index")); } TempData["error"] = "添加失败,错误代码:" + r.ErrMsg; } return(View(model)); }
public async Task <Unit> UpdateCity([FromRoute] int id, [FromBody] UpdateCityModel request) => await _mediator.Send(new UpdateCityCommand { Id = id, Name = request.Name });