Example #1
0
 public List <Order> Get(int customerId)
 {
     using (var context = new DemoContextFactory().Create())
     {
         _orders = context.Orders.ToList();
         return(_orders.Where(c => c.Customer.CustomerId == customerId).ToList());
     }
 }
Example #2
0
 public List <Order> Get()
 {
     using (var context = new DemoContextFactory().Create())
     {
         _orders = context.Orders.Include(a => a.Customer).ToList();
     }
     return(_orders);
 }
 public Customer Get(int id)
 {
     using (var context = new DemoContextFactory().Create())
     {
         _customers = context.Customers.ToList();
     }
     return(_customers.Single(cust => cust.CustomerId == id));
 }
 public List <Customer> Get()
 {
     using (var context = new DemoContextFactory().Create())
     {
         _customers = context.Customers.ToList();
     }
     return(_customers);
 }
        public Customer Add(Customer customer)
        {
            using (var context = new DemoContextFactory().Create())
            {
                _customers.Add(customer);
                context.SaveChanges();
            }

            //todo: add Id field
            return(customer);
        }
        public Customer Delete(int id)
        {
            Customer itemToRemove;

            using (var context = new DemoContextFactory().Create())
            {
                _customers = context.Customers.ToList();

                itemToRemove = _customers.SingleOrDefault(c => c.CustomerId == id);

                if (itemToRemove != null)
                {
                    //_customers.Remove(itemToRemove);
                    context.Customers.Remove(itemToRemove);
                    context.SaveChanges();
                }
            }
            return(itemToRemove);
        }