public void TestCompositeForeignKey() { Customer cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; cust.LoadByPrimaryKey("01001", "001"); Assert.AreEqual(3, cust.OrderCollectionByCustID.Count); }
private static void AddSimpleBinding(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Simple Binding var binding = new Binding(customer1, "Name", customer2, "Name"); bindingManager.Bindings.Add(binding); #endregion }
/// <summary> /// Deletes a customer. /// </summary> /// <param name="customer">Customer.</param> /// <returns>Number of customer records deleted.</returns> public int DeleteCustomer(Customer customer) { StringBuilder sql = new StringBuilder(); sql.Append(" DELETE FROM Customer "); sql.Append(" WHERE CustomerId = " + customer.CustomerId); try { return Db.Update(sql.ToString()); } catch { return 0; } }
private static void AddSimpleBindingFluent(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Simple Fluent Binding bindingManager.Bind(customer1, "Name") .To(customer2, "Name") .Activate(); #endregion }
private static void OutputCustomer(string title, Customer customer) { Console.WriteLine(title); Console.WriteLine(" Name = '{0}'", customer.Name); Console.WriteLine(" Gender = {0}", customer.Gender); Console.WriteLine(" BirthDate = {0}", customer.BirthDate); Console.WriteLine(" Address = {0}", customer.Address.Line1); Console.WriteLine(" {0}", customer.Address.Line2); Console.WriteLine(" {0}", customer.Address.Line3); Console.WriteLine(" {0}", customer.Address.Line4); Console.WriteLine(" {0}", customer.Address.PostCode); Console.WriteLine(); }
static void Main(string[] args) { var customer1 = new Customer(); var customer2 = new Customer(); var customer1OutputSink = new OutputSink(); var customer2OutputSink = new OutputSink(); using (var bindingManager = new BindingManager()) { var useFluentInterface = false; if (!useFluentInterface) { //add various bindings to the binding manager AddSimpleBinding(customer1, customer2, bindingManager); AddSimpleTypedBinding(customer1, customer2, bindingManager); AddComplexBinding(customer1, customer2, bindingManager); AddComplexTypedBinding(customer1, customer2, bindingManager); AddSimpleMultiBinding(customer1, customer1OutputSink, bindingManager); AddSimpleTypedMultiBinding(customer2, customer2OutputSink, bindingManager); } else { //add various bindings to the binding manager using the fluent interface AddSimpleBindingFluent(customer1, customer2, bindingManager); AddSimpleTypedBindingFluent(customer1, customer2, bindingManager); AddComplexBindingFluent(customer1, customer2, bindingManager); AddComplexTypedBindingFluent(customer1, customer2, bindingManager); AddSimpleMultiBindingFluent(customer1, customer1OutputSink, bindingManager); AddSimpleTypedMultiBindingFluent(customer2, customer2OutputSink, bindingManager); } //make some property changes customer1.Name = "Kent"; customer2.Gender = Gender.Male; customer2.Address.Line1 = "12 Somewhere Lodge"; customer2.Address.Line2 = "Northwich"; } //output the details of each Customer object OutputCustomer("Customer 1", customer1); OutputCustomer("Customer 2", customer2); //output the details of each output sink Console.WriteLine("Customer 1 Output Sink: {0}", customer1OutputSink.Output); Console.WriteLine("Customer 2 Output Sink: {0}", customer2OutputSink.Output); Console.WriteLine("Any key to exit"); Console.ReadKey(); }
/* * Check if textboxes are empty, * converts the textboxes text from string to integer where you need to. * Stores the customer details entered in the form into the list. */ private void BtnAddCustomer_Click(object sender, RoutedEventArgs e) { try { //generate booking reference number auto if the text box is empty(Always empty because is readonly) if (String.IsNullOrEmpty(TxtCustomerRefNum.Text)) { MessageBox.Show("Customer Reference number auto generated!"); //get access to datalayer to use singleton pattern customerReference = DataSingleton.getCustomerReference(); TxtCustomerRefNum.Text = customerReference.ToString(); } //checks if the the form is filled up else if (String.IsNullOrEmpty(TxtCustomerName.Text) || String.IsNullOrEmpty(TxtCustomerAddress.Text)) { throw new ArgumentException("error"); } else { try { //store form information to variables string name = TxtCustomerName.Text; string address = TxtCustomerAddress.Text; //Stored new customer with the information from the form taken from the variables we used before BusinessObjects.Customer newCustomer = new BusinessObjects.Customer(customerReference, name, address);//arguments Customers.Add(newCustomer); //add customer reference number to the drop down menu for selecting customer for booking ComboBoxCustomerRef.Items.Add(newCustomer.CustomerNumber); //empty text boxes TxtCustomerAddress.Text = String.Empty; TxtCustomerName.Text = String.Empty; TxtCustomerRefNum.Text = String.Empty; } catch (ArgumentException) { MessageBox.Show("fix the errors"); } } } catch (ArgumentException) { MessageBox.Show("Empty fields.\nFill the customer fields to proceed."); } }
static void Main() { var customer = new Customer { Name = "FN LN", Age = 50, IsRegistered = true }; var addresses = new List<Address> { new Address {AddressLine1 = "UK Address", Country = new Country {Name = "UK"}, PostCode = "UK Post"}, new Address {AddressLine1 = "US Address", Country = new Country {Name = "US"}, PostCode = "US Post"} }; var drivingLicenses = new List<DrivingLicense> { new DrivingLicense {LicenseNumber = "12345"}, new DrivingLicense {LicenseNumber = "67890"} }; customer.DrivingLicenses = drivingLicenses.ToArray(); customer.Addresses = addresses; IDictionary<string, string> dictionary = new Dictionary<string, string>(); dictionary.Add(new KeyValuePair<string, string>("Viral", "Shah")); customer.UnSupportedType = dictionary; }
public static void Main(string[] a) { BusinessObjects.BAL.ServiceAreaImpl SAI = new BusinessObjects.BAL.ServiceAreaImpl(""); BusinessObjects.BAL.CustomerImpl CI = new CustomerImpl(); BusinessObjects.BAL.CustomerRegistration CR = new CustomerRegistration(); Customer customerlist = CR.getUser(5); Console.WriteLine(customerlist.firstname); Customer customer = new Customer(); customer.address = "no5 anandaroad"; customer.city = "Chennai"; customer.country = "India"; customer.DOB = DateTime.Today; customer.firstname = "Kumar"; customer.lastname = "CM"; customer.mobile = "9874563222"; customer.PIN = "600017"; customer.state = "Tamilnadu"; if (CI.saveUser(customer, "hellopwd")) { Console.WriteLine("Inserted Successfully"); } else { Console.WriteLine("Failed to Insert"); } Console.WriteLine(CR.checkUserRemoteExists("9874563210")); Console.WriteLine(CR.checkUserExists("9874563222")); dynamic SArea = SAI.getServiceAreas(); foreach (var item in SArea) { Console.WriteLine(item.PIN); } Console.WriteLine(SAI.checkServiceability()); }
/// <summary> /// Deletes a customer record from the database. /// </summary> /// <param name="customer">The customer to be deleted.</param> /// <returns>Number of rows affected.</returns> public int DeleteCustomer(Customer customer) { using (ActionDataContext db = DataContextFactory.CreateContext()) { try { CustomerEntity entity = Mapper.ToEntity(customer); db.CustomerEntities.Attach(entity, false); db.CustomerEntities.DeleteOnSubmit(entity); db.SubmitChanges(); return 1; } catch (ChangeConflictException) { throw new Exception("A change to customer record was made before your changes."); } catch (Exception) { return 0; } } }
/// <summary> /// Remove the customer from the order /// </summary> public void ClearCustomer() { _customer = null; }
/// <summary> /// Inserts a new customer. /// </summary> /// <remarks> /// Following insert, customer object will contain new identifier. /// </remarks> /// <param name="customer">Customer.</param> public void InsertCustomer(Customer customer) { StringBuilder sql = new StringBuilder(); sql.Append(" INSERT INTO Customer (CompanyName, City, Country) "); sql.Append(" VALUES( " + Db.Escape(customer.Company) + ", "); sql.Append(" " + Db.Escape(customer.City) + ", "); sql.Append(" " + Db.Escape(customer.Country) + ") "); // Assign new customer Id back to business object int newId = Db.Insert(sql.ToString(), true); customer.CustomerId = newId; }
public void TestSaveComposite() { int ordKey = -1; CustomerGroup custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; Customer cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; Order ord = new Order(); ord.es.Connection.Name = "ForeignKeyTest"; try { using (esTransactionScope scope = new esTransactionScope()) { custGroup.GroupID = "XXXXX"; custGroup.GroupName = "Test"; custGroup.Save(); cust.CustomerID = "XXXXX"; cust.CustomerSub = "XXX"; cust.CustomerName = "Test"; cust.str().DateAdded = "2007-01-01 00:00:00"; cust.Active = true; cust.Manager = 1; ord = cust.OrderCollectionByCustID.AddNew(); ord.str().OrderDate = "2007-12-31 00:00:00"; cust.Save(); ordKey = ord.OrderID.Value; Assert.AreEqual(1, cust.OrderCollectionByCustID.Count); } } finally { // Clean up cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; if (cust.LoadByPrimaryKey("XXXXX", "XXX")) { OrderCollection ordColl = cust.OrderCollectionByCustID; ordColl.MarkAllAsDeleted(); cust.MarkAsDeleted(); cust.Save(); } custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; if (custGroup.LoadByPrimaryKey("XXXXX")) { custGroup.MarkAsDeleted(); custGroup.Save(); } } }
private static void AddSimpleTypedBinding(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Simple TypedBinding var binding = new TypedBinding<Customer, Customer>(customer1, c => c.Gender, customer2, c => c.Gender); bindingManager.Bindings.Add(binding); #endregion }
public void TestSave() { int empKey = -1; CustomerGroup custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; Employee emp = new Employee(); emp.es.Connection.Name = "ForeignKeyTest"; Customer cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; try { using (esTransactionScope scope = new esTransactionScope()) { custGroup.GroupID = "XXXXX"; custGroup.GroupName = "Test"; custGroup.Save(); emp.LastName = "LastName"; emp.FirstName = "FirstName"; cust = emp.CustomerCollectionByStaffAssigned.AddNew(); cust.CustomerID = "XXXXX"; cust.CustomerSub = "XXX"; cust.CustomerName = "Test"; cust.str().DateAdded = "2007-01-01 00:00:00"; cust.Active = true; cust.Manager = 1; emp.Save(); empKey = emp.EmployeeID.Value; Assert.AreEqual(1, emp.CustomerCollectionByStaffAssigned.Count); Assert.AreEqual(emp.EmployeeID.Value, cust.StaffAssigned.Value); } } finally { // Clean up emp = new Employee(); emp.es.Connection.Name = "ForeignKeyTest"; if (emp.LoadByPrimaryKey(empKey)) { CustomerCollection custColl = emp.CustomerCollectionByStaffAssigned; custColl.MarkAllAsDeleted(); emp.MarkAsDeleted(); emp.Save(); } custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; if (custGroup.LoadByPrimaryKey("XXXXX")) { custGroup.MarkAsDeleted(); custGroup.Save(); } } }
public void TestMultiDeleteEntity() { int empKey = -1; int ordKey = -1; CustomerGroup custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; EmployeeCollection empColl = new EmployeeCollection(); empColl.es.Connection.Name = "ForeignKeyTest"; Employee emp = new Employee(); emp.es.Connection.Name = "ForeignKeyTest"; Employee testEmp = new Employee(); testEmp.es.Connection.Name = "ForeignKeyTest"; Customer cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; Order ord = new Order(); ord.es.Connection.Name = "ForeignKeyTest"; try { using (esTransactionScope scope = new esTransactionScope()) { // Setup custGroup.GroupID = "YYYYY"; custGroup.GroupName = "Test"; custGroup.Save(); emp = empColl.AddNew(); emp.LastName = "LastName"; emp.FirstName = "FirstName"; cust = emp.CustomerCollectionByStaffAssigned.AddNew(); cust.CustomerID = "YYYYY"; cust.CustomerSub = "YYY"; cust.CustomerName = "Test"; cust.str().DateAdded = "2007-01-01 00:00:00"; cust.Active = true; cust.Manager = 1; ord = emp.OrderCollectionByEmployeeID.AddNew(); ord.CustID = "YYYYY"; ord.CustSub = "YYY"; ord.str().OrderDate = "2007-01-01"; empColl.Save(); empKey = emp.EmployeeID.Value; ordKey = ord.OrderID.Value; Assert.AreEqual(1, emp.CustomerCollectionByStaffAssigned.Count); Assert.AreEqual(1, emp.OrderCollectionByEmployeeID.Count); Assert.AreEqual(emp.EmployeeID.Value, cust.StaffAssigned.Value); Assert.AreEqual(emp.EmployeeID.Value, ord.EmployeeID.Value); // Test testEmp.LoadByPrimaryKey(empKey); testEmp.OrderCollectionByEmployeeID.MarkAllAsDeleted(); testEmp.CustomerCollectionByStaffAssigned.MarkAllAsDeleted(); testEmp.MarkAsDeleted(); testEmp.Save(); emp = new Employee(); emp.es.Connection.Name = "ForeignKeyTest"; Assert.IsFalse(emp.LoadByPrimaryKey(empKey)); ord = new Order(); ord.es.Connection.Name = "ForeignKeyTest"; Assert.IsFalse(ord.LoadByPrimaryKey(ordKey)); cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; Assert.IsFalse(cust.LoadByPrimaryKey("YYYYY", "YYY")); } } finally { // Clean up ord = new Order(); ord.es.Connection.Name = "ForeignKeyTest"; if (ord.LoadByPrimaryKey(ordKey)) { ord.MarkAsDeleted(); ord.Save(); } cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; if (cust.LoadByPrimaryKey("YYYYY", "YYY")) { cust.MarkAsDeleted(); cust.Save(); } emp = new Employee(); emp.es.Connection.Name = "ForeignKeyTest"; if (emp.LoadByPrimaryKey(empKey)) { emp.MarkAsDeleted(); emp.Save(); } custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; if (custGroup.LoadByPrimaryKey("YYYYY")) { custGroup.MarkAsDeleted(); custGroup.Save(); } } }
private static void AddSimpleTypedMultiBinding(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple TypedMultiBinding var binding = new TypedMultiBinding<OutputSink>(outputSink, o => o.Output); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Name)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Gender)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.BirthDate)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.Line1)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.Line2)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.Line3)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.Line4)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.PostCode)); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new OutputConverter(); bindingManager.Bindings.Add(binding); #endregion }
private static void AddSimpleTypedBindingFluent(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Simple Fluent TypedBinding bindingManager.Bind(customer1, c => c.Gender) .To(customer2, c => c.Gender) .Activate(); #endregion }
/// <summary> /// Inserts a new customer. Stubbed. /// </summary> /// <remarks> /// Following insert, customer object will contain the new identifier. /// </remarks> /// <param name="customer">Customer.</param> public void InsertCustomer(Customer customer) { throw new NotImplementedException("Oracle data access not implemented."); }
private static void AddSimpleMultiBindingFluent(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple Fluent MultiBinding bindingManager.MultiBind(outputSink, "Output") .WithConverter(new OutputConverter()) .OneWayToTarget() .To(customer, "Name") .AndTo(customer, "Gender") .AndTo(customer, "BirthDate") .AndTo(customer, "Address.Line1") .AndTo(customer, "Address.Line2") .AndTo(customer, "Address.Line3") .AndTo(customer, "Address.Line4") .AndTo(customer, "Address.PostCode") .Activate(); #endregion }
/// <summary> /// Updates a customer record in the database. /// </summary> /// <param name="customer">The customer with updated values.</param> /// <returns>Number of rows affected.</returns> public int UpdateCustomer(Customer customer) { using (ActionDataContext db = DataContextFactory.CreateContext()) { try { CustomerEntity entity = Mapper.ToEntity(customer); db.CustomerEntities.Attach(entity, true); db.SubmitChanges(); // Update business object with new version customer.Version = VersionConverter.ToString(entity.Version); return 1; } catch (ChangeConflictException) { throw new Exception("A change to customer record was made before your changes."); } catch { return 0; } } }
/// <summary> /// Updates a customer. Stubbed. /// </summary> /// <param name="customer">Customer.</param> /// <returns>Number of customer records updated.</returns> public int UpdateCustomer(Customer customer) { throw new NotImplementedException("Oracle data access not implemented."); }
private static void AddComplexBinding(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Complex Binding var binding = new Binding(customer1, "Address.Line1", customer2, "Address.Line1"); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new FormerAddressLineConverter(); bindingManager.Bindings.Add(binding); #endregion }
/// <summary> /// Updates a customer. /// </summary> /// <param name="customer">Customer.</param> /// <returns>Number of customer records updated.</returns> public int UpdateCustomer(Customer customer) { StringBuilder sql = new StringBuilder(); sql.Append(" UPDATE Customer "); sql.Append(" SET CompanyName = " + Db.Escape(customer.Company) + ", "); sql.Append(" City = " + Db.Escape(customer.City) + ", "); sql.Append(" Country = " + Db.Escape(customer.Country) + " "); sql.Append(" WHERE CustomerId = " + customer.CustomerId); return Db.Update(sql.ToString()); }
private static void AddSimpleTypedMultiBindingFluent(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple Fluent TypedMultiBinding bindingManager.MultiBind(outputSink, o => o.Output) .WithConverter(new OutputConverter()) .OneWayToTarget() .To(customer, c => c.Name) .AndTo(customer, c => c.Gender) .AndTo(customer, c => c.BirthDate) .AndTo(customer, c => c.Address.Line1) .AndTo(customer, c => c.Address.Line2) .AndTo(customer, c => c.Address.Line3) .AndTo(customer, c => c.Address.Line4) .AndTo(customer, c => c.Address.PostCode) .Activate(); #endregion }
private static void AddComplexTypedBinding(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Complex TypedBinding var binding = new TypedBinding<Customer, Customer>(customer1, c => c.Address.Line2, customer2, c => c.Address.Line2); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new FormerAddressLineConverter(); bindingManager.Bindings.Add(binding); #endregion }
public static Customer GetCustomer1() { Customer retVal = new Customer(); retVal.CustomerId = 1; retVal.CustomerName = "Customer 1"; return retVal; }
/// <summary> /// Inserts a new customer record to the database. /// </summary> /// <param name="customer">The customer to be inserted.</param> public void InsertCustomer(Customer customer) { using (ActionDataContext db = DataContextFactory.CreateContext()) { try { CustomerEntity entity = Mapper.ToEntity(customer); db.CustomerEntities.InsertOnSubmit(entity); db.SubmitChanges(); // update business object with new version and id customer.CustomerId = entity.CustomerId; customer.Version = VersionConverter.ToString(entity.Version); } catch (ChangeConflictException) { throw new Exception("A change to customer record was made before your changes."); } } }
private static void AddComplexTypedBindingFluent(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Complex Fluent TypedBinding bindingManager.Bind(customer1, c => c.Address.Line2) .To(customer2, c => c.Address.Line2) .OneWayToTarget() .WithConverter(new FormerAddressLineConverter()) .Activate(); #endregion }
private static void AddSimpleMultiBinding(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple MultiBinding var binding = new MultiBinding(outputSink, "Output"); binding.Sources.Add(new Binding(null, null, customer, "Name")); binding.Sources.Add(new Binding(null, null, customer, "Gender")); binding.Sources.Add(new Binding(null, null, customer, "BirthDate")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line1")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line2")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line3")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line4")); binding.Sources.Add(new Binding(null, null, customer, "Address.PostCode")); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new OutputConverter(); bindingManager.Bindings.Add(binding); #endregion }
/// <summary> /// Maps customer business object to customer entity. /// </summary> /// <param name="customer">A customer business object.</param> /// <returns>A customer entity.</returns> internal static CustomerEntity ToEntity(Customer customer) { return new CustomerEntity { CustomerId = customer.CustomerId, CompanyName = customer.Company, City = customer.City, Country = customer.Country, Version = VersionConverter.ToBinary(customer.Version) }; }