Пример #1
0
        public async Task <bool> AddUser(string username, string password, string email, string phone, string fullname,
                                         DateTime birthdate, bool isadmin = false)
        {
            bool res = false;

            try
            {
                var requestUrl = BaseAPIConnectionString.AddUserUrl(_token);
                var client     = new HttpClient();
                client.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json"));
                HttpRequestMessage requestMessage = new HttpRequestMessage();
                requestMessage.Method     = HttpMethod.Post;
                requestMessage.RequestUri = new Uri(requestUrl);
                JObject jobjadd = new JObject(new UserModels()
                {
                    Fullname  = fullname,
                    Username  = username,
                    Password  = password,
                    Email     = email,
                    Phone     = phone,
                    Birthdate = birthdate,
                    Role      = isadmin
                });

                requestMessage.Content = new HttpStringContent(jobjadd.ToString(Formatting.Indented));
                var response = await client.SendRequestAsync(requestMessage);

                res = response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(res);
        }
Пример #2
0
        public async Task <bool> UpdateUser(string username, string fullname, DateTime birthdate, string phone,
                                            string email)
        {
            bool res;

            try
            {
                var requestUrl = BaseAPIConnectionString.UpdateUserUrl(_token);
                var client     = new HttpClient();
                client.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json"));
                var response = await client.SendRequestAsync(new HttpRequestMessage()
                {
                    Method     = HttpMethod.Put,
                    RequestUri = new Uri(requestUrl),
                    Content    = new HttpStringContent(new JObject(new UserModels()
                    {
                        Username  = username,
                        Fullname  = fullname,
                        Phone     = phone,
                        Birthdate = birthdate,
                        Email     = email,
                    }).ToString(Formatting.Indented))
                });

                res = response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(res);
        }
Пример #3
0
        public async Task <UserModels> Login(string username, string password)
        {
            UserModels models;

            try
            {
                var http       = new HttpClient();
                var requestUrl = BaseAPIConnectionString.LoginUrl();
                http.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json"));
                HttpRequestMessage requestMessage = new HttpRequestMessage();

                var passwordBytes = Encoding.UTF8.GetBytes(password);
                var encrypt       = sec.Encrypt(passwordBytes);
                var a             = Encoding.UTF8.GetString(encrypt);

                JObject objectlogin = new JObject(new LoginObject()
                {
                    Username = username,
                    Password = a
                });

                requestMessage.Content    = new HttpStringContent(objectlogin.ToString(Formatting.Indented));
                requestMessage.Method     = HttpMethod.Post;
                requestMessage.RequestUri = new Uri(requestUrl);

                var response = await http.SendRequestAsync(requestMessage);

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    var root = JsonConvert.DeserializeObject <RootUserModels>(content);
                    models = root.UserInfo[0];
                }
                else
                {
                    models = null;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(models);
        }
Пример #4
0
        public async Task <DiskIo> GetDiskIoAsync()
        {
            DiskIo result;

            try
            {
                var http       = new HttpClient();
                var urlRequest = BaseAPIConnectionString.GetDiskIOUrl(_token);
                var response   = await http.GetAsync(urlRequest);

                var results = await response.Content.ReadAsStringAsync();

                var deserialize = JsonConvert.DeserializeObject <RootObjectDisk>(results);
                result = deserialize.Io;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(result);
        }
Пример #5
0
        public async Task <List <NetworkInterfaces> > GetNetworkInterfacesAsync()
        {
            List <NetworkInterfaces> result;

            try
            {
                var http       = new HttpClient();
                var urlRequest = BaseAPIConnectionString.GetNetworkPropertiesUrl(_token);
                var response   = await http.GetAsync(urlRequest);

                var results = await response.Content.ReadAsStringAsync();

                var deserialize = JsonConvert.DeserializeObject <RootObjectNetIfaces>(results);
                result = deserialize.NetIfaceList.ToList();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(result);
        }
Пример #6
0
        public async Task <CpuCurrentSpeed> GetCpuCurrentSpeedAsync()
        {
            CpuCurrentSpeed result;

            try
            {
                var http       = new HttpClient();
                var urlRequest = BaseAPIConnectionString.GetCpuCurrentSpeedUrl(_token);

                var response = await http.GetAsync(urlRequest);

                var results = await response.Content.ReadAsStringAsync();

                var deserialize = JsonConvert.DeserializeObject <RootObjectCpuCurrentSpeed>(results);
                result = deserialize.CpuCurrentSpeed;
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
            return(result);
        }
Пример #7
0
        public async Task <SystemInformation> GetSystemInformationAsync()
        {
            SystemInformation result;

            try
            {
                var http       = new HttpClient();
                var urlRequest = BaseAPIConnectionString.GetSystemInfoUrl(_token);
                var response   = await http.GetAsync(urlRequest);

                var results = await response.Content.ReadAsStringAsync();

                var deserialize = JsonConvert.DeserializeObject <RootObjectSi>(results);
                result = deserialize.Si;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            return(result);
        }
Пример #8
0
        public async Task <Memory> GetMemoryAsync()
        {
            Memory result;

            try
            {
                var http       = new HttpClient();
                var urlRequest = BaseAPIConnectionString.GetMemoryInfoUrl(_token);

                var response = await http.GetAsync(urlRequest);

                var results = await response.Content.ReadAsStringAsync();

                var deserialize = JsonConvert.DeserializeObject <RootObjectMemory>(results);

                result = deserialize.MemoryProperties;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(result);
        }
Пример #9
0
        public async Task <List <UserModels> > FetchAllUserAvailable()
        {
            var lst = new List <UserModels>();

            try
            {
                var requestUrl = BaseAPIConnectionString.FetchAllUserConnUrl(_token);
                var client     = new HttpClient();
                client.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json"));
                var response = await client.GetAsync(new Uri(requestUrl));

                if (response.IsSuccessStatusCode)
                {
                    var rs          = response.Content.ReadAsStringAsync();
                    var deserialize = JsonConvert.DeserializeObject <RootUserModels>(rs.GetResults());
                    lst = deserialize.UserInfo;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(lst);
        }