public void UpdateCustomer(int oldCustomerId, Customer newCustomer) { ShippingAddressRepository repository = new ShippingAddressRepository(StoreDbContext); var address = repository.CheckForAddress(newCustomer.ShippingAddress); var customer = StoreDbContext.Customers.Include(x => x.ShippingAddress).Single(x => x.Id == oldCustomerId); customer.Name = newCustomer.Name; customer.Email = newCustomer.Email; customer.Phone = newCustomer.Phone; customer.ShippingAddress = address; }
public override void Add(Customer entity) { ShippingAddressRepository repository = new ShippingAddressRepository(StoreDbContext); var shippingAddress = repository.CheckForAddress(entity.ShippingAddress); if (shippingAddress == null) { base.Add(entity); return; } entity.ShippingAddress = shippingAddress; shippingAddress.Customers.Add(entity); base.Add(entity); }
public override void AddRange(IEnumerable <Customer> entities) { HashSet <Customer> customers = new HashSet <Customer>(); ShippingAddressRepository repository = new ShippingAddressRepository(StoreDbContext); foreach (Customer entity in entities) { var shippingAddress = repository.CheckForAddress(entity.ShippingAddress); if (shippingAddress != null) { entity.ShippingAddress = shippingAddress; shippingAddress.Customers.Add(entity); } customers.Add(entity); } base.AddRange(customers); }