コード例 #1
0
 public bool UpdateOrder(Order o)
 {
     using (Entities1 entities = new Entities1())
     {
         Order updateOrder = entities.Orders.SingleOrDefault(o2 => o2.Id == o.Id);
         if (updateOrder.Id > 0)
         {
             updateOrder.Date        = o.Date;
             updateOrder.Price       = o.Price;
             updateOrder.Customer_Id = o.Customer_Id;
             entities.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
 public bool RemoveOrder(int orderId)
 {
     using (Entities1 entities = new Entities1())
     {
         if (entities.Orders.Any(o => o.Id == orderId))
         {
             entities.Orders.Remove(entities.Orders.Single(o1 => o1.Id == orderId));
             int res = entities.SaveChanges();
             if (res > 0)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #3
0
 public bool UpdateCustomer(Customer c)
 {
     using (Entities1 entities = new Entities1())
     {
         Customer updateCustomer = entities.Customers.SingleOrDefault(c2 => c2.Id == c.Id);
         if (updateCustomer.Id > 0)
         {
             updateCustomer.Age     = c.Age;
             updateCustomer.Country = c.Country;
             updateCustomer.Name    = c.Name;
             entities.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
 public bool RemoveCustomer(int customerId)
 {
     using (Entities1 entities = new Entities1())
     {
         if (entities.Customers.Any(c => c.Id == customerId))
         {
             var orders = entities.Orders.Where(o => o.Customer_Id == customerId).ToList();
             orders.ForEach(o => entities.Orders.Remove(o));
             entities.Customers.Remove(entities.Customers.Single(c => c.Id == customerId));
             int res = entities.SaveChanges();
             if (res > 0)
             {
                 return(true);
             }
         }
     }
     return(false);
 }