public bool endreBestilling(int id, Bestilling bestilling)
 {
     if (id == 0)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
 public List<Bestilling> hentAlleBestillinger()
 {
     var bestillingListe = new List<Bestilling>();
     var bestilling = new Bestilling()
     {
         BestillingID = 1,
         Total = 23,
         OrdreDato = DateTime.Now,
         Vare = new Vare() { Varenavn = "Eple", Pris = 12, Varebeholdning = 77}
     };
     bestillingListe.Add(bestilling);
     bestillingListe.Add(bestilling);
     bestillingListe.Add(bestilling);
     return bestillingListe;
 }
 public bool leggTilBestilling(int id)
 {
     using (var context = new ButikkContext())
     {
         VareDAL vare = new VareDAL();
         Vare nyvare = vare.hentEnVare(id);
         var bestilling = new Bestilling()
         {
             OrdreDato = System.DateTime.Now,
             Total = nyvare.Pris,
             Vare = nyvare
         };
         context.Bestillinger.Add(bestilling);
         var saved = context.SaveChanges();
         return saved >= 1;
     }
 }
        public bool endreBestilling(int id, Bestilling bestilling)
        {
            var db = new ButikkContext();

            try
            {
                Bestilling endreBestilling = db.Bestillinger.Find(id);
                endreBestilling.OrdreDato = bestilling.OrdreDato;
                endreBestilling.Total = bestilling.Total;
                endreBestilling.Vare = bestilling.Vare;

                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public Bestilling hentEnBestilling(int id)
        {
            var db = new ButikkContext();
            var enDbBestilling = db.Bestillinger.Find(id);

            if (enDbBestilling == null)
            {
                return null;
            }
            else
            {
                var utBestilling = new Bestilling()
                {
                    OrdreDato = enDbBestilling.OrdreDato,
                    Total = enDbBestilling.Total,
                    Vare = enDbBestilling.Vare
                };
                return utBestilling;
            }
        }
 public Bestilling hentEnBestilling(int id)
 {
     if(id == 0)
     {
         var bestilling = new Bestilling();
         bestilling.BestillingID = 0;
         return bestilling;
     }
     else
     {
         var bestilling = new Bestilling()
         {
             BestillingID = 1,
             Total = 23,
             OrdreDato = DateTime.Now,
             Vare = new Vare() { Varenavn = "Eple", Pris = 12, Varebeholdning = 77 }
         };
         return bestilling;
     }
 }
 public ActionResult endreBestilling(int id, Bestilling endreBestilling)
 {
     if(ModelState.IsValid)
     {
         var bestilling = new BestillingBLL();
         bool endringOk = bestilling.endreBestilling(id, endreBestilling);
         if(endringOk)
         {
             return RedirectToAction("BestillingListe");
         }
     }
     return View();
 }
 public ActionResult slettBestilling(int id, Bestilling slettBestilling)
 {
     var bestillingDb = new BestillingBLL();
     bool slettOk = bestillingDb.slettBestilling(id);
     if(slettOk)
     {
         return RedirectToAction("BestillingListe");
     }
     return View();
 }
        public void Registrer_feil_modell()
        {
            var controller = new BestillingController(new BestillingBLL(new BestillingDALStub()));
            var forventetBestilling = new Bestilling();
            /*controller.ViewData.ModelState.AddModelError("Total", "Ikke oppgitt total");

            // Act
            var actionResult = (ViewResult)controller.RegistrerBestilling(forventetBestilling);

            // Assert
            Assert.IsTrue(actionResult.ViewData.ModelState.Count == 1);
            Assert.AreEqual(actionResult.ViewName, "");*/
        }
        public void Registrer_feil_db()
        {
            var controller = new BestillingController(new BestillingBLL(new BestillingDALStub()));
            var forventetBestilling = new Bestilling();
            /*forventetBestilling.Vare.Varenavn = "";

            // Act
            var actionResult = (ViewResult)controller.RegistrerBestilling(forventetBestilling);

            // Assert
            Assert.AreEqual(actionResult.ViewName, "");*/
        }
 public bool endreBestilling(int id, Bestilling innBestilling)
 {
     var BestillingDAL = new DAL.BestillingDAL();
     return BestillingDAL.endreBestilling(id, innBestilling);
 }