Пример #1
0
 public static InvoiceCustomer ToInvoiceCustomer(this CustomerWithInvoices customer)
 {
     return(new InvoiceCustomer()
     {
         CustomerNumber = customer.CustomerNumber,
         CustomerName = customer.CustomerName,
         DisplayName = customer.DisplayName,
         CustomerBranch = customer.CustomerBranch,
         NationalOrRegionalAccountNumber = customer.NationalOrRegionalAccountNumber,
         ContractId = customer.ContractId,
         CustomerId = customer.CustomerId,
         AccountId = customer.AccountId,
         Phone = customer.Phone,
         Email = customer.Email,
         Address = customer.Address,
         NationalId = customer.NationalId,
         NationalNumber = customer.NationalNumber,
         NationalSubNumber = customer.NationalSubNumber,
         NationalIdDesc = customer.NationalIdDesc,
         NationalNumberSubDesc = customer.NationalNumberSubDesc,
         RegionalId = customer.RegionalId,
         RegionalIdDesc = customer.RegionalIdDesc,
         RegionalNumber = customer.RegionalNumber,
         RegionalNumberDesc = customer.RegionalNumberDesc,
         HasPayableInvoices = customer.HasPayableInvoices,
         NumberInvoices = customer.PagedResults.TotalInvoices,
         TotalAmountDue = (customer.TotalAmountDue != null) ? customer.TotalAmountDue.Value : 0
     });
 }
Пример #2
0
        public List <CustomerWithInvoices> GetBrazilCustomerInvoices(string country)
        {
            var sql = @"SELECT FirstName, LastName, InvoiceId, InvoiceDate
                        FROM Customer
	                    JOIN Invoice
		                ON Customer.CustomerId = Invoice.CustomerId
		                WHERE Customer.Country = @country;"        ;


            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                var cmd = connection.CreateCommand();
                cmd.CommandText = sql;
                cmd.Parameters.AddWithValue("country", country);

                var reader = cmd.ExecuteReader();

                var customerInvoices = new List <CustomerWithInvoices>();

                while (reader.Read())
                {
                    var customerInvoice = new CustomerWithInvoices
                    {
                        FirstName   = (string)reader["FirstName"],
                        LastName    = (string)reader["LastName"],
                        InvoiceDate = (System.DateTime)reader["InvoiceDate"],
                        InvoiceId   = (int)reader["InvoiceId"]
                    };
                    customerInvoices.Add(customerInvoice);
                }

                connection.Close();

                return(customerInvoices);
            }
        }