Ejemplo n.º 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();
     }
 }
Ejemplo n.º 2
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();
     }
 }
Ejemplo n.º 3
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();
     }
 }
Ejemplo n.º 4
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();
     }
 }