public void Update(Zone zone) { var zoneToUpdate = GetZoneById(zone.Id); if (zoneToUpdate == null) { throw new InvalidDataException("There is no such zone to update."); } var mapRectangleToUpdate = _mapRectanglesRepository.GetByZoneId(zoneToUpdate.Id); if (mapRectangleToUpdate == null) { throw new InvalidDataException("Can't find zone's map rectangle."); } zoneToUpdate.Name = zone.Name; mapRectangleToUpdate.TopLeftLatitude = zone.MapRectangle.TopLeftLatitude; mapRectangleToUpdate.TopLeftLongitude = zone.MapRectangle.TopLeftLongitude; mapRectangleToUpdate.BottomRightLatitude = zone.MapRectangle.BottomRightLatitude; mapRectangleToUpdate.BottomRightLongitude = zone.MapRectangle.BottomRightLongitude; _zoneRepository.Update(zoneToUpdate); _mapRectanglesRepository.Update(mapRectangleToUpdate); }
public async Task <IActionResult> ExecuteAsync(int zoneId, SaveZone saveZone, CancellationToken cancellationToken) { var zone = await zoneRepository.Get(zoneId, cancellationToken); if (zone == null) { return(new NotFoundResult()); } saveZoneToZoneMapper.Map(saveZone, zone); // add created by //var user = _httpContextAccessor.HttpContext.User; //if (user == null) // return new NotFoundResult(); //var claims = user.Claims.ToList(); //if (claims.Count < 1) // return new NotFoundResult(); //var userId = claims.FirstOrDefault(claimRecord => claimRecord.Type == "sub").Value; //zone.ModifiedBy = userId; // end created by zone = await zoneRepository.Update(zone, cancellationToken); var zoneViewModel = zoneToZoneMapper.Map(zone); return(new OkObjectResult(zoneViewModel)); }
public void UpdateZone(UpdateZoneInput input) { var zone = _zoneRepository.Get(input.Id); zone.ZoneCode = input.ZoneCode; zone.ZoneName = input.ZoneName; _zoneRepository.Update(zone); }
public ZoneDto UpdateZone(UpdateZoneCommand cmd) { var zone = zoneRepository.Find(cmd.Id); if (zone == null) { throw new ArgumentException($"A zone with id '{cmd.Id}' does not exist"); } zone.ChangeName(cmd.Name); zone.ChangeDescription(cmd.Description); zone.SetNewChannel(controlService, cmd.Channel); zone.SetEnablement(controlService, cmd.IsEnabled); zoneRepository.Update(zone); return(new ZoneDto(zone.Id, zone.Name, zone.Description, zone.Channel, zone.IsEnabled, controlService.IsStarted(zone.Channel))); }
public async Task <IActionResult> ExecuteAsync( int zoneId, JsonPatchDocument <SaveZone> patch, CancellationToken cancellationToken) { var zone = await zoneRepository.Get(zoneId, cancellationToken); if (zone == null) { return(new NotFoundResult()); } var saveZone = zoneToSaveZoneMapper.Map(zone); var modelState = actionContextAccessor.ActionContext.ModelState; patch.ApplyTo(saveZone, modelState); objectModelValidator.Validate( actionContextAccessor.ActionContext, validationState: null, prefix: null, model: saveZone); if (!modelState.IsValid) { return(new BadRequestObjectResult(modelState)); } saveZoneToZoneMapper.Map(saveZone, zone); await zoneRepository.Update(zone, cancellationToken); var zoneViewModel = zoneToZoneMapper.Map(zone); return(new OkObjectResult(zoneViewModel)); }
public DtoZoneListItem EditZone(DtoZoneListItem zone) { var edited = zoneRepository.Update(DtoZoneToZone(zone)); return(ZoneToDtoZone(edited)); }