예제 #1
0
        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);
        }
예제 #2
0
 public SaleCustomerList()
 {
     InitializeComponent();
     presenter           = new SaleCustomerPresenter(this);
     CurrentSaleCustomer = new SaleCustomer();
     GridSaleCustomerDetails.DataContext = CurrentSaleCustomer;
 }
예제 #3
0
        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));
        }
예제 #4
0
        public static SaleCustomer  CreateDummySaleCustomer()
        {
            SaleCustomer saleCustomer = new SaleCustomer();

            saleCustomer.Address = "Direccion de prueba";
            saleCustomer.Name    = "SaleCustomerTestName";
            return(saleCustomer);
        }
예제 #5
0
 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);
     }
 }
예제 #6
0
        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));
            }
        }