Exemple #1
0
 public List <Customer> GetAllCustomers()
 {
     using (var context = new OrderSystemContext())
     {
         return(context.Customers.AsNoTracking().ToList());
     }
 }
Exemple #2
0
 public void RemoveCustomer(int id)
 {
     using (var context = new OrderSystemContext())
     {
         context.Customers.Remove(context.Customers.Find(id));
         context.SaveChanges();
     }
 }
Exemple #3
0
 public void UpdateCustomer(Customer customer)
 {
     using (var context = new OrderSystemContext())
     {
         context.Entry(customer).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemple #4
0
 public void AddCustomer(Customer customer)
 {
     using (var context = new OrderSystemContext())
     {
         context.Customers.Add(customer);
         context.SaveChanges();
     }
 }
Exemple #5
0
 public Customer FindCustomer(int?id)
 {
     using (var context = new OrderSystemContext())
     {
         return(context.Customers
                .AsNoTracking()
                .SingleOrDefault(c => c.CustomerId == id));
     }
 }
 public List <CustomerViewModel> GetAllCustomers()
 {
     using (var context = new OrderSystemContext())
     {
         return(context.Customers.AsNoTracking()
                .Select(c => new CustomerViewModel
         {
             CustomerId = c.CustomerId,
             Name = c.FirstName + " " + c.LastName,
             OrderCount = c.Orders.Count()
         })
                .ToList());
     }
 }
 public CustomerViewModel FindCustomer(int?id)
 {
     using (var context = new OrderSystemContext())
     {
         var cust =
             context.Customers.AsNoTracking()
             .Select(c => new CustomerViewModel
         {
             CustomerId = c.CustomerId,
             Name       = c.FirstName + " " + c.LastName,
             OrderCount = c.Orders.Count(),
             Orders     = c.Orders.Select(
                 o => new OrderViewModel
             {
                 OrderSource = o.OrderSource,
                 CustomerId  = o.CustomerId,
                 OrderDate   = o.OrderDate
             }).ToList()
         }).FirstOrDefault(c => c.CustomerId == id);
         return(cust);
     }
 }
Exemple #8
0
 public UOWWrappingGenericRepos()
 {
     _context = new OrderSystemContext();
 }
Exemple #9
0
 public UOW()
 {
     _context = new OrderSystemContext();
 }
Exemple #10
0
 public CustomerWithOrdersData_DI(OrderSystemContext context)
 {
     _context = context;
 }