Beispiel #1
0
 private void SearchByUnitId(int id)
 {
     try
     {
         ApiResponse             response = Helper.GetApiResponse("api/Units/" + id.ToString());
         InventoryUi.Models.Unit data     = JsonConvert.DeserializeObject <InventoryUi.Models.Unit>(response.data.ToString());
         if (response.responseCode == ApiResponse.Success)
         {
             TxtUnitName.Text    = data.UnitName;
             TxtDescription.Text = data.UnitDescription;
         }
         else if (response.responseCode == ApiResponse.NoDataFound)
         {
             TxtUnitName.Text    = "";
             TxtDescription.Text = "";
             LblErrorMsg.Text    = "No Data Found";
             LblErrorMsg.Visible = true;
         }
         else if (response.responseCode == ApiResponse.Exception)
         {
             TxtUnitName.Text    = "";
             TxtDescription.Text = "";
             LblErrorMsg.Text    = "Api Error: " + response.error;
             LblErrorMsg.Visible = true;
         }
     }
     catch (Exception ex)
     {
         TxtUnitName.Text    = "";
         TxtDescription.Text = "";
         LblErrorMsg.Text    = "Page Error: " + ex.Message;
         LblErrorMsg.Visible = true;
     }
 }
        protected void CmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                InventoryUi.Models.Unit Unit = new InventoryUi.Models.Unit();
                Unit.UnitName        = TxtUnitName.Text;
                Unit.UnitDescription = TxtDescription.Text;
                string json = JsonConvert.SerializeObject(Unit);

                ApiResponse response = Helper.PostToApi("api/Units/Create", json);
                if (response.responseCode == 0)
                {
                    LblMsg.Text    = "New Unit created with Unit Id: " + response.data;
                    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;
            }
        }
 protected void CmdSearchById_Click(object sender, EventArgs e)
 {
     try
     {
         int id = 0;
         if (!int.TryParse(TxtId.Text, out id))
         {
             LblErrorMsg.Text    = "Please enter proper Id to search";
             LblErrorMsg.Visible = true;
         }
         else
         {
             ApiResponse             response = Helper.GetApiResponse("api/Units/" + id.ToString());
             InventoryUi.Models.Unit data     = JsonConvert.DeserializeObject <InventoryUi.Models.Unit>(response.data.ToString());
             if (response.responseCode == ApiResponse.Success)
             {
                 TxtUnitName.Text    = data.UnitName;
                 TxtDescription.Text = data.UnitDescription;
             }
             else if (response.responseCode == ApiResponse.NoDataFound)
             {
                 TxtUnitName.Text    = "";
                 TxtDescription.Text = "";
                 LblErrorMsg.Text    = "No Data Found";
                 LblErrorMsg.Visible = true;
             }
             else if (response.responseCode == ApiResponse.Exception)
             {
                 TxtUnitName.Text    = "";
                 TxtDescription.Text = "";
                 LblErrorMsg.Text    = "Api Error: " + response.error;
                 LblErrorMsg.Visible = true;
             }
         }
     }
     catch (Exception ex)
     {
         TxtUnitName.Text    = "";
         TxtDescription.Text = "";
         LblErrorMsg.Text    = "Page Error: " + ex.Message;
         LblErrorMsg.Visible = true;
     }
 }
Beispiel #4
0
        protected void CmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                int unitId = 0;

                if (int.TryParse(TxtId.Text, out unitId))
                {
                    InventoryUi.Models.Unit unit = new InventoryUi.Models.Unit();
                    unit.UnitId          = unitId;
                    unit.UnitName        = TxtUnitName.Text;
                    unit.UnitDescription = TxtDescription.Text;
                    string json = JsonConvert.SerializeObject(unit);

                    ApiResponse response = Helper.PutToApi("api/Units/Modify", json);
                    if (response.responseCode == 0)
                    {
                        LblMsg.Text    = "Changed 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;
            }
        }