예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        public void UpdateZone(UpdateZoneInput input)
        {
            var zone = _zoneRepository.Get(input.Id);

            zone.ZoneCode = input.ZoneCode;
            zone.ZoneName = input.ZoneName;

            _zoneRepository.Update(zone);
        }
예제 #4
0
        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)));
        }
예제 #5
0
        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));
        }
예제 #6
0
        public DtoZoneListItem EditZone(DtoZoneListItem zone)
        {
            var edited = zoneRepository.Update(DtoZoneToZone(zone));

            return(ZoneToDtoZone(edited));
        }