Ejemplo n.º 1
0
 public void UpdateCustomer(Customer customer)
 {
     using (var context = new MarketContext())
     {
         context.Entry(customer).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public void RemoveCustomer(int id)
 {
     using (var context = new MarketContext())
     {
         context.Customers.Remove(context.Customers.Find(id));
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void AddCustomer(Customer customer)
 {
     using (var context = new MarketContext())
     {
         context.Customers.Add(customer);
         context.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 public Customer FindCustomer(int?id)
 {
     using (var context = new MarketContext())
     {
         return(context.Customers
                .AsNoTracking()
                .SingleOrDefault(c => c.CustomerId == id));
     }
 }
Ejemplo n.º 5
0
 public List <CustomerViewModel> GetAllCustomers()
 {
     using (var context = new MarketContext())
     {
         return(context.Customers.AsNoTracking()
                .Select(c => new CustomerViewModel
         {
             CustomerId = c.CustomerId,
             Name = c.FirstName + " " + c.LastName,
             OrderCount = c.Orders.Count()
         })
                .ToList());
     }
 }
Ejemplo n.º 6
0
 public Customer FindCustomer(int?id)
 {
     using (var context = new MarketContext())
     {
         try
         {
             return(context.Customers
                    .AsNoTracking()
                    .SingleOrDefault(c => c.CustomerId == id));
         }
         catch (System.Exception ex)
         {
             throw;
         }
     }
 }
Ejemplo n.º 7
0
 public CustomerViewModel FindCustomer(int?id)
 {
     using (var context = new MarketContext())
     {
         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);
     }
 }
 public WebSiteOrderData(MarketContext context)
 {
     _context = context;
 }
Ejemplo n.º 9
0
 public UowWrappingGenericRepos()
 {
     _context = new MarketContext();
 }