Exemple #1
0
        internal Bestillinger BuildBestillingModells(BestillingViewModel bestilling, DB db)
        {
            bestilling_VM = bestilling;
            DateTime kombinert_dato =
                bestilling_VM.reise_dato.Date.Add(bestilling_VM.reise_dato_tid.TimeOfDay);


            bestillinger = new Bestillinger
            {
                fra        = bestilling_VM.fra,
                til        = bestilling_VM.til,
                reise_dato = kombinert_dato,

                bestilling_dato = DateTime.Now,
                total_pris      = 0,
                billett_liste   = new List <Billetter>()
            };
            BuildBilletter("Barn", bestilling_VM.antall_barn);
            BuildBilletter("Student", bestilling_VM.antall_studenter);
            BuildBilletter("Voksen", bestilling_VM.antall_voksne);
            bestillinger.total_pris = MappingUtillity.BeregnBestillingPris(bestillinger);

            try
            {
                db.Bestillinger.Add(bestillinger);
                db.SaveChanges();
                return(bestillinger);
            }
            catch (Exception feil)
            {
                return(null);

                System.Diagnostics.Debug.WriteLine("feil");
            }
        }
        public string ajaxtestinn(BestillingViewModel bestilling)
        {
            System.Diagnostics.Debug.WriteLine(" ajaxtestinn " + bestilling.reise_dato);
            var jsonSerializer = new JavaScriptSerializer();

            return(jsonSerializer.Serialize("bestilling date " + bestilling.reise_dato));
        }
        public ActionResult Index(BestillingViewModel bestilling)
        {
            if (!(bestilling.antall_barn.HasValue || bestilling.antall_studenter.HasValue || bestilling.antall_voksne.HasValue))
            {
                return(View());
            }
            List <Bestillinger> bestillinger_liste = new List <Bestillinger>();
            Bestillinger        bestilling_utreise;
            Bestillinger        bestilling_retur;

            if (ModelState.IsValid)
            {
                var md = new dbModellBygger();
                bestilling_utreise = md.BuildBestillingModells(bestilling, db);
                bestillinger_liste.Add(bestilling_utreise);

                if (bestilling.retur_dato.HasValue)
                {
                    String fra = bestilling.fra;
                    bestilling.fra            = bestilling.til;
                    bestilling.til            = fra;
                    bestilling.reise_dato     = (DateTime)bestilling.retur_dato;
                    bestilling.reise_dato_tid = (DateTime)bestilling.retur_dato_tid;
                    bestilling_retur          = md.BuildBestillingModells(bestilling, db);
                    bestillinger_liste.Add(bestilling_retur);
                }
            }

            int id = bestillinger_liste[0].bestilling_id;

            return(RedirectToAction("Bestilling_detaljer", new { id = @id }));
        }
        public bool Bestill(BestillingViewModel innkommendeBestilling)
        {
            bool success;
            var  _kunde     = KundeMapping(innkommendeBestilling);
            var  checkKunde = GetByNavn(_kunde.Navn);

            if (checkKunde == null)
            {
                success = this._kundeRepo.Insert(_kunde);
                this._kundeRepo.Save();
                if (!success)
                {
                    return(success);
                }
            }
            else
            {
                _kunde = checkKunde;
            }
            var _bestilling = BestillingMapping(innkommendeBestilling, _kunde);

            success = this._bestillingRepo.Insert(_bestilling);
            this._bestillingRepo.Save();
            return(success);
        }
Exemple #5
0
        public void GenererReferanseMedRiktigModell()
        {
            var controller = NyHomeControllerMedSession();

            controller.Session["GjeldendeBestilling"] = new BestillingViewModel()
            {
                Tur = GenererNyReise()
            };

            var model = new BestillingViewModel()
            {
                Kredittkort = new KredittkortViewModel()
                {
                    CVC        = 123,
                    Kortholder = "Ola Nordmann",
                    Kortnummer = 1234567891234567,
                    Utlop      = "11-21"
                }
            };
            var faktisk = (RedirectToRouteResult)controller.GenererReferanse(model);

            var tempData = (Bestilling)controller.TempData["bestilling"];

            Assert.IsTrue(faktisk.RouteValues.ContainsKey("action"));
            Assert.AreEqual("Kvittering", faktisk.RouteValues["action"]);
        }
Exemple #6
0
        // GET: Bestilling/Create
        public ActionResult Create()
        {
            BrugerModel bruger = new BrugerModel();

            if (User.Identity.IsAuthenticated)
            {
                try
                {
                    bruger = _dataBasen.HentBruger(User.Identity.Name);
                }
                catch
                {
                    bruger.Brugernavn = "DetHerKommerTilAtGåGalt";
                }


                BestillingViewModel bestillingView = new BestillingViewModel {
                    Brugernavn = bruger.Brugernavn, Meddelelse = "Velkommen " + bruger.Navn
                };
                return(View(bestillingView));
            }
            else
            {
                return(RedirectToAction("Login", "Bruger"));
            }
        }
        public ActionResult GenererReferanse(BestillingViewModel kredittkortInformasjon)
        {
            if (!ModelState.IsValid)
            {
                return(View("BetalingFeilet"));
            }
            else
            {
                string CVCstring = kredittkortInformasjon.Kredittkort.CVC + "";
                string utlop     = kredittkortInformasjon.Kredittkort.Utlop;
                string feilmelding;
                bool   gyldig = bllbestilling.VerifiserKredittkort(CVCstring, utlop, out feilmelding);
                if (!gyldig)
                {
                    ViewBag.Feilmelding = feilmelding;
                    return(View("BetalingFeilet"));
                }
            }

            var kunder = (List <Kunde>)Session["KunderBestilling"];
            //Denne inneholder informasjon om Tur- og Retur-property
            var gjeldende = (BestillingViewModel)Session["GjeldendeBestilling"];

            TempData["bestilling"] = bllbestilling.LeggInn(kunder, gjeldende);
            return(RedirectToAction("Kvittering"));
        }
        private Kunde KundeMapping(BestillingViewModel bestilling)
        {
            var kunde = new Kunde()
            {
                Navn      = bestilling.Navn,
                Adresse   = bestilling.Adresse,
                Telefonnr = bestilling.Telefonnr
            };

            return(kunde);
        }
        private Pizza BestillingMapping(BestillingViewModel bestilling, Kunde kunde)
        {
            var outgoingBestilling = new Pizza()
            {
                PizzaType = bestilling.PizzaType,
                Antall    = bestilling.Antall,
                Tykkelse  = bestilling.Tykkelse
            };

            outgoingBestilling = KundeIdMapping(outgoingBestilling, kunde);
            return(outgoingBestilling);
        }
 public ActionResult Bestill(BestillingViewModel innkommendeBestilling)
 {
     if (ModelState.IsValid)
     {
         this._dbLogic = new DBLogic();
         bool insertOK = this._dbLogic.Bestill(innkommendeBestilling);
         if (insertOK)
         {
             return(RedirectToAction("Bestillinger"));
         }
     }
     return(View("Bestilling"));
 }
        public ActionResult ValgtReise(string turIndeks, string returIndeks)
        {
            var turListe   = (List <Reise>)Session["turListe"];
            var returListe = (List <Reise>)Session["returListe"];

            if (turListe == null || returListe == null)
            {
                return(RedirectToAction("Sok"));
            }

            int turIndeksInt   = int.Parse(turIndeks);
            int returIndeksInt = -1; //Hvis returindeks er -1 antar vi at man kun skal ha en-veis-tur

            if (returIndeks != null)
            {
                returIndeksInt = int.Parse(returIndeks);
            }

            if (turIndeksInt < 0 || turIndeksInt >= turListe.Count)
            {
                return(RedirectToAction("Sok"));
            }
            if (returIndeksInt < -1 || returIndeksInt >= returListe.Count)
            {
                return(RedirectToAction("Sok"));
            }


            int antallBilletter = (int)Session["antallbilletter"];
            var kunde           = new List <Kunde>();

            for (var i = 0; i < antallBilletter; i++)
            {
                kunde.Add(new Kunde());
            }

            var bestillingsdata = new BestillingViewModel()
            {
                Tur    = turListe[turIndeksInt],
                Kunder = kunde
            };

            if (returIndeksInt >= 0)
            {
                bestillingsdata.Retur = returListe[returIndeksInt];
            }

            Session["GjeldendeBestilling"] = bestillingsdata;
            return(View("BestillingDetaljer", bestillingsdata));
        }
Exemple #12
0
        public void GenererReferanseMedFeilModell()
        {
            var controller = NyHomeControllerMedSession();

            var model = new BestillingViewModel()
            {
                Kredittkort = new KredittkortViewModel()
            };

            controller.ViewData.ModelState.AddModelError("Kortholder", "Ikke oppgitt fornavn");

            var faktisk = (ViewResult)controller.GenererReferanse(model);

            Assert.AreEqual("BetalingFeilet", faktisk.ViewName);
        }
Exemple #13
0
        // GET: Bestilling/Create
        public ActionResult Create()
        {
            BrugerModel login = _login.GetLogin();

            if (login == null)
            {
                return(RedirectToAction("Login", "Bruger"));
            }
            else
            {
                string brugernavn = Request.HttpContext.Session.GetString("login");
                BestillingViewModel bestillingView = new BestillingViewModel {
                    Brugernavn = login.Brugernavn, Meddelelse = "Velkommen " + login.Navn
                };
                return(View(bestillingView));
            }
        }
Exemple #14
0
        public Bestilling LeggInn(List <Kunde> kunder, BestillingViewModel gjeldende)
        {
            var bestilling = new Bestilling()
            {
                Bestillingstidspunkt = DateTime.Now,
                FlygningerTur        = new List <Flygning>(),
                Passasjerer          = kunder,
                Totalpris            = gjeldende.Totalpris
            };

            do //Lag en unik UUID helt til det ikke finnes i databasen fra før.
            {
                bestilling.Referanse = Guid.NewGuid().ToString().ToUpper().Substring(0, 6);
            } while (dbBestilling.Hent(bestilling.Referanse) != null);


            foreach (var flygning in gjeldende.Tur.Flygninger)
            {
                Flygning dbFlygning = dbflygning.Finn(flygning.ID);
                if (dbFlygning == null)
                {
                    throw new InvalidOperationException("Ugyldig flygning");                     //Det skjedde en feil
                }
                bestilling.FlygningerTur.Add(dbFlygning);
            }

            if (gjeldende.Retur != null)
            {
                bestilling.FlygningerRetur = new List <Flygning>();
                foreach (var flygning in gjeldende.Retur.Flygninger)
                {
                    var dbFlygning = dbflygning.Finn(flygning.ID);
                    if (dbFlygning == null)
                    {
                        throw new InvalidOperationException("Ugyldig flygning");
                    }

                    bestilling.FlygningerRetur.Add(dbFlygning);
                }
            }

            dbBestilling.LeggInn(bestilling);


            return(bestilling);
        }
Exemple #15
0
        public void GenererReferanseMedUgyldigKredittkort()
        {
            var controller = NyHomeControllerMedSession();

            var model = new BestillingViewModel()
            {
                Kredittkort = new KredittkortViewModel()
                {
                    CVC        = 123,
                    Kortholder = "",
                    Kortnummer = 1,
                    Utlop      = ""
                }
            };

            var faktisk = (ViewResult)controller.GenererReferanse(model);

            Assert.AreEqual("BetalingFeilet", faktisk.ViewName);
            Assert.IsNotNull(faktisk.ViewBag.Feilmelding);
        }
Exemple #16
0
        public ActionResult Create(BestillingViewModel bestillingView)
        {
            bestillingView.Meddelelse = "";

            BrugerModel login = _login.GetLogin();

            BestillingModel bestilling = new BestillingModel
            {
                Brugernavn           = bestillingView.Brugernavn,
                AntalMargherita      = bestillingView.AntalMargherita,
                AntalCapricciosa     = bestillingView.AntalCapricciosa,
                AntalQuattroStagioni = bestillingView.AntalQuattroStagioni
            };

            try
            {
                _dataBasen.OpretBestilling(bestilling);
            }
            catch (DataBasenException dbe)
            {
                switch (dbe.Message)
                {
                case "Brugernavn ukendt":
                    bestillingView.Meddelelse = "Brugernavnet findes ikke. Opret brugeren før du bestiller.";
                    break;

                case "Brugernavn mangler":
                    bestillingView.Meddelelse = "Husk at udfylde Brugernavn.";
                    break;

                default:
                    bestillingView.Meddelelse = dbe.Message;
                    break;
                }
                return(View(bestillingView));
            }
            catch (Exception e)
            {
                bestillingView.Meddelelse = e.Message;
                return(View(bestillingView));
            }

            StringBuilder tekst = new StringBuilder();

            tekst.AppendLine("Ny bestilling fra kl " + DateTime.Now.ToShortTimeString());
            tekst.AppendFormat("Antal Margherita: {0}", bestilling.AntalMargherita).AppendLine();
            tekst.AppendFormat("Antal Capricciosa: {0}", bestilling.AntalCapricciosa).AppendLine();
            tekst.AppendFormat("Antal Quattro Stagioni: {0}", bestilling.AntalQuattroStagioni).AppendLine();
            tekst.AppendLine();
            tekst.AppendLine("Bestillingen skal sendes til");
            tekst.AppendLine(login.Navn);
            tekst.AppendLine(login.Gade);
            tekst.AppendLine(login.Postnummer.ToString() + " " + login.Bynavn);

            try
            {
                _emailService.SendEmail("*****@*****.**", "Ny bestilling", tekst.ToString()).Wait();
            }
            catch (Exception)
            {
                bestillingView.Meddelelse = "kokken har ikke modtaget din bestiling.";
            }

            return(RedirectToAction(nameof(Bestilt)));
        }