private void SearchById(int id) { try { ApiResponse response = Helper.GetApiResponse("api/Products/" + id.ToString()); InventoryUi.Models.Product data = JsonConvert.DeserializeObject <InventoryUi.Models.Product>(response.data.ToString()); if (response.responseCode == ApiResponse.Success) { TxtProductName.Text = data.ProductName; TxtDescription.Text = data.ProductDescription.Replace("<br />", "\r\n"); CboCategory.SelectedValue = data.CategoryId.ToString(); CboUnit.SelectedValue = data.UnitId.ToString(); TxtPrice.Text = data.Price.ToString(); CboCurrency.SelectedValue = data.Currency; } else if (response.responseCode == ApiResponse.NoDataFound) { this.ClearFields(); LblErrorMsg.Text = "No Data Found"; LblErrorMsg.Visible = true; } else if (response.responseCode == ApiResponse.Exception) { this.ClearFields(); LblErrorMsg.Text = "Api Error: " + response.error; LblErrorMsg.Visible = true; } } catch (Exception ex) { this.ClearFields(); LblErrorMsg.Text = "Page Error: " + ex.Message; LblErrorMsg.Visible = true; } }
protected void CmdSave_Click(object sender, EventArgs e) { try { int productId = 0; decimal price = 0; if (!decimal.TryParse(TxtPrice.Text, out price)) { LblErrorMsg.Text = "Invalis Price value !"; LblErrorMsg.Visible = true; } else if (int.TryParse(TxtId.Text, out productId)) { InventoryUi.Models.Product product = new InventoryUi.Models.Product(); product.ProductId = productId; product.ProductName = TxtProductName.Text; product.ProductDescription = TxtDescription.Text.Replace("\r\n", "<br />"); product.CategoryId = int.Parse(CboCategory.SelectedValue); product.Price = price; product.Currency = CboCurrency.SelectedValue; product.UnitId = int.Parse(CboUnit.SelectedValue); string json = JsonConvert.SerializeObject(product); ApiResponse response = Helper.PutToApi("api/Products/Modify", json); if (response.responseCode == 0) { LblMsg.Text = "Changes saved"; LblMsg.Visible = true; } else { LblErrorMsg.Text = "Server Error: " + response.error; LblErrorMsg.Visible = true; } } else { LblErrorMsg.Text = "Please enter proper Id to search"; LblErrorMsg.Visible = true; } } catch (Exception ex) { TxtDescription.Text = ""; LblErrorMsg.Text = "Page Error: " + ex.Message; LblErrorMsg.Visible = true; } }
protected void CmdSave_Click(object sender, EventArgs e) { try { decimal price = 0; if (!decimal.TryParse(TxtPrice.Text, out price)) { LblErrorMsg.Text = "Invalis Price value !"; LblErrorMsg.Visible = true; } else { InventoryUi.Models.Product product = new InventoryUi.Models.Product(); product.ProductId = 0; product.ProductName = TxtProductName.Text; product.ProductDescription = TxtDescription.Text.Replace("\r\n", "<br />"); product.CategoryId = int.Parse(CboCategory.SelectedValue); product.Price = price; product.Currency = CboCurrency.SelectedValue; product.UnitId = int.Parse(CboUnit.SelectedValue); string json = JsonConvert.SerializeObject(product); ApiResponse response = Helper.PostToApi("api/Products/Create", json); if (response.responseCode == 0) { LblMsg.Text = "New product created with Product Id: " + response.data.ToString(); LblMsg.Visible = true; } else { LblErrorMsg.Text = "Server Error: " + response.error; LblErrorMsg.Visible = true; } } } catch (Exception ex) { TxtDescription.Text = ""; LblErrorMsg.Text = "Page Error: " + ex.Message; LblErrorMsg.Visible = true; } }