Пример #1
0
        //public IEnumerable<TeaserEntityDL> GetAllTeasers()
        //{
        //    using (SqlConnection connection = new SqlConnection(ConnectionString))
        //    {
        //        connection.Open();
        //        using (SqlCommand command = new SqlCommand("SELECT iD, Title, Text, Date FROM Teaser", connection))
        //        {
        //            SqlDataReader reader = command.ExecuteReader();
        //            while (reader.Read())
        //            {
        //                yield return GetTeaserEntity(reader);
        //            }
        //        }
        //    }
        //}

        public TeaserEntityDL GetTeaserData(int iDteaser)
        {
            try
            {
                using (EntityFramework accessToDB = new EntityFramework())
                {
                    return(accessToDB.TeaserEntityDLTable.Where(x => x.Id == iDteaser).SingleOrDefault());
                }
            }
            catch (Exception ex)
            {
                TeaserEntityDL error = new TeaserEntityDL();
                error.Title     = $"Der Artikel Id={iDteaser} wurde nicht eingelesen";
                error.Text      = "Fehlerbeschreibung:";
                error.ImageName = $"{ex.Message.ToString()}";
                return(error);
            }
            //using (SqlConnection connection = new SqlConnection(ConnectionString))
            //{
            //    connection.Open();
            //    using (SqlCommand command = new SqlCommand("SELECT iD, Title, Text, Date FROM Teaser WHERE iD=@iDteaser", connection))
            //    {
            //        command.Parameters.AddWithValue("@iDteaser", iDteaser);
            //        SqlDataReader reader = command.ExecuteReader();
            //        if (!reader.Read())
            //        {
            //            return null;
            //        }
            //        return GetTeaserEntity(reader);
            //    }
            //}
        }
Пример #2
0
        public string UpdateTeaserData(TeaserEntityDL teaserToDB)
        {
            try
            {
                using (EntityFramework accessToDB = new EntityFramework())
                {
                    accessToDB.Entry(teaserToDB).State = EntityState.Modified;
                    accessToDB.SaveChanges();
                    return("Die Anforderung wurde erfüllt");
                }
            }
            catch (Exception ex)
            {
                string error = $"Die Anforderung wurde nicht erfüllt. Unten Fehlerbeschreibung:\n {ex.Message.ToString()}";
                return(error);
            }

            //using (SqlConnection connection = new SqlConnection(ConnectionString))
            //{
            //    connection.Open();
            //    using (SqlCommand command = new SqlCommand("UPDATE Teaser SET Title=@Title, Text=@Text , Date=@Date WHERE id=@IdTeaser", connection))
            //    {
            //        command.Parameters.AddWithValue("@Title", teaserToDB.Title);
            //        command.Parameters.AddWithValue("@Text", teaserToDB.Text);
            //        command.Parameters.AddWithValue("@Date", teaserToDB.DateOfTeaser);
            //        command.Parameters.AddWithValue("@IdTeaser", teaserToDB.Id);
            //        command.ExecuteNonQuery();
            //    }
            //}
        }
Пример #3
0
        // TEASER
        //private TeaserEntityDL GetTeaserEntity(SqlDataReader reader)
        //{
        //    TeaserEntityDL teaserFromDB = new TeaserEntityDL();
        //    teaserFromDB.Id = reader.GetInt32(reader.GetOrdinal("iD"));
        //    teaserFromDB.Title = reader.GetString(reader.GetOrdinal("Title"));
        //    teaserFromDB.Text = reader.GetString(reader.GetOrdinal("Text")) ?? string.Empty;
        //    teaserFromDB.DateOfTeaser = reader.GetDateTime(reader.GetOrdinal("Date"));
        //    return teaserFromDB;
        //}

        // Teasers
        public List <TeaserEntityDL> GetAllTeasers()
        {
            try
            {
                using (EntityFramework accessToDB = new EntityFramework())
                {
                    return(accessToDB.TeaserEntityDLTable.ToList());
                }
            }
            catch (Exception ex)
            {
                List <TeaserEntityDL> error  = new List <TeaserEntityDL>();
                TeaserEntityDL        error1 = new TeaserEntityDL();
                error1.ImageName = "Die Artikel wurden nicht eingelesen";
                error1.Text      = "Unten Fehlerbeschreibung: \n";
                error1.ImageName = ex.Message.ToString();
                error.Add(error1);
                return(error);
            }
        }