private async void CreateCustomer() { try { string InsertUrl = baseUrl + "api/Customer/Create"; tblCustomer objCust = new tblCustomer(); objCust.CustName = txtCustName.Text.ToString(); objCust.CustEmail = txtCustEmail.Text.ToString(); objCust.CustAddress = txtCustAddress.Text.ToString(); objCust.CustContact = txtCustContact.Text.ToString(); if ((objCust != null) && (objCust.CustEmail != "")) { using (var objClient = new HttpClient()) { string contentType = "application/json"; var serializedCustomer = JsonConvert.SerializeObject(objCust); var content = new StringContent(serializedCustomer, Encoding.UTF8, contentType); var result = await objClient.PostAsync(InsertUrl, content); GetCustomer_(url); Clear(); } } else { MessageBox.Show("Email Id is Must!"); } } catch { MessageBox.Show("Invalid Customer!!"); } }
public List<tblCustomer> GetCustomerList(int PageNo, int RowCountPerPage, int IsPaging) { dbConnector objConn = new dbConnector(); SqlConnection Conn = objConn.GetConnection; Conn.Open(); try { List<tblCustomer> _listCustomer = new List<tblCustomer>(); if (Conn.State != System.Data.ConnectionState.Open) Conn.Open(); SqlCommand objCommand = new SqlCommand("READ_CUSTOMER", Conn); objCommand.CommandType = CommandType.StoredProcedure; objCommand.Parameters.AddWithValue("@PageNo", PageNo); objCommand.Parameters.AddWithValue("@RowCountPerPage", RowCountPerPage); objCommand.Parameters.AddWithValue("@IsPaging", IsPaging); SqlDataReader _Reader = objCommand.ExecuteReader(); while (_Reader.Read()) { tblCustomer objCust = new tblCustomer(); objCust.CustID = Convert.ToInt32(_Reader["CustID"]); objCust.CustName = _Reader["CustName"].ToString(); objCust.CustEmail = _Reader["CustEmail"].ToString(); objCust.CustAddress = _Reader["CustAddress"].ToString(); objCust.CustContact = _Reader["CustContact"].ToString(); _listCustomer.Add(objCust); } return _listCustomer; } catch { throw; } finally { if (Conn != null) { if (Conn.State == ConnectionState.Open) { Conn.Close(); Conn.Dispose(); } } } }
public string Create(tblCustomer objCust) { try { CrudDataService objCrd = new CrudDataService(); Int32 message = 0; if ((objCust.CustName != null) && (objCust.CustEmail != null)) message = objCrd.InsertCustomer(objCust); else message = -1; return message.ToString(); } catch { throw; } }
public tblCustomer GetCustomerDetails(long? id) { dbConnector objConn = new dbConnector(); SqlConnection Conn = objConn.GetConnection; Conn.Open(); try { tblCustomer objCust = new tblCustomer(); if (Conn.State != System.Data.ConnectionState.Open) Conn.Open(); SqlCommand objCommand = new SqlCommand("VIEW_CUSTOMER", Conn); objCommand.CommandType = CommandType.StoredProcedure; objCommand.Parameters.AddWithValue("@CustID", id); SqlDataReader _Reader = objCommand.ExecuteReader(); while (_Reader.Read()) { objCust.CustID = Convert.ToInt32(_Reader["CustID"]); objCust.CustName = _Reader["CustName"].ToString(); objCust.CustEmail = _Reader["CustEmail"].ToString(); objCust.CustAddress = _Reader["CustAddress"].ToString(); objCust.CustContact = _Reader["CustContact"].ToString(); } return objCust; } catch { throw; } finally { if (Conn != null) { if (Conn.State == ConnectionState.Open) { Conn.Close(); Conn.Dispose(); } } } }
public string Edit(tblCustomer objCust) { try { CrudDataService objCrd = new CrudDataService(); Int32 message = 0; message = objCrd.UpdateCustomer(objCust); return message.ToString(); } catch { throw; } }
public Int32 UpdateCustomer(tblCustomer objCust) { dbConnector objConn = new dbConnector(); SqlConnection Conn = objConn.GetConnection; Conn.Open(); int result = 0; try { if (Conn.State != System.Data.ConnectionState.Open) Conn.Open(); SqlCommand objCommand = new SqlCommand("UPDATE_CUSTOMER", Conn); objCommand.CommandType = CommandType.StoredProcedure; objCommand.Parameters.AddWithValue("@CustID", objCust.CustID); objCommand.Parameters.AddWithValue("@CustName", objCust.CustName); objCommand.Parameters.AddWithValue("@CustEmail", objCust.CustEmail); objCommand.Parameters.AddWithValue("@CustAddress", objCust.CustAddress); objCommand.Parameters.AddWithValue("@CustContact", objCust.CustContact); result = Convert.ToInt32(objCommand.ExecuteScalar()); if (result > 0) { return result; } else { return 0; } } catch { throw; } finally { if (Conn != null) { if (Conn.State == ConnectionState.Open) { Conn.Close(); Conn.Dispose(); } } } }