Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }