Esempio n. 1
0
        /// <summary>
        /// Create new entity.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <DataResponse <AddEntityResult> > Add(AddEntityModel request)
        {
            try
            {
                var errorList = Helper.ValidateObject(request);
                if (errorList?.Count > 0)
                {
                    return(new DataResponse <AddEntityResult>(null)
                    {
                        errorMessages = errorList,
                        message = "Data Error",
                        status = false
                    });
                }
                var portalApi = await _ioTConnectAPIDiscovery.GetPortalUrl(_envCode, _solutionKey, IoTConnectBaseURLType.UserBaseUrl);

                string accessTokenUrl = string.Concat(portalApi, EntityApi.Add);
                string formattedUrl   = String.Format(accessTokenUrl, Constants.entityVersion);
                var    addEntity      = await formattedUrl.WithHeaders(new { Content_type = Constants.contentType, Authorization = Constants.bearerTokenType + _token })
                                        .PostJsonAsync(request).ReceiveJson <DataResponse <List <AddEntityResult> > >();

                return(new DataResponse <AddEntityResult>(null)
                {
                    data = addEntity.data.FirstOrDefault(),
                    message = addEntity.message,
                    status = true
                });
            }
            catch (IoTConnectException ex)
            {
                List <ErrorItemModel> errorItemModels = new List <ErrorItemModel>();
                errorItemModels.AddRange(ex.error);
                return(new DataResponse <AddEntityResult>(null)
                {
                    errorMessages = errorItemModels,
                    message = ex.message,
                    status = false
                });
            }
            catch (Exception ex)
            {
                await _ioTConnectAPIDiscovery.LoggedException(_envCode, ex, "Entity", "Add()");

                throw ex;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get All IotConnnect Country.
        /// </summary>
        /// <returns></returns>
        public async Task <DataResponse <List <Conuntry> > > Countries()
        {
            try
            {
                var portalApi = await _ioTConnectAPIDiscovery.GetPortalUrl(_envCode, _solutionKey, IoTConnectBaseURLType.MasterBaseUrl);

                string accessTokenUrl = string.Concat(portalApi, MasterApi.Country);
                string formattedUrl   = String.Format(accessTokenUrl, Constants.masterVersion);
                return(await formattedUrl.WithHeaders(new { Content_type = Constants.contentType, Authorization = Constants.bearerTokenType + _token })
                       .GetJsonAsync <DataResponse <List <Conuntry> > >());
            }
            catch (IoTConnectException ex)
            {
                List <ErrorItemModel> errorItemModels = new List <ErrorItemModel>();
                errorItemModels.AddRange(ex.error);
                return(new DataResponse <List <Conuntry> >(null)
                {
                    errorMessages = errorItemModels,
                    message = ex.message,
                    status = false
                });
            }
            catch (Exception ex)
            {
                await _ioTConnectAPIDiscovery.LoggedException(_envCode, ex, "Master", "Countries()");

                throw ex;
            }
        }
        /// <summary>
        /// Login into IotConnect.
        /// </summary>
        /// <param name="loginModel">The login model.</param>
        /// <returns></returns>
        public async Task <DataResponse <LoginResult> > Login(LoginModel loginModel)
        {
            try
            {
                var portalAuthApi = await _ioTConnectAPIDiscovery.GetPortalUrl(_envCode, _solutionKey, IoTConnectBaseURLType.AuthBaseUrl);

                string formattedUrl = String.Format(portalAuthApi, Constants.authVersion);
                string basicToken   = await GetBasicToken(formattedUrl);

                if (!string.IsNullOrWhiteSpace(basicToken))
                {
                    var dataResponse = await GetLoginAccess(loginModel.UserName, loginModel.Password, formattedUrl, basicToken, _solutionKey);

                    return(new DataResponse <LoginResult>(null)
                    {
                        data = dataResponse,
                        status = true
                    });
                }
                else
                {
                    return(new DataResponse <LoginResult>(null));
                }
            }
            catch (IoTConnectException ex)
            {
                List <ErrorItemModel> errorItemModels = new List <ErrorItemModel>();
                errorItemModels.AddRange(ex.error);

                return(new DataResponse <LoginResult>(null)
                {
                    errorMessages = errorItemModels,
                    message = ex.message,
                    status = false
                });
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Get role list with user count.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <DataResponse <List <AllRoleResult> > > AllRole(AllRoleModel request)
        {
            try
            {
                var portalApi = await _ioTConnectAPIDiscovery.GetPortalUrl(_envCode, _solutionKey, IoTConnectBaseURLType.UserBaseUrl);

                string accessTokenUrl = string.Concat(portalApi, UserApi.Roles);
                string formattedUrl   = String.Format(accessTokenUrl, Constants.userVersion);
                var    roleList       = await formattedUrl.WithHeaders(new { Content_type = Constants.contentType, Authorization = Constants.bearerTokenType + _token })
                                        .SetQueryParams(new
                {
                    PageSize   = request.PageSize,
                    PageNo     = request.PageNo,
                    SortBy     = request.SortBy,
                    SearchText = request.SearchText
                }).GetJsonAsync <BaseResponse <List <AllRoleResult> > >();

                return(new DataResponse <List <AllRoleResult> >(null)
                {
                    data = roleList.Data,
                    status = true
                });
            }
            catch (IoTConnectException ex)
            {
                List <ErrorItemModel> errorItemModels = new List <ErrorItemModel>();
                errorItemModels.AddRange(ex.error);
                return(new DataResponse <List <AllRoleResult> >(null)
                {
                    errorMessages = errorItemModels,
                    message = ex.message,
                    status = false
                });
            }
            catch (Exception ex)
            {
                await _ioTConnectAPIDiscovery.LoggedException(_envCode, ex, "User", "AllRole()");

                throw ex;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Add new User.
        /// </summary>
        /// <param name="model">Add User Model.</param>
        /// <param name="password">(Optional)Password. Default Empty.</param>
        /// <returns></returns>
        public async Task <DataResponse <AddUserResult> > Add(AddUserModel model, string password = "")
        {
            try
            {
                var errorList = Helper.ValidateObject(model);
                if (errorList?.Count > 0)
                {
                    return(new DataResponse <AddUserResult>(null)
                    {
                        errorMessages = errorList,
                        message = "Data Error",
                        status = false
                    });
                }
                model.Properties = null;
                var portalApi = await _ioTConnectAPIDiscovery.GetPortalUrl(_envCode, _solutionKey, IoTConnectBaseURLType.UserBaseUrl);

                string accessTokenUrl = string.Concat(portalApi, UserApi.Add);
                string formattedUrl   = String.Format(accessTokenUrl, Constants.userVersion);
                var    result         = await formattedUrl.WithHeaders(new { Content_type = Constants.contentType, Authorization = Constants.bearerTokenType + _token })
                                        .PostJsonAsync(model).ReceiveJson <DataResponse <List <AddUserResult> > >();

                if (!string.IsNullOrWhiteSpace(password))
                {
                    var resetPaasword = await ResetPassword(new ResetPasswordModel()
                    {
                        Email = model.UserId, InvitationGuid = result.data.FirstOrDefault().invitationGuid, NewPassword = password
                    });

                    return(new DataResponse <AddUserResult>(null)
                    {
                        data = null,
                        message = "User registered successfully",
                        status = true,
                    });
                }
                return(new DataResponse <AddUserResult>(null)
                {
                    data = result.data.FirstOrDefault(),
                    message = result.message,
                    status = true,
                });
            }
            catch (IoTConnectException ex)
            {
                List <ErrorItemModel> errorItemModels = new List <ErrorItemModel>();
                errorItemModels.AddRange(ex.error);
                return(new DataResponse <AddUserResult>(null)
                {
                    errorMessages = errorItemModels,
                    message = ex.message,
                    status = false
                });
            }
            catch (Exception ex)
            {
                await _ioTConnectAPIDiscovery.LoggedException(_envCode, ex, "User", "Add()");

                throw ex;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// This API endpoint gives you the list of available rules in your device template.
        /// You can also add filters as given in the parameters.Though the filters are optional,
        /// to apply them, you need to send these filter parameters in a query string.
        /// </summary>
        /// <param name="pagingModel"></param>
        /// <returns></returns>
        public async Task <DataResponse <List <AllRuleResult> > > All(PagingModel pagingModel)
        {
            try
            {
                var portalApi = await _ioTConnectAPIDiscovery.GetPortalUrl(_envCode, _solutionKey, IoTConnectBaseURLType.DeviceBaseUrl);

                string accessTokenUrl = string.Concat(portalApi, RuleApi.AllRules);
                string formattedUrl   = String.Format(accessTokenUrl, Constants.deviceVersion);
                var    result         = await formattedUrl.WithOAuthBearerToken(_token)
                                        .SetQueryParams(new
                {
                    pageSize   = pagingModel.PageSize,
                    pageNumber = pagingModel.PageNo,
                    searchtext = pagingModel.SearchText,
                    sortBy     = pagingModel.SortBy
                })
                                        .GetJsonAsync <DataResponse <List <AllRuleResult> > >();

                return(new DataResponse <List <AllRuleResult> >(null)
                {
                    data = result.data,
                    message = result.message,
                    status = true
                });
            }
            catch (IoTConnectException ex)
            {
                List <ErrorItemModel> errorItemModels = new List <ErrorItemModel>();
                errorItemModels.AddRange(ex.error);
                return(new DataResponse <List <AllRuleResult> >(null)
                {
                    errorMessages = errorItemModels,
                    message = ex.message,
                    status = false
                });
            }
            catch (Exception ex)
            {
                await _ioTConnectAPIDiscovery.LoggedException(_envCode, ex, "Rule", "All()");

                throw ex;
            }
        }