Beispiel #1
0
        //GET ONE MESSAGE
        public FeedbackEntityDL GetMessage(int idMessage)
        {
            try
            {
                using (EntityFramework accessToDB = new EntityFramework())
                {
                    return(accessToDB.FeedbackEntityDLTable.Where(x => x.Id == idMessage).SingleOrDefault());
                }
            }
            catch (Exception ex)
            {
                FeedbackEntityDL error = new FeedbackEntityDL("Keine Bericht", "wurde eingelesen", "Fehlerbeschreibung:", $"{ex.Message.ToString()}");
                return(error);
            }

            //using (SqlConnection connection = new SqlConnection(ConnectionString))
            //{
            //    connection.Open();
            //    using (SqlCommand command = new SqlCommand("SELECT id,requestType,message,email,phoneNumber FROM Messages WHERE id=@idMessage", connection))
            //    {
            //        command.Parameters.AddWithValue("@idMessage", idMessage);
            //        using (SqlDataReader reader = command.ExecuteReader())
            //        {
            //            if(!reader.Read())
            //            {
            //                return null;
            //            }
            //            return GetFeedbackEntity(reader);
            //        }
            //    }
            //}
        }
Beispiel #2
0
        // ADD ONE MESSAGE FROM WEB SITE
        public string AddMessageFromWebSite(FeedbackEntityDL messageToDB)
        {
            string result = "";

            try
            {
                using (EntityFramework accessToDB = new EntityFramework())
                {
                    accessToDB.FeedbackEntityDLTable.Add(messageToDB);
                    accessToDB.SaveChanges();
                    return(result = "Wir danken für Ihre Meinung");
                }
            }
            catch (Exception ex)
            {
                return(result = $"Die Bericht wurde nicht gespeichert. Fehlerbeschreibung: {ex.Message.ToString()}");
            }

            //using (SqlConnection connection = new SqlConnection(ConnectionString))
            //{
            //    connection.Open();
            //    using (SqlCommand command = new SqlCommand("INSERT INTO Messages (email, phoneNumber, message, requestType) VALUES (@email, @phoneNumber, @message, @requestType)", connection))
            //    {
            //        command.Parameters.AddWithValue("@email", messageToDB.Email);
            //        command.Parameters.AddWithValue("@phoneNumber", messageToDB.PhoneNumber ?? string.Empty);
            //        command.Parameters.AddWithValue("@message", messageToDB.Message ?? string.Empty);
            //        command.Parameters.AddWithValue("@requestType", messageToDB.RequestType);
            //        command.ExecuteNonQuery();
            //    }
            //}
        }