Beispiel #1
0
        public Entity.ActionStatus Manage(Entity.NotificationAddRequest request)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
            var _list = new List <string>();

            try
            {
                if (request.Guid == null || request.Guid == Guid.Empty)
                {
                    var addRuleResult = _iotConnectClient.Rule.Add(Mapper.Configuration.Mapper.Map <IOT.AddRuleModel>(request)).Result;

                    if (addRuleResult != null && !addRuleResult.status)
                    {
                        _logger.Error($"Notification is not added in iotconnect, Error: {addRuleResult.message}");
                        actionStatus.Success = false;
                        actionStatus.Message = addRuleResult.errorMessages[0].Message;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(addRuleResult.data.ruleGuid))
                        {
                            actionStatus.Data = Get(Guid.Parse(addRuleResult.data.ruleGuid.ToUpper()));
                        }
                    }
                }
                else
                {
                    var updateRuleResult = _iotConnectClient.Rule.Update(request.Guid.ToString(), Mapper.Configuration.Mapper.Map <IOT.UpdateRuleModel>(request)).Result;
                    if (updateRuleResult != null && !updateRuleResult.status)
                    {
                        _logger.Error($"Notification is not updated in iotconnect, Error: {updateRuleResult.message}");
                        actionStatus.Success = false;
                        actionStatus.Message = updateRuleResult.errorMessages[0].Message;
                    }
                    else
                    {
                        actionStatus.Data = Get(request.Guid.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(Constants.ACTION_EXCEPTION, "NotificationService.Manage " + ex);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }
Beispiel #2
0
 public Entity.BaseResponse <Entity.SingleRuleResponse> Manage(Entity.NotificationAddRequest request)
 {
     Entity.BaseResponse <Entity.SingleRuleResponse> response = new Entity.BaseResponse <Entity.SingleRuleResponse>(true);
     try
     {
         var status = _service.Manage(request);
         response.IsSuccess = status.Success;
         response.Message   = status.Message;
         response.Data      = status.Data;
     }
     catch (Exception ex)
     {
         return(new Entity.BaseResponse <Entity.SingleRuleResponse>(false, ex.Message));
     }
     return(response);
 }
Beispiel #3
0
        public Entity.ActionStatus Manage(Entity.NotificationAddRequest request)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
            var _list = new List <string>();

            try
            {
                if (request.Guid == null || request.Guid == Guid.Empty)
                {
                    var addRuleResult = _iotConnectClient.Rule.Add(Mapper.Configuration.Mapper.Map <IOT.AddRuleModel>(request)).Result;

                    if (addRuleResult != null && !addRuleResult.status)
                    {
                        _logger.ErrorLog(new Exception($"Notification is not added in iotconnect, Error: {addRuleResult.message}")
                                         , this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                        actionStatus.Success = false;
                        actionStatus.Message = new UtilityHelper().IOTResultMessage(addRuleResult.errorMessages);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(addRuleResult.data.ruleGuid))
                        {
                            actionStatus.Data = Get(Guid.Parse(addRuleResult.data.ruleGuid.ToUpper()));
                        }
                    }
                }
                else
                {
                    IOT.DataResponse <IOT.SingleRuleResult> singleRule = _iotConnectClient.Rule.Single(request.Guid.ToString()).Result;
                    if (singleRule.data == null)
                    {
                        _logger.ErrorLog(new Exception($"Notification is not added in iotconnect, Error: {singleRule.message}")
                                         , this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                        actionStatus.Success = false;
                        actionStatus.Message = singleRule.errorMessages[0].Message;
                    }
                    else
                    {
                        request.IsActive = singleRule.data.isActive;
                        var updateRuleResult = _iotConnectClient.Rule.Update(request.Guid.ToString(), Mapper.Configuration.Mapper.Map <IOT.UpdateRuleModel>(request)).Result;
                        if (updateRuleResult != null && !updateRuleResult.status)
                        {
                            _logger.ErrorLog(new Exception($"Notification is not updated in iotconnect, Error: {updateRuleResult.message}")
                                             , this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                            actionStatus.Success = false;
                            actionStatus.Message = new UtilityHelper().IOTResultMessage(updateRuleResult.errorMessages);
                        }
                        else
                        {
                            actionStatus.Data = Get(request.Guid.Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }