예제 #1
0
        // UPDATE ONE CONNECTION
        public string UpdateConnection(ConnectionEntityDL connectionToDB)
        {
            string result = "";

            try
            {
                using (EntityFramework accessToDB = new EntityFramework())
                {
                    accessToDB.Entry(connectionToDB).State = EntityState.Modified;
                    accessToDB.SaveChanges();
                    return(result = "Die Verkehresverbindung wurde korrigiert.");
                }
            }
            catch (Exception ex)
            {
                return(result = $"Die Verkehresverbindung wurde nicht korrigiert. Fehlerbeschreibung: {ex.Message.ToString()}");
            }

            //using (SqlConnection connection = new SqlConnection(ConnectionString))
            //{
            //    connection.Open();
            //    using (SqlCommand command = new SqlCommand("UPDATE Departures2 SET departureCityId=@departureCityId, arrivalCityId=@arrivalCityId, departureTime=@departureTime, arrivalTime=@arrivalTime WHERE id=@IdConnection", connection))
            //    {
            //        command.Parameters.AddWithValue("@departureCityId", connectionToDB.DepartureCityId);
            //        command.Parameters.AddWithValue("@arrivalCityId", connectionToDB.ArrivalCityId);
            //        command.Parameters.AddWithValue("@departureTime", connectionToDB.DepartureTime);
            //        command.Parameters.AddWithValue("@arrivalTime", connectionToDB.ArrivalTime);
            //        command.Parameters.AddWithValue("@IdConnection", connectionToDB.Id);
            //        command.ExecuteNonQuery();
            //    }
            //}
        }
예제 #2
0
        //public IEnumerable<ConnectionEntityDL> GetConnections()
        //{
        //    using (SqlConnection connection = new SqlConnection(ConnectionString))
        //    {
        //        connection.Open();
        //        using (SqlCommand command = new SqlCommand("SELECT id,departureCityId,arrivalCityId,departureTime,arrivalTime FROM Departures2", connection))
        //        {
        //            using (SqlDataReader reader = command.ExecuteReader())
        //            {
        //                while (reader.Read())
        //                {
        //                    yield return GetDbConnectionEntity(reader);
        //                }
        //            }
        //        }
        //    }
        //}

        // GET ONE CONNECTION BY ID
        public ConnectionEntityDL GetConnectionByID(int idConnection)
        {
            try
            {
                using (EntityFramework accessToDB = new EntityFramework())
                {
                    return(accessToDB.ConnectionEntityDLTable.Where(x => x.Id == idConnection).SingleOrDefault());
                }
            }
            catch (Exception ex)
            {
                ExceptionLog(ex.Message.ToString());
                ConnectionEntityDL nullObject = new ConnectionEntityDL(); string errorMessage = $"{ex.Message.ToString()}";
                return(nullObject);
            }

            //using (SqlConnection connection = new SqlConnection(ConnectionString))
            //{
            //    connection.Open();
            //    using (SqlCommand command = new SqlCommand("SELECT id,departureCityId,arrivalCityId,departureTime,arrivalTime FROM Departures2 WHERE id=@idConnection ", connection))
            //    {
            //        command.Parameters.AddWithValue("@idConnection", idConnection);
            //        using (SqlDataReader reader = command.ExecuteReader())
            //        {
            //            if (!reader.Read())
            //            {
            //                return null;
            //            }
            //            return GetDbConnectionEntity(reader);
            //        }
            //    }
            //}
        }
예제 #3
0
        //public IEnumerable<ConnectionEntityDL> GetConnectionsByDepartureCityIdArrivalCityId(int departureCityId, int arrivalCityId)
        //{
        //    using (SqlConnection connection = new SqlConnection(ConnectionString))
        //    {
        //        connection.Open();
        //        using (SqlCommand command = new SqlCommand("SELECT id,departureCityId,arrivalCityId,departureTime,arrivalTime FROM Departures2 WHERE departureCityId = @departureCityId AND arrivalCityId = @arrivalCityId", connection))
        //        {
        //            command.Parameters.AddWithValue("@departureCityId", departureCityId);
        //            command.Parameters.AddWithValue("@arrivalCityId", arrivalCityId);
        //            using (SqlDataReader reader = command.ExecuteReader())
        //            {
        //                while (reader.Read())
        //                {
        //                    yield return GetDbConnectionEntity(reader);
        //                }
        //            }
        //        }
        //    }
        //}

        // INSERT ONE CONNECTION
        public string InsertConnection(ConnectionEntityDL connectionToDB)
        {
            string result = "";

            try
            {
                using (EntityFramework accessToDB = new EntityFramework())
                {
                    accessToDB.ConnectionEntityDLTable.Add(connectionToDB);
                    accessToDB.SaveChanges();
                    return(result = "Die Verbindung wurde gegründet");
                }
            }
            catch (Exception ex)
            {
                return(result = $"Die Verbindung wurde nicht gegründet! Fehlerbeschreibung:\n {ex.Message.ToString()}");
            }

            //using (SqlConnection connection = new SqlConnection(ConnectionString))
            //{
            //    connection.Open();
            //    using (SqlCommand command = new SqlCommand("INSERT INTO Departures2(departureCityId,arrivalCityId,departureTime,arrivalTime) VALUES (@departureCity,@arrivalCity,@departureTime,@arrivalTime)", connection))
            //    {
            //        command.Parameters.AddWithValue("@departureCity", connectionToDB.DepartureCityId);
            //        command.Parameters.AddWithValue("@arrivalCity", connectionToDB.ArrivalCityId);
            //        command.Parameters.AddWithValue("@departureTime", connectionToDB.DepartureTime);
            //        command.Parameters.AddWithValue("@arrivalTime", connectionToDB.ArrivalTime);
            //        command.ExecuteNonQuery();
            //    }
            //}
        }