Ejemplo n.º 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");
            }
        }
Ejemplo n.º 2
0
        public async Task <Bestillinger> HentEn(int id)
        {
            try
            {
                Console.WriteLine(id);
                Bestillinger enBestilling = await _db.Bestillinger.FindAsync(id);

                if (enBestilling == null)
                {
                    return(null);                      //finner ikke id i DB
                }
                var hentetBestilling = new Bestillinger()
                {
                    ID    = enBestilling.ID,
                    Kunde = enBestilling.Kunde,
                    Pris  = enBestilling.Pris,
                    Tur   = enBestilling.Tur,
                    Retur = enBestilling.Retur
                };
                return(hentetBestilling);
            }
            catch (Exception e)
            {
                Log.Error("Error i HentEn: {error}", e);
                Debug.WriteLine(e.Message);
                return(null);
            }
        }
Ejemplo n.º 3
0
        public async Task <Bestilling> HentEn(int id)
        {
            try
            {
                Bestillinger enBestilling = await _db.Bestillinger.FindAsync(id);

                if (enBestilling == null)
                {
                    return(null);
                }

                var hentetBestilling = new Bestilling()
                {
                    Id   = enBestilling.Id,
                    pris = enBestilling.Pris,
                    Fra  = enBestilling.Fra,
                    Til  = enBestilling.Til,
                    Dato = enBestilling.Dato,
                    Tid  = enBestilling.Tid
                };
                return(hentetBestilling);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        public void settInnBestillingTurRetur_Feil()
        {
            //Arrange
            var controller        = new HomeController(new BestillingLogikk(new BestillingRepositoryStub()));
            var forventetResultat = new List <Bestillinger>();
            var bestilling        = new Bestillinger()
            {
                enVei_id       = 0,
                turRetur_id    = 2,
                dato           = "2019-10-24",
                datoRetur      = "2019-10-25",
                totalPris      = 1000,
                antallReisende = 1,
            };

            forventetResultat.Add(bestilling);
            forventetResultat.Add(bestilling);

            //Act
            int enVeiID    = (int)(bestilling.enVei_id);
            int turReturID = (int)(bestilling.enVei_id);
            var jsonResult = (string)controller.leggBestillingTurRetur(enVeiID, turReturID, bestilling.dato, bestilling.datoRetur, bestilling.totalPris, bestilling.antallReisende);

            //Assert
            Assert.IsNotNull(jsonResult);
            Assert.AreEqual("false", jsonResult);
        }
Ejemplo n.º 5
0
        public static double BeregnBestillingPris(Bestillinger bestillinger)
        {
            double total_pris = 0;

            foreach (Billetter b in bestillinger.billett_liste)
            {
                total_pris = total_pris + getBillettPris(b.billett_type);
            }
            return(total_pris);
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> HentEn(int id)
        {
            Bestillinger bestilling = await _db.HentEn(id);

            if (bestilling == null)
            {
                Log.Information("Bestillingen ikke funnet");
                return(NotFound("Bestillingen ikke funnet"));
            }
            return(Ok(bestilling));
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Endre(Bestillinger endreBestilling)
        {
            if (ModelState.IsValid)
            {
                bool returOk = await _db.Endre(endreBestilling);

                if (!returOk)
                {
                    Log.Information("Endring av bestilling kunne ikke utføres");
                    return(NotFound("Endring av bestilling kunne ikke utføres"));
                }
                return(Ok("Bestillingen ble endret"));
            }
            Log.Information("Endring av bestilling kunne ikke utføres: Feil i inputvalidering");
            return(BadRequest("Feil i inputvalidering"));
        }
Ejemplo n.º 8
0
        public async Task HentAlleBestillingerOK()
        {
            Bestillinger bestilling = new Bestillinger {
                Id = 1, Antall = 5, Avgang = It.IsAny <Avganger>(), Bruker = It.IsAny <Brukere>()
            };
            List <Bestillinger> bestillingListe = new List <Bestillinger> {
                bestilling
            };

            mockRep.Setup(s => s.HentAlleBestillinger()).ReturnsAsync(bestillingListe);
            var BestillingController = new BestillingController(mockRep.Object, mockLog.Object);

            var resultat = await BestillingController.HentAlleBestillinger() as OkObjectResult;

            //Assert
            Assert.Equal((int)HttpStatusCode.OK, resultat.StatusCode);
            Assert.Equal <List <Bestillinger> >((List <Bestillinger>)resultat.Value, bestillingListe);
        }
Ejemplo n.º 9
0
        public async Task <bool> Slett(int id)
        {
            try
            {
                Bestillinger enBestilling = await _db.Bestillinger.FindAsync(id);

                _db.Bestillinger.Remove(enBestilling);
                await _db.SaveChangesAsync();

                Log.Information("Bestilling slettet.");
                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Error i Slett: {error}", e);
                return(false);
            }
        }
Ejemplo n.º 10
0
        public async Task <bool> Slett(int id)
        {
            try
            {
                Bestillinger enDBBestilling = await _db.Bestillinger.FindAsync(id);

                if (enDBBestilling == null)
                {
                    return(false);
                }
                _db.Bestillinger.Remove(enDBBestilling);
                await _db.SaveChangesAsync();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 11
0
        public async Task <bool> Lagre(Bestilling innBestilling)
        {
            try
            {
                var nyBestillingRad = new Bestillinger();
                nyBestillingRad.Pris = innBestilling.pris;
                nyBestillingRad.Fra  = innBestilling.Fra;
                nyBestillingRad.Til  = innBestilling.Til;
                nyBestillingRad.Dato = innBestilling.Dato;
                nyBestillingRad.Tid  = innBestilling.Tid;
                _db.Bestillinger.Add(nyBestillingRad);
                await _db.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        public async Task <bool> Endre(Bestillinger endreBestilling)
        {
            try
            {
                Bestillinger enBestillling = await _db.Bestillinger.FindAsync(endreBestilling.ID);

                enBestillling.Kunde = endreBestilling.Kunde;
                enBestillling.Pris  = endreBestilling.Pris;
                enBestillling.Tur   = endreBestilling.Tur;
                enBestillling.Retur = endreBestilling.Retur;

                await _db.SaveChangesAsync();

                Log.Information("Bestilling endret.");
                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Error i Endre: {error}", e);
                return(false);
            }
        }
Ejemplo n.º 13
0
        public bool insertBestilling(Handlevogn hv)
        {
            var db = new DBContext();

            try
            {
                var nyBestilling = new Bestillinger()
                {
                    KundeId = hv.kunde.id
                };
                List <Ordrelinjer> nyOrdrelinjer = new List <Ordrelinjer>();
                foreach (HandlevognItem h in hv.varer)
                {
                    Ordrelinjer tmpOrdrelinje = new Ordrelinjer()
                    {
                        ID            = h.id,
                        ProduktId     = h.Vare.id,
                        Vare          = db.Varer.FirstOrDefault(k => k.ID == h.Vare.id),
                        Kvantitet     = h.Antall,
                        Bestillingsnr = nyBestilling.ID,
                        Bestilling    = nyBestilling
                    };

                    nyOrdrelinjer.Add(tmpOrdrelinje);
                    db.Ordrelinjer.Add(tmpOrdrelinje);
                }
                nyBestilling.Ordrelinjer = nyOrdrelinjer;
                hv.calculateSumTotal();
                nyBestilling.PrisTotal = hv.prisTotal;
                nyBestilling.OrderDate = DateTime.Now;
                db.Bestillinger.Add(nyBestilling);
                db.SaveChanges();
                return(true);
            }
            catch (Exception feil)
            {
                return(false);
            }
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            //check forbindelse
            if (SQL.SqlConnectionOK())
            {
                Console.WriteLine("Der er forbindelse til databasen");
            }
            else
            {
                Console.WriteLine("Der er ikke forbindelse til databasen");
            }

            //oprette to kunder
            Kunder k1 = new Kunder("Allan", "Jensen", "Telegrafvej 9", "52012368", "Pensionist");

            k1.InsertIntoDB();

            Kunder k2 = new Kunder("Vincet", "Hansen", "Telegrafvej 2", "52012858", "Pensionist");

            k2.InsertIntoDB();


            //oprette to bestillinger
            Bestillinger b1 = new Bestillinger(1, 1, "Baby Boss 1", 2, "2020-01-10 10:10", "købe");

            b1.InsertIntoDB();

            Bestillinger b2 = new Bestillinger(2, 2, "Fast and Forest3", 4, "2020-05-12 20:00", "købe");

            b2.InsertIntoDB();


            //list af alle kunder:

            List <Kunder> heleKunder = Kunder.KundeListe();

            foreach (var item in heleKunder)
            {
                Console.WriteLine(" ID: " + item.Kundeid + "Fnavn: " + item.Fnavn + "Enavn: " + item.Enavn + "Adresse: " + item.Adresse + " Telnummer: " + item.Telnumer + " Kunetype: " + item.Kundetype);
            }

            SQL.DataReader();


            //sortere

            SortEnavn Senv = new SortEnavn();

            List <Kunder> kundelist =
                new List <Kunder>()
            {
                k1, k2
            };

            //kundelist.Sort(Senv);
            Console.WriteLine("sorteret list efter Enavn:");

            foreach (var item in kundelist)

            {
                Console.WriteLine($"{item.Fnavn} {item.Enavn}");
            }


            // Update
            SQL.Update("Allan");



            //Delete
            SQL.Delete("Vincet");



            // list bestillinger fra kundeid=2

            List <Bestillinger> heleBestillinger = Bestillinger.BestillingerListe();

            foreach (var item in heleBestillinger)
            {
                Console.WriteLine(" BestillingrID: " + item.Bestillingid + " KundeID: " + item.Kundeid + "Flmnavn  : " + item.Flmnavn + "Antalpls: " + item.Antalpls + " Bestillingstid: " + item.Bestillingstid + " Typebilletter: " + item.Typebilletter);
            }

            SQL.DataReader();



            Console.ReadKey();
        }