Example #1
0
        public void DeleteDeviceRegistration(string id)
        {
            Models.DeviceRegistration deviceRegistration = GetDeviceRegistration(id);
            if (deviceRegistration == null)
            {
                return;
            }

            _context.DevicesRegistration.Remove(deviceRegistration);
            _context.SaveChanges();
            _log.Log($"Dispositivo {deviceRegistration.Name} foi removido.");
        }
Example #2
0
        public Models.DeviceRegistration Put(string id, [FromBody] Models.DeviceRegistration deviceRegistration)
        {
            if (deviceRegistration == null)
            {
                throw new Box.Common.BoxLogicException("Dispositivo inválido.");
            }

            if (id != deviceRegistration.DeviceCustomUId)
            {
                throw new Box.Common.BoxLogicException("Id inválido.");
            }

            return(this._sgiService.SaveDeviceRegistration(deviceRegistration));
        }
Example #3
0
        public Models.DeviceRegistration Post([FromBody] Models.DeviceRegistration deviceRegistration)
        {
            if (deviceRegistration == null)
            {
                throw new Box.Common.BoxLogicException("Dispositivo inválido.");
            }

            if (!this._sgiService.CanRegisterDevice(deviceRegistration.DeviceId))
            {
                throw new Box.Common.BoxLogicException("Dispositivo já cadastrado.");
            }

            deviceRegistration.DeviceCustomUId = Guid.NewGuid().ToString();
            return(this._sgiService.SaveDeviceRegistration(deviceRegistration));
        }
Example #4
0
        public Models.DeviceRegistration SaveDeviceRegistration(Models.DeviceRegistration deviceRegistration)
        {
            Models.DeviceRegistration oldDeviceRegistration = GetDeviceRegistration(deviceRegistration.DeviceCustomUId);

            if (oldDeviceRegistration == null)
            {
                if (!CanRegisterDevice(deviceRegistration.DeviceId))
                {
                    throw new Box.Common.BoxLogicException("Dispositivo já cadastrado.");
                }

                _context.Entry <Models.DeviceRegistration>(deviceRegistration).State = EntityState.Added;
            }
            else
            {
                _context.DevicesRegistration.Attach(oldDeviceRegistration);
                _context.Entry <Models.DeviceRegistration>(oldDeviceRegistration).CurrentValues.SetValues(deviceRegistration);
            }

            _context.SaveChanges(true);
            _log.Log($"Dispositivo {deviceRegistration.Name} foi criado/alterado.");

            return(deviceRegistration);
        }