//BESTILLINGER public List <BestillingView> hentAlleBestillinger() { try { using (var db = new AirlineDbContext()) { List <Handel> alleBestillinger = db.Handler.ToList(); List <BestillingView> bestillingsListe = new List <BestillingView>(); foreach (var bestilling in alleBestillinger) { BestillingView nyBestilling = new BestillingView { HandelId = bestilling.HandelId, Eier = bestilling.Kunde.Fornavn + " " + bestilling.Kunde.Etternavn, AntallBilletter = bestilling.Billetter.Count, TotalPris = bestilling.TotalPris }; bestillingsListe.Add(nyBestilling); } return(bestillingsListe); } } catch (Exception error) { string feilmelding = DateTime.Now.ToString() + " " + error.ToString() + "\n\r"; File.AppendAllText(HttpContext.Current.Server.MapPath("~/Logger/Registreringer.txt"), feilmelding); List <BestillingView> bestillingsListe = new List <BestillingView>(); return(bestillingsListe); } }
public ActionResult Lagre(BestillingView bestillingModel) { // Sjekk hvis kunden eksisterer var dbKunde = db.Kunder.SingleOrDefault(k => k.Navn == bestillingModel.Bestilling.Kunde.Navn); if (dbKunde == null) { //Opprett kunde objekt Kunde kunde = bestillingModel.Bestilling.Kunde; db.Kunder.Add(kunde); db.SaveChanges(); db.Bestillinger.Add(bestillingModel.Bestilling); db.SaveChanges(); return(RedirectToAction("Liste")); } else { int kundeId = dbKunde.Id; var bestilling = new Bestilling { PizzaType = bestillingModel.Bestilling.PizzaType, Tykkelse = bestillingModel.Bestilling.Tykkelse, Antall = bestillingModel.Bestilling.Antall, KundeId = kundeId }; db.Bestillinger.Add(bestilling); db.SaveChanges(); return(RedirectToAction("Liste")); } }
public ActionResult Register() { var bestilling = new Bestilling(); List <String> pizzaTypes = new List <string> { "Margherita (kr 100)", "Primavera (kr 150)", "IndiaVolata (kr 200)" }; BestillingView bestillingViewModel = new BestillingView(bestilling, pizzaTypes); return(View(bestillingViewModel)); }
//Bestillinger og billetter public List <BestillingView> hentAlleBestillinger() { //Dummy metode for at InterFace implementasjon skal være OK, //Må endre før testing. List <BestillingView> liste = new List <BestillingView>(); BestillingView best = new BestillingView() { AntallBilletter = 2, Eier = "Donal Duck", HandelId = 1, TotalPris = 598 }; liste.Add(best); liste.Add(best); liste.Add(best); return(liste); }