public ActionResult <ZoneDto> UpdateZone(int zoneId, ZoneForUpdateDto zone) { if (zone.Name == zone.Description) { ModelState.AddModelError("Description", "Description must be different from Name."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var zoneFromRepo = _croudSeekRepository.GetZone(zoneId); if (zoneFromRepo == null) { return(NotFound()); } _mapper.Map(zone, zoneFromRepo); _croudSeekRepository.UpdateZone(zoneFromRepo); _croudSeekRepository.Save(); return(NoContent()); }
public IActionResult UpdateZone(int systemId, int zoneId, [FromBody] ZoneForUpdateDto zone) { var system = _unitOfWork.IrigationSystemRepository.ExistIrigationSystem(systemId); if (!system) { return(NotFound("Irrigation system not found")); } var updateZone = _unitOfWork.ZoneRepository.GetZoneBySystem(systemId, zoneId); if (updateZone == null) { return(NotFound("Zone for update not found")); } updateZone.MoistureStart = zone.MoistureStart; updateZone.MoistureStop = zone.MoistureStop; updateZone.WaterSwitch = zone.WaterSwitch; var zoneForUpdate = _mapper.Map <Zone>(updateZone); _unitOfWork.ZoneRepository.Update(zoneForUpdate); if (!_unitOfWork.Save()) { return(StatusCode(500, "A problem happened with handling your request. Try again!")); } return(NoContent()); }
public async Task UpdateZone(ZoneForUpdateDto zone, int zoneId) { var json = JsonSerializer.Serialize(zone); var zoneJson = new StringContent(json, Encoding.Unicode, "application/json"); var result = await _httpClient.PutAsync($"api/zones/{zoneId}", zoneJson); }