Inheritance: System.Data.Objects.DataClasses.EntityObject
Esempio n. 1
0
        public void Create(CreateCustomerRequest createCustomerRequest)
        {
            using (var context = new PRToolsEntities())
            {
                var customerEntity = new Customer
                                         {

                                             FacebookURL = createCustomerRequest.FacebookUrl,
                                             ZLastName = createCustomerRequest.ZLastName,
                                             ZFirstName = createCustomerRequest.ZFirstName,
                                             WebsiteURL = createCustomerRequest.WebsiteUrl,
                                             TwitterHandle = createCustomerRequest.TwitterHandle,
                                             Phone = createCustomerRequest.Phone,
                                             Name = createCustomerRequest.Name,
                                             ListName = createCustomerRequest.ListName,
                                             GooglePlacesURL = createCustomerRequest.GooglePlacesUrl,
                                         };

                if (createCustomerRequest.ParentCustomerId > 0)
                    customerEntity.ParentCustomerId = createCustomerRequest.ParentCustomerId;

                if (createCustomerRequest.AccountManagerId > 0)
                    customerEntity.AccountManagerId = createCustomerRequest.AccountManagerId;

                if (createCustomerRequest.CustomerType != Domain.CustomerType.Undefined)
                {
                    string customerTypeKey = createCustomerRequest.CustomerType.ToString();
                    CustomerType customerType =
                        context.CustomerTypes.FirstOrDefault(
                            x => x.CustomerTypeKey == customerTypeKey);

                    customerEntity.CustomerType = customerType;
                }

                customerEntity.Addresses.Add(new Address
                                                 {
                                                     Street = createCustomerRequest.MailingAddress.Street,
                                                     AdditionalInfo =
                                                         createCustomerRequest.MailingAddress.AdditionalInfo,
                                                     City = createCustomerRequest.MailingAddress.City,
                                                     State = createCustomerRequest.MailingAddress.State,
                                                     Zipcode = createCustomerRequest.MailingAddress.Zipcode,
                                                     AddressType = "Mailing",
                                                 });

                foreach (Domain.Contact contact in createCustomerRequest.Contacts)
                {
                    customerEntity.Contacts.Add(new Contact
                                                    {
                                                        FirstName = contact.FirstName,
                                                        LastName = contact.LastName,
                                                        Phone = contact.Phone,
                                                        Email = contact.Email,
                                                    });
                }

                context.Customers.AddObject(customerEntity);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomers(Customer customer)
 {
     base.AddObject("Customers", customer);
 }
Esempio n. 3
0
 /// <summary>
 /// Create a new Customer object.
 /// </summary>
 /// <param name="customerId">Initial value of the CustomerId property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Customer CreateCustomer(global::System.Int32 customerId, global::System.String name)
 {
     Customer customer = new Customer();
     customer.CustomerId = customerId;
     customer.Name = name;
     return customer;
 }