Exemple #1
0
 // Example
 public List <Auto> GetAllAutos()
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         return(dbContext.Autos.ToList());
     }
 }
Exemple #2
0
 public List <Kunde> GetAllKunde()
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         return(dbContext.Kunden.ToList());
     }
 }
Exemple #3
0
 public List <Reservation> GetAllReservation()
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         return(dbContext.Reservationen.ToList());
     }
 }
Exemple #4
0
 public Reservation FindReservationByNr(int searchId)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         return(dbContext.Reservationen
                .SingleOrDefault(r => r.ReservationsNr == searchId));
     }
 }
Exemple #5
0
 public Kunde FindKundeById(int id)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         return(dbContext.Kunden
                .Where(k => k.Id == id)
                .FirstOrDefault());
     }
 }
Exemple #6
0
 public Auto Delete(Auto auto)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         dbContext.Entry(auto).State = EntityState.Deleted;
         dbContext.SaveChanges();
         return(auto);
     }
 }
Exemple #7
0
 public Kunde Delete(Kunde kunde)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         dbContext.Entry(kunde).State = EntityState.Deleted;
         dbContext.SaveChanges();
         return(kunde);
     }
 }
Exemple #8
0
 public Reservation Delete(Reservation res)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         dbContext.Entry(res).State = EntityState.Deleted;
         dbContext.SaveChanges();
         return(res);
     }
 }
Exemple #9
0
 public Auto FindAutoById(int id)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         return(dbContext.Autos
                .Where(a => a.Id == id)
                .FirstOrDefault());
     }
 }
Exemple #10
0
 public Auto Insert(Auto auto)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         Auto insertedAuto = dbContext.Autos.Add(auto);
         dbContext.Entry(insertedAuto).State = EntityState.Added;
         dbContext.SaveChanges();
         return(insertedAuto);
     }
 }
Exemple #11
0
 public Reservation Insert(Reservation res)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         Reservation insertedReservation = dbContext.Reservationen.Add(res);
         dbContext.Entry(insertedReservation).State = EntityState.Added;
         dbContext.SaveChanges();
         return(insertedReservation);
     }
 }
Exemple #12
0
 public Kunde Insert(Kunde kunde)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         Kunde insertedKunde = dbContext.Kunden.Add(kunde);
         dbContext.Entry(insertedKunde).State = EntityState.Added;
         dbContext.SaveChanges();
         return(insertedKunde);
     }
 }
Exemple #13
0
 public Auto Update(Auto auto)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         try
         {
             dbContext.Entry(auto).State = EntityState.Modified;
             dbContext.SaveChanges();
             return(auto);
         }
         catch (DbUpdateConcurrencyException ex)
         {
             throw CreateOptimisticConcurrencyException <Auto>(dbContext, auto);
         }
     }
 }
Exemple #14
0
 public Reservation Update(Reservation res)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         try
         {
             dbContext.Entry(res).State = EntityState.Modified;
             dbContext.SaveChanges();
             return(res);
         }
         catch (DbUpdateConcurrencyException)
         {
             throw CreateOptimisticConcurrencyException <Reservation>(dbContext, res);
         }
     }
 }
Exemple #15
0
 public Kunde Update(Kunde kunde)
 {
     using (KundenReservationContext dbContext = new KundenReservationContext())
     {
         try
         {
             dbContext.Entry(kunde).State = EntityState.Modified;
             dbContext.SaveChanges();
             return(kunde);
         }
         catch (DbUpdateConcurrencyException ex)
         {
             throw ManagerBase.CreateOptimisticConcurrencyException <Kunde>(dbContext, kunde);
         }
     }
 }
Exemple #16
0
        protected static OptimisticConcurrencyException <T> CreateOptimisticConcurrencyException <T>(KundenReservationContext context, T entity)
            where T : class
        {
            var dbEntity = (T)context.Entry(entity)
                           .GetDatabaseValues()
                           .ToObject();

            return(new OptimisticConcurrencyException <T>($"Update {typeof(T).Name}: Concurrency-Fehler", dbEntity));
        }
        public static void InitializeTestData()
        {
            using (KundenReservationContext context = new KundenReservationContext())
            {
                var luxusklasseAutoTableName  = context.GetTableName <LuxusklasseAuto>();
                var mittelklasseAutoTableName = context.GetTableName <MittelklasseAuto>();
                var standardAutoTableName     = context.GetTableName <StandardAuto>();
                var autoTableName             = context.GetTableName <Auto>();
                var kundeTableName            = context.GetTableName <Kunde>();
                var reservationTableName      = context.GetTableName <Reservation>();

                try
                {
                    // Delete all records from tables
                    //      > Cleanup for specific subtypes necessary when not using table per hierarchy (TPH)
                    //        since entities will be stored in different tables.
                    if (luxusklasseAutoTableName != autoTableName)
                    {
                        context.DeleteAllRecords(luxusklasseAutoTableName);
                    }
                    if (mittelklasseAutoTableName != autoTableName)
                    {
                        context.DeleteAllRecords(mittelklasseAutoTableName);
                    }
                    if (standardAutoTableName != autoTableName)
                    {
                        context.DeleteAllRecords(standardAutoTableName);
                    }
                    context.DeleteAllRecords(reservationTableName);
                    context.DeleteAllRecords(autoTableName);
                    context.DeleteAllRecords(kundeTableName);

                    // Reset the identity seed (Id's will start again from 1)
                    context.ResetEntitySeed(luxusklasseAutoTableName);
                    context.ResetEntitySeed(mittelklasseAutoTableName);
                    context.ResetEntitySeed(standardAutoTableName);
                    context.ResetEntitySeed(autoTableName);
                    context.ResetEntitySeed(kundeTableName);
                    context.ResetEntitySeed(reservationTableName);

                    // Temporarily allow insertion of identity columns (Id)
                    context.SetAutoIncrementOnTable(luxusklasseAutoTableName, true);
                    context.SetAutoIncrementOnTable(mittelklasseAutoTableName, true);
                    context.SetAutoIncrementOnTable(standardAutoTableName, true);
                    context.SetAutoIncrementOnTable(autoTableName, true);
                    context.SetAutoIncrementOnTable(kundeTableName, true);
                    context.SetAutoIncrementOnTable(reservationTableName, true);

                    // Insert test data
                    context.Autos.AddRange(Autos);
                    context.Kunden.AddRange(Kunden);
                    context.Reservationen.AddRange(Reservationen);
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Error while re-initializing database entries.", ex);
                }
                finally
                {
                    // Disable insertion of identity columns (Id)
                    context.SetAutoIncrementOnTable(luxusklasseAutoTableName, false);
                    context.SetAutoIncrementOnTable(mittelklasseAutoTableName, false);
                    context.SetAutoIncrementOnTable(standardAutoTableName, false);
                    context.SetAutoIncrementOnTable(autoTableName, false);
                    context.SetAutoIncrementOnTable(kundeTableName, false);
                    context.SetAutoIncrementOnTable(reservationTableName, false);
                }
            }
        }