Exemplo n.º 1
0
        public Entity.ActionStatus Manage(Entity.Rule request)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
            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($"Rule is not added in iotconnect, Error: {addRuleResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                        actionStatus.Success = false;
                        actionStatus.Message = "Something Went Wrong!";
                    }
                    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.ErrorLog(new Exception($"Rule is not added in iotconnect, Error: {updateRuleResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                        actionStatus.Success = false;
                        actionStatus.Message = "Something Went Wrong!";
                    }
                    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);
        }
        public Entity.BaseResponse <Entity.SingleRuleResponse> Manage([FromBody] Entity.Rule request)
        {
            if (request == null)
            {
                return(new Entity.BaseResponse <Entity.SingleRuleResponse>(false, "Invalid 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);
        }