Example #1
0
        public bool settInnBestillingTurRetur(int avgangId, int returId, string dato, string datoRetur, int antallReisende, int totalSum)
        {
            using (var db = new BestillingContext())
            {
                Avgang avgang = db.avgang.Where(a => a.id == avgangId).First();
                Avgang retur  = db.avgang.Where(a => a.id == returId).First();

                var nyBestilling = new Bestillinger();
                nyBestilling.enVei_id       = avgangId;
                nyBestilling.turRetur_id    = returId;
                nyBestilling.dato           = dato;
                nyBestilling.datoRetur      = datoRetur;
                nyBestilling.totalPris      = totalSum;
                nyBestilling.antallReisende = antallReisende;
                nyBestilling.avgangEnVei    = avgang;
                nyBestilling.avgangturRetur = retur;

                try
                {
                    db.bestillinger.Add(nyBestilling);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception feil)
                {
                    throw new Exception("Får ikke lagt inn bestillingen: " + feil);
                }
            }
        }
Example #2
0
        public bool settInnBestillingTurRetur(int avgangId, int returId, string dato, string datoRetur, int antallReisende, int totalSum)
        {
            var listBestilling = new List <Bestillinger>();
            var bestilling     = new Bestillinger()
            {
                enVei_id       = 1,
                turRetur_id    = 2,
                dato           = "2019-10-24",
                datoRetur      = "2019-10-25",
                totalPris      = 1000,
                antallReisende = 1,
            };


            listBestilling.Add(bestilling);

            if (avgangId == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #3
0
        public bool endreBestilling(int id, string dato, string datoRetur, int antallReisende, int totalPris)
        {
            using (var db = new BestillingContext())
            {
                try
                {
                    Bestillinger endreBestilling = db.bestillinger.Where(a => a.id == id).First();
                    endreBestilling.dato           = dato;
                    endreBestilling.datoRetur      = datoRetur;
                    endreBestilling.antallReisende = antallReisende;
                    endreBestilling.totalPris      = totalPris;

                    var nyLogg = new endringsLogg();
                    nyLogg.tabell      = "Bestillinger";
                    nyLogg.beskrivelse = "Endret bestilling med id: " + id;
                    DateTime time = DateTime.Now;
                    nyLogg.sisteEndret = time.ToString();
                    db.logg.Add(nyLogg);

                    db.SaveChanges();
                    return(true);
                }
                catch (Exception feil)
                {
                    /* Denne logg - filen ligger i:  ~\ITPE3200WebApplication\Gruppeoppgave 1\loggingFeil.log  */
                    Logger logger = LogManager.GetLogger("logging");
                    logger.Error(feil, "ERROR: Får ikke endret bestillinger!");
                    throw new Exception("Får ikke endret verdier i databasen, feil: " + feil);
                }
            }
        }
Example #4
0
        public bool slettBestilling(int id)
        {
            using (var db = new BestillingContext())
            {
                try
                {
                    Bestillinger slettBestilling = db.bestillinger.FirstOrDefault(b => b.id == id);
                    db.bestillinger.Remove(slettBestilling);

                    var nyLogg = new endringsLogg();
                    nyLogg.tabell      = "Bestillinger";
                    nyLogg.beskrivelse = "Slettet bestilling med id: " + id;
                    DateTime time = DateTime.Now;
                    nyLogg.sisteEndret = time.ToString();
                    db.logg.Add(nyLogg);
                    db.SaveChanges();

                    return(true);
                }
                catch (Exception feil)
                {
                    /* Denne logg - filen ligger i:  ~\ITPE3200WebApplication\Gruppeoppgave 1\loggingFeil.log  */
                    Logger logger = LogManager.GetLogger("logging");
                    logger.Error(feil, "ERROR: Får ikke slettet bestillingen!");
                    throw new Exception("Får ikke lagt til verdier til databasen, feil: " + feil);
                }
            }
        }
Example #5
0
        public bool settInnBestillingEnvei(int avgangId, string dato, int antallReisende, int totalSum)
        {
            using (var db = new BestillingContext())
            {
                Avgang avgang = db.avgang.Where(a => a.id == avgangId).First();

                var nyBestilling = new Bestillinger();
                nyBestilling.enVei_id       = avgangId;
                nyBestilling.dato           = dato;
                nyBestilling.totalPris      = totalSum;
                nyBestilling.antallReisende = antallReisende;
                nyBestilling.avgangEnVei    = avgang;

                try
                {
                    var nyLogg = new endringsLogg();
                    nyLogg.tabell      = "Bestillinger";
                    nyLogg.beskrivelse = "Lagt til ny bestilling med id: " + avgangId;
                    DateTime time = DateTime.Now;
                    nyLogg.sisteEndret = time.ToString();
                    db.logg.Add(nyLogg);

                    db.bestillinger.Add(nyBestilling);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception feil)
                {
                    /* Denne logg - filen ligger i:  ~\ITPE3200WebApplication\Gruppeoppgave 1\loggingFeil.log  */
                    Logger logger = LogManager.GetLogger("logging");
                    logger.Error(feil, "ERROR: Får ikke lagt inn envei bestillingen!");
                    throw new Exception("Får ikke lagt inn bestillingen: " + feil);
                }
            }
        }
Example #6
0
 public bool slettBestilling(int id)
 {
     using (var db = new BestillingContext())
     {
         try
         {
             Bestillinger slettBestilling = db.bestillinger.FirstOrDefault(b => b.id == id);
             db.bestillinger.Remove(slettBestilling);
             db.SaveChanges();
             return(true);
         }
         catch (Exception feil)
         {
             return(false);
         }
     }
 }
Example #7
0
 public bool endreBestilling(int id, string dato, string datoRetur, int antallReisende, int totalPris)
 {
     using (var db = new BestillingContext())
     {
         try
         {
             Bestillinger endreBestilling = db.bestillinger.Where(a => a.id == id).First();
             endreBestilling.dato           = dato;
             endreBestilling.datoRetur      = datoRetur;
             endreBestilling.antallReisende = antallReisende;
             endreBestilling.totalPris      = totalPris;
             db.SaveChanges();
             return(true);
         }
         catch (Exception feil)
         {
             return(false);
         }
     }
 }