public IActionResult Update(string id, UpdateDeviceModel model)
        {
            var entity = _service.Devices.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(new AppResultBuilder().NotFound()));
            }
            var validationResult = _service.ValidateUpdateDevice(User, entity, model);

            if (!validationResult.Valid)
            {
                return(BadRequest(validationResult.Result));
            }
            _service.UpdateDevice(entity, model);
            context.SaveChanges();
            return(NoContent());
        }
Example #2
0
        public void Handle(PayloadMessage message)
        {
            try
            {
                if (message.Value == null || message.Value == "null")
                {
                    LogResult.Report(Log, "log_ForInfo", "Kafka Message is Null");
                    return;
                }

                string s = message.Value;

                if (CreateDeviceEvent != null && CreateDeviceEvent.ActionUTC != null)
                {
                    if (CreateDeviceEvent.ActionUTC.ToString() != null && message.Value.Contains(CreateDeviceEvent.ActionUTC.ToString("yyyy-MM-ddThh:mm:ss")) && message.Value.Contains(CreateDeviceEvent.ReceivedUTC.ToString()) &&
                        CreateDeviceEvent.DeviceUID.ToString() != null && message.Value.Contains(CreateDeviceEvent.DeviceUID.ToString()))
                    {
                        deviceServiceCreateResponse = JsonConvert.DeserializeObject <CreateDeviceModel>(message.Value);
                    }
                    LogResult.Report(Log, "log_ForInfo", string.Format("Response Received With Offset {0}: {1}", message.OffSet, message.Value));

                    if (UpdateDeviceEvent != null && UpdateDeviceEvent.ActionUTC != null && UpdateDeviceEvent.DeviceUID != Guid.Empty)
                    {
                        if (UpdateDeviceEvent.ActionUTC.ToString() != null && message.Value.Contains(UpdateDeviceEvent.ActionUTC.ToString("yyyy-MM-ddThh:mm:ss")) && message.Value.Contains(UpdateDeviceEvent.ReceivedUTC.ToString()) &&
                            UpdateDeviceEvent.DeviceUID.ToString() != null && message.Value.Contains(UpdateDeviceEvent.DeviceUID.ToString()))
                        {
                            deviceServiceUpdateResponse = JsonConvert.DeserializeObject <UpdateDeviceModel>(message.Value);
                        }
                        LogResult.Report(Log, "log_ForInfo", string.Format("Response Received With Offset {0}: {1}", message.OffSet, message.Value));
                    }
                }
            }
            catch (Exception e)
            {
                LogResult.Report(Log, "log_ForError", "Got Error While Handling Response", e);
                throw new Exception(e + "Got Error While Handling Response");
            }
        }
Example #3
0
 public ValidationResult ValidateUpdateDevice(ClaimsPrincipal principal,
                                              Device entity, UpdateDeviceModel model)
 {
     return(ValidationResult.Pass());
 }
Example #4
0
 public void UpdateDevice(Device entity, UpdateDeviceModel model)
 {
     model.CopyTo(entity);
 }