Example #1
0
 /// <summary>
 /// Place an order to the database
 /// </summary>
 /// <param name="customer">id of customer placeing order</param>
 /// <param name="order">object containing the list of order items</param>
 public static void AddOrder(int customer, IOrderList order)
 {
     using (var context = new POneContext(connection))
     {
         decimal price = 0;
         foreach (var orderdata in order.Cart)
         {
             price += orderdata.Price * orderdata.Quantity;
         }
         var ticket = new Orders
         {
             CustId    = customer,
             Total     = price,
             Stamp     = DateTime.Now,
             OrderData = order.Cart
         };
         foreach (var orderdata in order.Cart)
         {
             context.Products.Find(orderdata.PrdId).Stock -= orderdata.Quantity;
             orderdata.OrdId = ticket.OrdId;
         }
         context.Add(ticket);
         context.SaveChanges();
     }
 }
Example #2
0
 /// <summary>
 /// remove a customer from the database
 /// </summary>
 /// <param name="ID">id of customer</param>
 public static void RemoveCustomer(int ID)
 {
     using (var context = new POneContext(connection))
     {
         context.Customers.Remove(context.Customers.Find(ID));
         context.SaveChanges();
     }
 }
Example #3
0
 /// <summary>
 /// remove a store from the database
 /// only works when the store has no products
 /// </summary>
 /// <param name="activeStore">id of store</param>
 public static void RemoveStore(int activeStore)
 {
     using (var context = new POneContext(connection))
     {
         context.Locations.Remove(context.Locations.Find(activeStore));
         context.SaveChanges();
     }
 }
Example #4
0
 /// <summary>
 /// increce the stock of an item
 /// </summary>
 /// <param name="ID">items id</param>
 /// <param name="stock">quantity to9 add</param>
 public static void StockProduct(int ID, int stock)
 {
     using (var context = new POneContext(connection))
     {
         context.Products.Find(ID).Stock += stock;
         context.SaveChanges();
     }
 }
Example #5
0
 /// <summary>
 /// removes a product from the database
 /// </summary>
 /// <param name="ID">id of item</param>
 public static void RemoveProduct(int ID)
 {
     using (var context = new POneContext(connection))
     {
         context.Remove(context.Products.Find(ID));
         context.SaveChanges();
     }
 }
Example #6
0
 /// <summary>
 /// Add a location to the database
 /// </summary>
 /// <param name="name">Name of location</param>
 public static void AddLocation(string name)
 {
     using (var context = new POneContext(connection))
     {
         var location = new Locations {
             Name = name
         };
         context.Add(location);
         context.SaveChanges();
     }
 }
Example #7
0
 /// <summary>
 /// add a customer to the database
 /// </summary>
 /// <param name="name">name of customer</param>
 public static void AddCustomer(string name)
 {
     using (var context = new POneContext(connection))
     {
         var customer = new Customers {
             Name = name
         };
         context.Add(customer);
         context.SaveChanges();
     }
 }
Example #8
0
 /// <summary>
 /// adds a product to the database
 /// </summary>
 /// <param name="name">name of product</param>
 /// <param name="LocID">id of products location</param>
 /// <param name="p">price of item</param>
 /// <param name="s">ctock of item</param>
 public static void AddProduct(string name, int LocID, decimal p, int s)
 {
     using (var context = new POneContext(connection))
     {
         var product = new Products
         {
             Name  = name,
             Loc   = context.Locations.Find(LocID),
             Price = p,
             Stock = s
         };
         context.Add(product);
         context.SaveChanges();
     }
 }