Ejemplo n.º 1
0
        public void OrderProduct(Product p, int amount)
        {
            // Create an order

            // Sets datetime variable for date and estDelivery. As DateTime can't be null so we set
            // the property to the same thing. If they are the same, that means estDilevery has not been set
            DateTime now = DateTime.Now;

            // EnumStatus: I am using the built in EnumStatus' and do a toString on them as the DB takes a string
            Order o = new Order(p.Id, p.SupplierId, ToString(), amount, now, now);

            // Insert order
            PersistencyService.InsertOrder(o);
        }
Ejemplo n.º 2
0
        public void OrderProduct(Product p, int amount)
        {
            // Makes sure you can't order 0 or a negative amount of products
            if (amount <= 0)
            {
                throw new ArgumentException("Du skal bestille mindst èt produkt");
            }

            // Create an order

            // Sets datetime variable for date and estDelivery. As DateTime can't be null so we set
            // the property to the same thing. If they are the same, that means estDilevery has not been set
            DateTime now = DateTime.Now;

            // EnumStatus: I am using the built in EnumStatus' and do a toString on them as the DB takes a string
            Order o = new Order(p.Id, p.SupplierId, "På vej", amount, now, now);


            // Insert order
            try
            {
                // Add to db, returns id if succesful, returns 0 if fail
                o.Id = PersistencyService.InsertOrder(o).Result;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }

            // Set the product supplier on Order
            o.Supplier = p.Supplier;

            if (p.OrderList == null)
            {
                p.OrderList = new ObservableCollection <Order>();
            }

            p.OrderList.Add(o);
        }