Example #1
0
        protected void Operation_Click(object sender, EventArgs e)
        {
            try
            {
                //LoadHTMLTable();
                bool xSuccess = false;
                int  xClassid = 0;

                if (Validation())
                {
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["uri"]);
                        client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                        //Save
                        if (btnOperation.InnerText.Trim() == "Add")
                        {
                            CustomerClasses p = new CustomerClasses
                            {
                                classCode     = txtCode_CustomerClass.Value.ToString().Trim(),
                                classDesc     = txtName_CustomerClass.Value.ToString().Trim(),
                                classIsactive = (!chkInActive_CustomerClass.Checked),
                                classProduct  = 0,
                                classService  = 0
                            };
                            var post = client.PostAsJsonAsync <CustomerClasses>("api/CustomerClasses", p);
                            post.Wait();
                            var response = post.Result;

                            if (response.IsSuccessStatusCode)
                            {
                                var a = response.Content.ReadAsStringAsync().Result;
                                CustomerClassUpdate customerClassesUpdates = JsonConvert.DeserializeObject <CustomerClassUpdate>(a);
                                xClassid = customerClassesUpdates.id;

                                ControlNosUpdate c = new ControlNosUpdate {
                                    controldescription = "Customer Class Code", sitecode = System.Configuration.ConfigurationManager.AppSettings["SiteCode"].ToString(), controlnumber = Convert.ToString((Int64.Parse(_ControlNo) + 1))
                                };
                                string api = "api/ControlNos/updatecontrol";
                                post = client.PostAsJsonAsync <ControlNosUpdate>(api, c);
                                post.Wait();
                                response = post.Result;
                                if (response.IsSuccessStatusCode)
                                {
                                    xSuccess = true;
                                    Response.Redirect("CustomerMaster.aspx");
                                }
                            }
                            else
                            {
                                oCommonEngine.SetAlert(this.Page, response.StatusCode + "...!", Utilities.CommonEngine.MessageType.Error, Utilities.CommonEngine.MessageDuration.Short);
                            }
                        }
                        else  //Update
                        {
                            CustomerClassUpdate p = new CustomerClassUpdate
                            {
                                classCode     = txtCode_CustomerClass.Value.ToString().Trim(),
                                classDesc     = txtName_CustomerClass.Value.ToString().Trim(),
                                classIsactive = (!chkInActive_CustomerClass.Checked),
                                classProduct  = 0,
                                classService  = 0,
                                id            = Int32.Parse(_PKey)
                            };
                            xClassid = Int32.Parse(_PKey);
                            var post = client.PutAsJsonAsync <CustomerClassUpdate>("api/CustomerClasses", p);
                            post.Wait();
                            var response = post.Result;

                            if (response.IsSuccessStatusCode)
                            {
                                xSuccess = true;

                                //string api = "api/Departmentaldiscounts/10";
                                //post = client.DeleteAsync(api);
                                //post.Wait();
                                //response = post.Result;
                                //if (response.IsSuccessStatusCode)
                                //{
                                //    xSuccess = true;
                                //}
                            }
                            else
                            {
                                oCommonEngine.SetAlert(this.Page, response.StatusCode + "...!", Utilities.CommonEngine.MessageType.Error, Utilities.CommonEngine.MessageDuration.Short);
                            }
                        }


                        if (xSuccess)
                        {
                            if (btnOperation.InnerText.Trim() == "Add")
                            {
                                oCommonEngine.SetAlert(this.Page, "Customer Class Saved Successfully..!", Utilities.CommonEngine.MessageType.Success, Utilities.CommonEngine.MessageDuration.Short);
                                Session["AlertMessage"]     = "Customer Class Created Sucessfully...!";
                                txtCode_CustomerClass.Value = Convert.ToString((Int64.Parse(_ControlNo) + 1));
                                txtName_CustomerClass.Value = string.Empty;
                                LoadDepartments();
                            }
                            else
                            {
                                Session["AlertMessage"] = "Customer Class " + " Updated Sucessfully...!";
                                Response.Redirect("CustomerMaster.aspx?PKey=CLASS");
                            }
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                oCommonEngine.SetAlert(this.Page, Ex.Message, Utilities.CommonEngine.MessageType.Error, Utilities.CommonEngine.MessageDuration.Short);
            }
        }
Example #2
0
        private void FetchRecords()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["uri"]);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                //GET Method
                string api      = "api/CustomerClasses/" + _PKey;
                var    response = client.GetAsync(api).Result;
                if (response.IsSuccessStatusCode)
                {
                    var             a = response.Content.ReadAsStringAsync().Result;
                    CustomerClasses customerClasses = JsonConvert.DeserializeObject <CustomerClasses>(a);

                    txtName_CustomerClass.Value       = customerClasses.classDesc;
                    chkInActive_CustomerClass.Checked = (customerClasses.classIsactive == false);
                }
                else
                {
                    Console.WriteLine("Internal server Error");
                }
            }

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["uri"]);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                //GET Method
                string api      = "api/Departmentaldiscounts?filter={\"where\":{\"classid\":" + _PKey + "}}";
                var    response = client.GetAsync(api).Result;
                if (response.IsSuccessStatusCode)
                {
                    var a = response.Content.ReadAsStringAsync().Result;
                    List <ItemDeptDiscountUpdate> depts = JsonConvert.DeserializeObject <List <ItemDeptDiscountUpdate> >(a);

                    for (int i = 0; i < depts.Count; i++)
                    {
                        for (int j = 1; j < tblDiscount.Rows.Count; j++)
                        {
                            if (Int32.Parse(tblDiscount.Rows[j].Cells[3].InnerText) == depts[i].departmentid)
                            {
                                // var txtDiscount = (HtmlInputText)tblDiscount.Rows[j].Cells[2].Controls[0];

                                var cell       = tblDiscount.Rows[j].Cells[2];
                                var txtDynamic = cell.Controls.OfType <HtmlInputText>().FirstOrDefault();
                                txtDynamic.Value = depts[i].discount.ToString();

                                tblDiscount.Rows[j].Cells[4].InnerText = depts[i].id.ToString();


                                //string tInputBox0 = tblDiscount.Rows[j].Cells[2].Controls[0].ClientID;
                                //var tContent = (HtmlInputText)tblDiscount.Rows[j].Cells[2].FindControl(tInputBox0);
                                //var txtdis = (HtmlInputText)tblDiscount.Rows[j].Cells[2].Controls[0];
                                //string x = txtdis.Value;
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Internal server Error");
                }
            }
        }