public bool AddCustomer(TblCustomerDTO dto) { string sql = "INSERT tblCustomers(name, phone, address, point) " + "VALUES(@name, @phone, @address, @point) "; try { cn = DBUtil.MakeConnect(); if (cn != null) { cmd = new SqlCommand(sql, cn); cmd.Parameters.AddWithValue("@name", dto.name); cmd.Parameters.AddWithValue("@phone", dto.phone); cmd.Parameters.AddWithValue("@address", dto.address); cmd.Parameters.AddWithValue("@point", dto.point); return(cmd.ExecuteNonQuery() > 0); } } catch (SqlException e) { throw new Exception(e.Message); } finally { DBUtil.CloseConnection(null, cn); } return(false); }
public bool UpdatePoint(TblCustomerDTO dto) { string sql = "UPDATE tblCustomers " + "SET point = @point " + "WHERE idCustomer = @id "; try { cn = DBUtil.MakeConnect(); if (cn != null) { cmd = new SqlCommand(sql, cn); cmd.Parameters.AddWithValue("@point", dto.point); cmd.Parameters.AddWithValue("@id", dto.idCustomer); return(cmd.ExecuteNonQuery() > 0); } } catch (SqlException e) { throw new Exception(e.Message); } finally { DBUtil.CloseConnection(null, cn); } return(false); }
public void SaveCustomer(frmCustomerDetail frmCustomerDetail) { try { string name = frmCustomerDetail.getCustomerName().Text; string phone = frmCustomerDetail.getCustomerPhone().Text; string address = frmCustomerDetail.getAddress().Text; bool isValid = checkCustomerField(name, phone, address); if (isValid) { TblCustomerDTO dto = new TblCustomerDTO() { idCustomer = frmCustomerDetail.getCustomerID(), name = name, phone = phone, address = address }; if (frmCustomerDetail.isAddNew()) { customerModel.addCustomer(dto); LoadCustomers(); } else { customerModel.updateCustomer(dto); LoadCustomers(); } MessageBox.Show(MessageUtil.SAVE_SUCCESS); } } catch (Exception) { MessageBox.Show(MessageUtil.ERROR + " Save Customer!"); } }
private void updateCustomerPoint() { //calculate point for customer int amount = int.Parse(form.getCurrentAmount().Text); int point = amount / 100; int customerPoint = int.Parse(form.getCustomerPoint().Text); int discount = int.Parse(form.getDiscount().Text); if (discount == 0) { point += customerPoint; } else { point += customerPoint - discount; } string customerId = form.getCustomerId().Text; TblCustomerDTO dto = new TblCustomerDTO() { idCustomer = customerId, point = point, }; customerModel.updatePoint(dto); }
public IActionResult UpdateCustomer([FromBody] TblCustomerDTO dto) { bool isValidToken = ValidateToken(); if (isValidToken) { TblCustomerDAO dao = TblCustomerDAO.getInstance(); try { bool isSuccess = dao.UpdateCustomer(dto); if (isSuccess) { return(Ok(isSuccess)); } else { return(BadRequest()); } } catch (Exception) { StatusCode(500); } } return(Unauthorized()); }
public bool updatePoint(TblCustomerDTO dto) { HttpResponseMessage responseMessage = ApiConnection.loadPutJsonObject("customer/update-point", dto, Program.TokenGlobal); if (responseMessage.IsSuccessStatusCode) { return(true); } return(false); }
public bool updateCustomer(TblCustomerDTO dto) { HttpResponseMessage responseMessage = ApiConnection.loadPutJsonObject("customer/update-customer", dto, Program.TokenGlobal); if (responseMessage.IsSuccessStatusCode) { var resultFromApi = responseMessage.Content.ReadAsStringAsync(); bool isSuccess = JsonConvert.DeserializeObject <bool>(resultFromApi.Result); return(isSuccess); } return(false); }
public List <TblCustomerDTO> loadCustomers() { string sql = "SELECT idCustomer, name, phone, address, point " + "FROM tblCustomers "; List <TblCustomerDTO> listCustomer = null; try { cn = DBUtil.MakeConnect(); if (cn != null) { cmd = new SqlCommand(sql, cn); reader = cmd.ExecuteReader(); while (reader.Read()) { TblCustomerDTO customer = new TblCustomerDTO() { idCustomer = reader["idCustomer"].ToString(), name = reader["name"].ToString(), phone = reader["phone"].ToString(), address = reader["address"].ToString(), point = int.Parse(reader["point"].ToString()) }; if (listCustomer == null) { listCustomer = new List <TblCustomerDTO>(); } listCustomer.Add(customer); } return(listCustomer); } } catch (SqlException e) { throw new Exception(e.Message); } finally { DBUtil.CloseConnection(reader, cn); } return(listCustomer); }