Example #1
0
        public async void ExecuteLoginCommand()
        {
            if (CheckValidations())
            {
                UserModel user = new UserModel();
                user.EmailId  = Email;
                user.Password = Password;
                UserDialogs.Instance.ShowLoading();
                Rest_Response rest_result = await WebService.PostData(user, "User/UserLogin");

                if (rest_result != null)
                {
                    if (rest_result.status_code == 200)
                    {
                        RootObjectLoginUserModel data = JsonConvert.DeserializeObject <RootObjectLoginUserModel>(rest_result.response_body);
                        if (data.StatusCode == 200)
                        {
                            var userobj = data.user_detail;
                            if (userobj.IsAdmin)
                            {
                                App.Current.MainPage = new AdminMasterController();
                            }
                            else
                            {
                                App.baseUser = userobj;
                                App.setting_Model.userModel = userobj;
                                var sUser = JsonConvert.SerializeObject(App.setting_Model);
                                Settings.GeneralSettings = sUser;
                                App.Current.MainPage     = new UserMasterController();
                            }
                        }
                        else
                        {
                            UserDialogs.Instance.Alert("Invalid Username or Password", null, "OK");
                        }
                    }
                }
                UserDialogs.Instance.HideLoading();
            }
        }
Example #2
0
        public async Task <ObservableCollection <ProductModel> > GetProduct()
        {
            ObservableCollection <ProductModel> productList = null;


            UserDialogs.Instance.ShowLoading();
            Rest_Response rest_result = await WebService.GetData("Product/GetProductList");

            if (rest_result != null)
            {
                if (rest_result.status_code == 200)
                {
                    RootObjectProduct data = JsonConvert.DeserializeObject <RootObjectProduct>(rest_result.response_body);
                    if (data.StatusCode == 200)
                    {
                        productList = data.Result;
                    }
                }
            }
            UserDialogs.Instance.HideLoading();
            return(productList);
        }
Example #3
0
        private async void ExecuteAddItemCommand()
        {
            if (CheckValidations())
            {
                ProductModel product = new ProductModel();
                product.Name  = Name;
                product.Price = Convert.ToDouble(Price);

                product.Qty   = Convert.ToInt16(Qty);
                product.Image = ItemImage;
                product.Desc  = Desc;
                product.Type  = Type;

                UserDialogs.Instance.ShowLoading();

                Rest_Response rest_result = await WebService.PostData(product, "Product/AddProduct");

                if (rest_result != null)
                {
                    if (rest_result.status_code == 200)
                    {
                        RootObjectProduct data = JsonConvert.DeserializeObject <RootObjectProduct>(rest_result.response_body);
                        if (data.StatusCode == 200)
                        {
                            var userobj = data.Result;
                            UserDialogs.Instance.Alert("Item Added", null, "OK");
                        }
                    }
                    else
                    {
                        UserDialogs.Instance.Alert("Product Already Added");
                    }
                }
                UserDialogs.Instance.HideLoading();
            }
        }
Example #4
0
        //Post Data
        public static async Task <Rest_Response> PostData(object body, string methodUrl)
        {
            Rest_Response resp = new Rest_Response();

            try
            {
                JObject             json            = null;
                string              serialized_body = "";
                HttpClient          httpClient      = new HttpClient();
                HttpResponseMessage response        = null;

                string url = Constant.BaseUrl + methodUrl;
                serialized_body = JsonConvert.SerializeObject(body);

                //string getSerializeBody = String.Empty;
                //getSerializeBody = Tools.serialize_json(body, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Include });
                //serialized_body = "'" + getSerializeBody + "'";

                StringContent content = new StringContent(serialized_body, Encoding.UTF8, encoding);
                httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(encoding));
                response = await httpClient.PostAsync(url, content);

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

                json = JObject.Parse(await response.Content.ReadAsStringAsync());

                #region Build-Response-Object

                if (!string.IsNullOrEmpty(response_text))
                {
                    resp.content_length = response_text.Length;
                }
                else
                {
                    resp.content_length = 0;
                }

                resp.content_type  = encoding;
                resp.response_body = response_text;
                resp.status_code   = (int)response.StatusCode;

                #endregion

                #region Enumerate-Response
                bool rest_enumerate = true;
                if (rest_enumerate)
                {
                    Debug.WriteLine("rest_client response status_code " + resp.status_code + ": " + resp.content_length + "B for " + "POST" + " " + url);
                    Debug.WriteLine(resp.response_body);
                }

                #endregion

                httpClient.Dispose();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(resp);
        }