Esempio n. 1
0
 public async Task <ReturnData <Users> > ValidateUser(string username, string password)
 {
     return(await Task.Run(() =>
     {
         try
         {
             Users user = new Users
             {
                 username = username,
                 password = password
             };
             string url = ApiUrl.apiUrl() + "account/validateuser";
             string json = JsonConvert.SerializeObject(user);
             using (var client = new WebClient())
             {
                 client.Headers.Add("content-type", "application/json");
                 var response = Encoding.ASCII.GetString(client.UploadData(url, "POST", Encoding.UTF8.GetBytes(json)));
                 return JsonConvert.DeserializeObject <ReturnData <Users> >(response);
             }
         }
         catch (Exception ex)
         {
             ReturnData <Users> err = new ReturnData <Users>
             {
                 code = 500,
                 message = ex.Message
             };
             return err;
         }
     }));
 }
Esempio n. 2
0
 public async Task <ReturnData <int> > AddBrands(string brnd, string createdby)
 {
     return(await Task.Run(() =>
     {
         try
         {
             brands brand = new brands
             {
                 name = brnd,
                 createdby = createdby
             };
             string url = ApiUrl.apiUrl() + "products/addbrand";
             string json = JsonConvert.SerializeObject(brand);
             using (var client = new WebClient())
             {
                 client.Headers.Add("content-type", "application/json");
                 var response = Encoding.ASCII.GetString(client.UploadData(url, "POST", Encoding.UTF8.GetBytes(json)));
                 return JsonConvert.DeserializeObject <ReturnData <int> >(response);
             }
         }
         catch (WebException ex) when(ex.Response is HttpWebResponse response)
         {
             ReturnData <int> err = new ReturnData <int>
             {
                 code = 500,
                 message = ex.Message
             };
             return err;
         }
     }));
 }
Esempio n. 3
0
        public async Task <ResponseAPI <categories> > GetCategory()
        {
            ResponseAPI <categories> res = new ResponseAPI <categories>();

            try
            {
                string url = ApiUrl.apiUrl() + "products/GetCategories?status=" + "active";
                using (var client = new HttpClient())
                {
                    HttpResponseMessage response = await client.GetAsync(url);

                    response.EnsureSuccessStatusCode();
                    var resp = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <ResponseAPI <categories> >(resp));
                }
            }
            catch (Exception ex)
            {
                res = new ResponseAPI <categories>
                {
                    code    = 500,
                    message = ex.Message,
                    data    = null
                };
                return(res);
            }
        }
Esempio n. 4
0
        public async Task <ResponseAPI <brandCategory> > FetchBrandCategory()
        {
            ResponseAPI <brandCategory> res = new ResponseAPI <brandCategory>();

            return(await Task.Run(async() =>
            {
                try
                {
                    string url = ApiUrl.apiUrl() + "products/fetchbrandcategory";
                    using (var client = new HttpClient())
                    {
                        HttpResponseMessage response = await client.GetAsync(url);
                        response.EnsureSuccessStatusCode();
                        var resp = await response.Content.ReadAsStringAsync();
                        return JsonConvert.DeserializeObject <ResponseAPI <brandCategory> >(resp);
                    }
                }
                catch (Exception ex)
                {
                    res = new ResponseAPI <brandCategory>
                    {
                        code = 500,
                        message = ex.Message,
                        data = null
                    };
                    return res;
                }
            }));
        }