Exemplo n.º 1
0
        //Method that creates new Address for specific Company
        public bool CreateNewAddress(AddressDTO AddressNew)
        {
            bool check = false;
            using (TransactionScope transaction = new TransactionScope())
            {

                try
                {
                    Address AddressIn = new Address();
                    //Data transfer to the the AddressIn
                    AddressIn.Address1 = AddressNew.Address1;
                    AddressIn.Address2 = AddressNew.Address2;
                    AddressIn.City = AddressNew.City;
                    AddressIn.State = AddressNew.State;
                    AddressIn.PostalCode = AddressNew.PostalCode;
                    AddressIn.Country = AddressNew.Country;

                    using (var context = new RFQEntities())
                    {
                        //Finding references for the Foreign Keys
                        Company existingCompany = context.Companies.Single(p => p.CompanyID == AddressNew.CompanyID);

                        //Adding refernces
                        AddressIn.Company = existingCompany;

                        if (AddressIn.EntityState == EntityState.Detached)
                        {
                            context.Addresses.AddObject(AddressIn);
                        }

                        context.SaveChanges();

                    }

                }

                catch (Exception e)
                {
                    transaction.Dispose();
                    check = false;
                    return check;

                }
                transaction.Complete();
                check = true;
                return check;

            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new Address object.
 /// </summary>
 /// <param name="addressID">Initial value of the AddressID property.</param>
 /// <param name="companyID">Initial value of the CompanyID property.</param>
 /// <param name="address1">Initial value of the Address1 property.</param>
 /// <param name="city">Initial value of the City property.</param>
 /// <param name="state">Initial value of the State property.</param>
 /// <param name="postalCode">Initial value of the PostalCode property.</param>
 /// <param name="country">Initial value of the Country property.</param>
 public static Address CreateAddress(global::System.Int32 addressID, global::System.Int32 companyID, global::System.String address1, global::System.String city, global::System.String state, global::System.String postalCode, global::System.String country)
 {
     Address address = new Address();
     address.AddressID = addressID;
     address.CompanyID = companyID;
     address.Address1 = address1;
     address.City = city;
     address.State = state;
     address.PostalCode = postalCode;
     address.Country = country;
     return address;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Addresses EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAddresses(Address address)
 {
     base.AddObject("Addresses", address);
 }