public int SaveAddress(HsrOrderApp.BL.DomainModel.Address address, HsrOrderApp.BL.DomainModel.Customer forThisCustomer) { AddressRepository rep = new AddressRepository(db); Address dbAddress = rep.SaveAddressInternal(address); if (address.IsNew) { Customer customer = db.CustomerSet.First(c => c.CustomerId == forThisCustomer.CustomerId); customer.Addresses.Add(dbAddress); db.SaveChanges(); } return(dbAddress.AddressId); }
public int SaveAddress(HsrOrderApp.BL.DomainModel.Address address, HsrOrderApp.BL.DomainModel.Customer forThisCustomer) { AddressRepository rep = new AddressRepository(db); int addressid = rep.SaveAddress(address); if (address.IsNew) { CustomerAddress ca = new CustomerAddress(); ca.AddressId = addressid; ca.CustomerId = forThisCustomer.CustomerId; db.CustomerAddresses.InsertOnSubmit(ca); db.SubmitChanges(); } return(addressid); }
public int SaveCustomer(HsrOrderApp.BL.DomainModel.Customer customer) { try { string setname = "CustomerSet"; Customer dbCustomer; bool isNew = false; if (customer.CustomerId == default(int) || customer.CustomerId <= 0) { isNew = true; dbCustomer = new Customer(); } else { dbCustomer = new Customer() { CustomerId = customer.CustomerId, Version = customer.Version.ToTimestamp() }; dbCustomer.EntityKey = db.CreateEntityKey(setname, dbCustomer); db.AttachTo(setname, dbCustomer); } dbCustomer.Name = customer.Name; dbCustomer.FirstName = customer.FirstName; dbCustomer.Title = customer.Title; if (isNew) { db.AddToCustomerSet(dbCustomer); } db.SaveChanges(); customer.CustomerId = dbCustomer.CustomerId; return(dbCustomer.CustomerId); } catch (OptimisticConcurrencyException ex) { if (ExceptionPolicy.HandleException(ex, "DA Policy")) { throw; } return(default(int)); } }
public int SaveCustomer(HsrOrderApp.BL.DomainModel.Customer customer) { try { Customer dbCustomer = new Customer(); bool isNew = false; if (customer.CustomerId == default(int) || customer.CustomerId <= 0) { isNew = true; } dbCustomer.CustomerId = customer.CustomerId; dbCustomer.Version = customer.Version.ToTimestamp(); dbCustomer.Name = customer.Name; dbCustomer.FirstName = customer.FirstName; dbCustomer.Title = customer.Title; if (isNew) { db.Customers.InsertOnSubmit(dbCustomer); } else { db.Customers.Attach(dbCustomer, true); } db.SubmitChanges(); customer.CustomerId = dbCustomer.CustomerId; return(dbCustomer.CustomerId); } catch (ChangeConflictException ex) { if (ExceptionPolicy.HandleException(ex, "DA Policy")) { throw; } return(default(int)); } }