// Example public List <Auto> GetAllAutos() { using (KundenReservationContext dbContext = new KundenReservationContext()) { return(dbContext.Autos.ToList()); } }
public List <Kunde> GetAllKunde() { using (KundenReservationContext dbContext = new KundenReservationContext()) { return(dbContext.Kunden.ToList()); } }
public List <Reservation> GetAllReservation() { using (KundenReservationContext dbContext = new KundenReservationContext()) { return(dbContext.Reservationen.ToList()); } }
public Reservation FindReservationByNr(int searchId) { using (KundenReservationContext dbContext = new KundenReservationContext()) { return(dbContext.Reservationen .SingleOrDefault(r => r.ReservationsNr == searchId)); } }
public Kunde FindKundeById(int id) { using (KundenReservationContext dbContext = new KundenReservationContext()) { return(dbContext.Kunden .Where(k => k.Id == id) .FirstOrDefault()); } }
public Auto Delete(Auto auto) { using (KundenReservationContext dbContext = new KundenReservationContext()) { dbContext.Entry(auto).State = EntityState.Deleted; dbContext.SaveChanges(); return(auto); } }
public Kunde Delete(Kunde kunde) { using (KundenReservationContext dbContext = new KundenReservationContext()) { dbContext.Entry(kunde).State = EntityState.Deleted; dbContext.SaveChanges(); return(kunde); } }
public Reservation Delete(Reservation res) { using (KundenReservationContext dbContext = new KundenReservationContext()) { dbContext.Entry(res).State = EntityState.Deleted; dbContext.SaveChanges(); return(res); } }
public Auto FindAutoById(int id) { using (KundenReservationContext dbContext = new KundenReservationContext()) { return(dbContext.Autos .Where(a => a.Id == id) .FirstOrDefault()); } }
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); } }
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); } }
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); } }
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); } } }
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); } } }
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); } } }
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); } } }