Exemplo n.º 1
0
        public bool lagreBestilling(bestilling innBestilling)
        {
            using (var db = new DB())
            {
                Bestilling bestilling = new Bestilling()
                {
                    fraStasjon  = innBestilling.fraStasjon,
                    tilStasjon  = innBestilling.tilStasjon,
                    dato        = innBestilling.dato,
                    returDato   = innBestilling.returDato,
                    avgang      = innBestilling.avgang,
                    returAvgang = innBestilling.returAvgang,
                    epost       = innBestilling.epost
                };

                try
                {
                    db.Bestilling.Add(bestilling);
                    db.SaveChanges();
                    return(true);
                }

                catch (Exception)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
        public int CreateOrder(Bestilling order)
        {
            decimal orderTotal = 0;
            var     cartItems  = GetCartItems();

            // Iterate over the items in the cart,
            // adding the order details for each
            foreach (var item in cartItems)
            {
                var orderDetail = new Bestiltprodukt
                {
                    produktid    = item.produktid,
                    bestillingid = order.bestillingsid,
                    pris         = item.produkt.pris,
                    antall       = item.antall
                };
                // Set the order total of the shopping cart
                orderTotal += (item.antall * item.produkt.pris);
                storeDB.bestilteprodukter.Add(orderDetail);
            }
            // Set the order's total to the orderTotal count
            order.total = orderTotal;
            // Save the order
            storeDB.SaveChanges();
            // Empty the shopping cart
            EmptyCart();
            // Return the OrderId as the confirmation number
            return(order.bestillingsid);
        }
Exemplo n.º 3
0
        public int bestillVare(int kundeid, int vareid)
        {
            Bestilling nyBestilling = new Bestilling();

            nyBestilling.tid = DateTime.Now;
            Kunde k = db.Kunder.FirstOrDefault(kunde => kunde.kundeID == kundeid);

            nyBestilling.kundeID = k;//koble til kunde
            Vare v = db.Varer.FirstOrDefault(vare => vare.vareID == vareid);

            nyBestilling.vareID = v;//koble til vare
            db.Bestillinger.Add(nyBestilling);
            db.SaveChanges();

            return(nyBestilling.ordreID);
        }
Exemplo n.º 4
0
        public bool slettordre(int id)
        {
            var        db    = new Kundecontext();
            Bestilling kunde = db.bestillingene.Find(id);

            if (kunde == null)
            {
                return(false);
            }
            else
            {
                db.bestillingene.Remove(kunde);
                db.SaveChanges();
                return(true);
            }
        }