Beispiel #1
0
 public Customer GetCustomerById(int customerId)
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         return entities.Customer.FirstOrDefault(c => c.ID == customerId);
     }  
 }
Beispiel #2
0
 public List<Order> GetAllOrders()
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         entities.Order.ToList().ForEach(o => Console.WriteLine(JsonConvert.SerializeObject(o)));
         return entities.Order.ToList();
     }
 }
Beispiel #3
0
 public List<Order> GetAllOrdersByCustomerId(int customerId)
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         entities.Order.Where(o => o.CUSTOMER_ID == customerId).ToList().ForEach(o => Console.WriteLine(JsonConvert.SerializeObject(o)));
         return entities.Order.ToList();
     }
 }
Beispiel #4
0
 public Order GetOrderById(int orderId)
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         List<Order> orders = entities.Order.Where(o => o.ID == orderId).ToList();
         return orders[0];
     }
 }
Beispiel #5
0
 public List<OrderCustomer> GetAllOrdersCustomer()
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         List<OrderCustomer> orders = new List<OrderCustomer>();
         entities.Customer.Join(entities.Order, o => o.ID, c => c.CUSTOMER_ID, (c, o)
             => new
             {
                 c.NAME,
                 o.CUSTOMER_ID,
                 o.ID,
                 o.PRICE,
                 o.DATE
             }).ToList().ForEach(co => orders.Add(new OrderCustomer(co.NAME, co.CUSTOMER_ID, co.ID, co.PRICE, co.DATE)));                
         orders.ForEach(co => Console.WriteLine(JsonConvert.SerializeObject(co)));
         return orders;
     }
 }
Beispiel #6
0
 public bool AddOrder(Order o)
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         try
         {
             entities.Order.Add(o);
             entities.SaveChanges();
             Console.WriteLine($"Order {o.ID} Added successfully");
             return true;
         }
         catch (Exception)
         {
             Console.WriteLine($"can't add this order {o.ID}");
             return false;
         }
     }
 }
Beispiel #7
0
 public bool UpdateOrder(Order o, int price)
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         try
         {
             entities.Order.Take(1).FirstOrDefault().PRICE = price;
             entities.SaveChanges();
             Console.WriteLine($"order price update successfully");
             return true;
         }
         catch (Exception)
         {
             Console.WriteLine($"can't update order");
             return false;
         }
     }
 }
Beispiel #8
0
 public bool UpdateCustomer(Customer c, string newName)
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         try
         {
             entities.Customer.Take(1).FirstOrDefault().NAME = $"{newName}"; 
             entities.SaveChanges();
             Console.WriteLine($"Customer name update successfully");
             return true;
         }
         catch (Exception)
         {
             Console.WriteLine($"can't update customer");
             return false;
         }
     }
 }
Beispiel #9
0
 public bool RemoveOrder(int orderId)
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         try
         {
             entities.Order.Remove(entities.Order.FirstOrDefault(o => o.ID == orderId));
             entities.SaveChanges();
             Console.WriteLine($"Order id {orderId} removed successfully");
             return true;
         }
         catch (Exception)
         {
             Console.WriteLine($"can't remove order id {orderId}");
             return false;
         }
     }
 }
Beispiel #10
0
 public bool RemoveCustomer(int customerId)
 {
     using (TargilsicumEntities entities = new TargilsicumEntities())
     {
         try
         {
             entities.Customer.Remove(entities.Customer.FirstOrDefault(c => c.ID == customerId));                    
             entities.SaveChanges();
             Console.WriteLine($"Customer id {customerId} removed successfully");
             return true;                    
         }
         catch (Exception)
         {
             Console.WriteLine($"can't remove customer id {customerId}");
             return false;
         }
     }
 }
Beispiel #11
0
        public bool AddCustomer(Customer c)
        {
            using (TargilsicumEntities entities = new TargilsicumEntities())
            {
                try
                {
                    entities.Customer.Add(c);
                    entities.SaveChanges();
                    Console.WriteLine($"Customer {c.NAME} Added successfully");
                    return true;
                }
                catch (Exception)
                {
                    Console.WriteLine($"can't add this customer name {c.NAME}");
                    return false;
                }

            }
        }