public static List <SaleCustomer> GetSaleCustomer() { List <SaleCustomer> customers = new List <SaleCustomer>(); using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("SELECT * FROM ClientesVentas")) { command.Connection = connection; connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { SaleCustomer customer = new SaleCustomer(); customer.Name = reader["nombre"].ToString(); customer.Address = reader["domicilio"].ToString(); customer.City = reader["ciudad"].ToString(); customer.PhoneNumber = reader["telefono"].ToString(); customer.StateId = int.Parse(reader["estadoID"].ToString()); customer.RFC = reader["RFC"].ToString(); customer.DistrictOrColony = reader["colonia"].ToString(); customer.ZipCode = reader["CP"].ToString(); customers.Add(customer); } } } } return(customers); }
public SaleCustomerList() { InitializeComponent(); presenter = new SaleCustomerPresenter(this); CurrentSaleCustomer = new SaleCustomer(); GridSaleCustomerDetails.DataContext = CurrentSaleCustomer; }
public IHttpActionResult Update(SaleCustomer saleCustomer) { SaleCustomerResponse response = new SaleCustomerResponse(); try { SaleCustomer saleCustomerSaved = saleCustomerBL.UpdateSaleCustomer(saleCustomer); response.SaleCustomer = saleCustomerSaved; response.Success = true; } catch (SaleCustomerException ex) { response.ErrorCode = ex.Error; response.ErrorMessage = "Error. " + ex.Error.ToString(); response.SaleCustomer = null; response.Success = false; } catch (Exception ex) { response.ErrorMessage = "Error. " + ex.Message; response.SaleCustomer = null; response.Success = false; } return(Ok(response)); }
public static SaleCustomer CreateDummySaleCustomer() { SaleCustomer saleCustomer = new SaleCustomer(); saleCustomer.Address = "Direccion de prueba"; saleCustomer.Name = "SaleCustomerTestName"; return(saleCustomer); }
public SaleCustomer UpdateSaleCustomer(SaleCustomer saleCustomer) { using (SqlCommand command = new SqlCommand()) { using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = ConnectionString; command.Connection = connection; command.CommandText = "spUpsertSaleCustomer"; command.CommandType = CommandType.StoredProcedure; foreach (PropertyInfo prop in (from x in saleCustomer.GetType().GetProperties() where !excludedPropertiesInUpdate.Contains(x.Name) select x).ToArray()) { command.Parameters.AddWithValue("@" + prop.Name, prop.GetValue(saleCustomer)); } connection.Open(); object saleCustomerId = command.ExecuteScalar(); saleCustomer.Id = int.Parse(saleCustomerId.ToString()); connection.Close(); } return(saleCustomer); } }
public SaleCustomer UpdateSaleCustomer(SaleCustomer customer) { //Add validations here! SaleCustomerError result = SaleCustomerError.None; if (string.IsNullOrEmpty(customer.Name)) { result |= SaleCustomerError.InvalidName; } if (customer.StateId <= 0) { result |= SaleCustomerError.InvalidState; } if (result != SaleCustomerError.None) { throw new SaleCustomerException(result); } else { return(saleCustomerDL.UpdateSaleCustomer(customer)); } }