Пример #1
0
        public void OpretBestilling(BestillingModel bestilling)
        {
            if (bestilling.Brugernavn == null | bestilling.Brugernavn == "")
            {
                throw new DataBasenException("Brugernavn mangler");
            }

            if (_brugere.ContainsKey(bestilling.Brugernavn))
            {
                _bestillinger.Add(Guid.NewGuid(), bestilling);
                return;
            }
            else
            {
                throw new DataBasenException("Brugernavn ukendt");
            }
        }
Пример #2
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)));
        }