//Reservation Insert(Reservation reservation)
 public Reservation Insert(Reservation reservation)
 {
     using (var context = new AutoReservationEntities())
     {
         return context.Reservationen.Attach(reservation);
     }
 }
        public void UpdateAutoTest()
        {
            using (AutoReservationEntities context = new AutoReservationEntities())
            {
                TestEnvironmentHelper.InitializeTestData();
                AutoReservationBusinessComponent arbc = new AutoReservationBusinessComponent();

                var res = (from auto in context.Autos select auto).FirstOrDefault().Id;
                //Console.WriteLine("Abgefragte Id:" + res);

                Auto autoOriginal = arbc.GetAuto(res);
                Auto autoModified = arbc.GetAuto(res);
                //Console.WriteLine("Marke original vorher:" + autoOriginal.Marke);
                //Console.WriteLine("Marke modified vorher:" + autoModified.Marke);

                autoModified.Marke = "Fiat Punto Abart";
                arbc.EditAuto(autoOriginal, autoModified);

                //Auto autoControl = arbc.GetAuto(res);
                //Console.WriteLine("Marke original nachher:" + autoOriginal.Marke);
                //Console.WriteLine("Marke control  nachher:" + autoControl.Marke);
                //Console.WriteLine("Marke modified nachher:" + autoModified.Marke);

                Assert.AreEqual(autoOriginal.Marke, autoModified.Marke, "UpdateAutoTest: Autos sind nicht gleich nach Update");
            }
        }
 //Auto Get(Id)
 public Kunde GetKunde(int id)
 {
     using (var context = new AutoReservationEntities())
     {
         return context.Kunden.Find(id);
     }
 }
        public static void InitializeTestData()
        {
            using (AutoReservationEntities context = new AutoReservationEntities())
            {
                var connection = (SqlConnection)context.Database.Connection;
                var command = new SqlCommand();
                command.Connection = connection;

                connection.Open();

                DeleteAll(command);

                // Insert Autos
                SetAutoIncrementOnTable(connection, "Auto", true);
                InsertAutos(command);
                SetAutoIncrementOnTable(connection, "Auto", false);

                // Insert Kunden
                SetAutoIncrementOnTable(connection, "Kunde", true);
                InsertKunden(command);
                SetAutoIncrementOnTable(connection, "Kunde", false);

                // Insert Reservationen
                SetAutoIncrementOnTable(connection, "Reservation", true);
                InsertReservationen(command);
                SetAutoIncrementOnTable(connection, "Reservation", false);
            }
        }
 //Kunde Insert(Kunde kunde)
 public Kunde Insert(Kunde kunde)
 {
     using (var context = new AutoReservationEntities())
     {
         return context.Kunden.Attach(kunde);
     }
 }
 public List<Auto> GetAutos()
 {
     using (var ctx = new AutoReservationEntities())
     {
         return ctx.Autos.ToList<Auto>();
     }
 }
 //Reservation Get(Id)
 public Reservation GetReservation(int id)
 {
     using (var context = new AutoReservationEntities())
     {
         return context.Reservationen.Include("Auto").Include("Kunde").ToList().Find(i => i.ReservationNr == id);
     }
 }
 //Reservation
 //List<Reservation> GetAll()
 public List<Reservation> GetReservationen()
 {
     using (var context = new AutoReservationEntities())
     {
         return context.Reservationen.Include("Auto").Include("Kunde").ToList();
     }
 }
 //Kunde
 //List<Kunde> GetAll()
 public List<Kunde> GetKunden()
 {
     using (var context = new AutoReservationEntities())
     {
         return context.Kunden.ToList();
     }
 }
 public void CreateAuto(Auto created)
 {
     using (var ctx = new AutoReservationEntities())
     {
         ctx.AddToAutos(created);
         ctx.SaveChanges();
     }
 }
 public void CreateReservation(Reservation created)
 {
     using (var ctx = new AutoReservationEntities())
     {
         ctx.AddToReservationen(created);
         ctx.SaveChanges();
     }
 }
 public void AddKunde(Kunde kunde)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         context.AddToKunden(kunde);
         context.SaveChanges();
     }
 }
 public void AddAuto(Auto auto)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         context.AddToAutos(auto);
         context.SaveChanges();
     }
 }
 public void CreateKunde(Kunde created)
 {
     using (var ctx = new AutoReservationEntities())
     {
         ctx.AddToKunden(created);
         ctx.SaveChanges();
     }
 }
 public void AddResevation(Reservation reservation)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         context.AddToReservationen(reservation);
         context.SaveChanges();
     }
 }
 public void DeleteAuto(Auto auto)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         context.Autos.Attach(auto);
         context.Autos.DeleteObject(auto);
         context.SaveChanges();
     }
 }
 //Reservation Delete(Reservation reservation)
 public Reservation Delete(Reservation reservation)
 {
     using (var context = new AutoReservationEntities())
     {
         context.Reservationen.Attach(reservation);
         context.Reservationen.Remove(reservation);
         return reservation;
     }
 }
 public void DeleteAuto(Auto auto)
 {
     using (var ctx = new AutoReservationEntities())
     {
         ctx.Autos.Attach(auto);
         ctx.Autos.DeleteObject(auto);
         ctx.SaveChanges();
     }
 }
 public void DeleteKunde(Kunde kunde)
 {
     using (var ctx = new AutoReservationEntities())
     {
         ctx.Kunden.Attach(kunde);
         ctx.Kunden.DeleteObject(kunde);
         ctx.SaveChanges();
     }
 }
 public void DeleteReservation(Reservation res)
 {
     using (var ctx = new AutoReservationEntities())
     {
         ctx.Reservationen.Attach(res);
         ctx.Reservationen.DeleteObject(res);
         ctx.SaveChanges();
     }
 }
 public void DeleteKunde(Kunde kunde)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         context.Kunden.Attach(kunde);
         context.Kunden.DeleteObject(kunde);
         context.SaveChanges();
     }
 }
 public void DeleteReservation(Reservation reservation)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         context.Reservationen.Attach(reservation);
         context.Reservationen.DeleteObject(reservation);
         context.SaveChanges();
       }
 }
 //Kunde Delete(Kunde)
 public Kunde Delete(Kunde kunde)
 {
     using (var context = new AutoReservationEntities())
     {
         context.Kunden.Attach(kunde);
         context.Kunden.Remove(kunde);
         return kunde;
     }
 }
 public Auto GetAuto(int autoId)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         var auto = from r in context.Autos
                     where r.Id == autoId
                     select r;
         return auto.FirstOrDefault();
      }
 }
        public List<Kunde> GetKunden()
        {
            using (AutoReservationEntities context = new AutoReservationEntities())
            {
                var kunden = from k in context.Kunden
                             select k;

                return kunden.ToList();
             }
        }
        public List<Auto> GetAutos()
        {
            using (AutoReservationEntities context = new AutoReservationEntities())
            {
                var autos = from a in context.Autos
                            select a;

                return autos.ToList();
             }
        }
 public Kunde GetKunde(int kundenId)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         var kunde = from r in context.Kunden
                           where r.Id == kundenId
                           select r;
         return kunde.FirstOrDefault();
      }
 }
 public void DeleteReservation(Reservation reservationDelete)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         try
         {
             context.Reservationen.Attach(reservationDelete);
             context.DeleteObject(reservationDelete);
             context.SaveChanges();
         }
         catch (OptimisticConcurrencyException ex)
         {
             throw new LocalOptimisticConcurrencyException<Reservation>(ex.Message);
         }
     }
 }
 public void DeleteKunde(Kunde kundeDelete)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         try
         {
             context.Kunden.Attach(kundeDelete);
             context.DeleteObject(kundeDelete);
             context.SaveChanges();
         }
         catch (OptimisticConcurrencyException ex)
         {
             throw new LocalOptimisticConcurrencyException<Kunde>(ex.Message);
         }
     }
 }
 public void DeleteAuto(Auto autoDelete)
 {
     using (AutoReservationEntities context = new AutoReservationEntities())
     {
         try
         {
             context.Autos.Attach(autoDelete);
             context.DeleteObject(autoDelete);
             context.SaveChanges();
         }
         catch (OptimisticConcurrencyException ex)
         {
             throw new LocalOptimisticConcurrencyException<Auto>(ex.Message);
         }
     }
 }