public static ReligiousQuote GetQuote(DateTime date)
        {
            var religiousTransformer = new ReligiousQuoteTransformer();
            var quote = new ReligiousQuote();

            using (var dbconn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString))
            {
                if (dbconn.State == ConnectionState.Open)
                {
                    dbconn.Close();
                }
                dbconn.Open();

                using (var cmd = new SqlCommand("spGetDailyReligiousQuote", dbconn))
                {
                    try
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@dateofQuote", date.ToString("MM/dd/yyyy"));

                        var reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            quote = religiousTransformer.Transform(reader);
                        }
                    }
                    catch (Exception)
                    {
                        // Ignored
                    }
                }
                return(quote);
            }
        }
Beispiel #2
0
        public List <ReligiousQuote> GetFavoriteReligiousQuotes(int userId)
        {
            var religiousQuotes           = new List <ReligiousQuote>();
            var religiousQuoteTransformer = new ReligiousQuoteTransformer();

            using (var sp = new StoredProcedure("spGetFavoriteReligiousQuote"))
            {
                sp.SqlCommand.Parameters.AddWithValue("@userID", userId);

                var reader = sp.SqlCommand.ExecuteReader();

                while (reader.Read())
                {
                    religiousQuotes.Add(religiousQuoteTransformer.Transform(reader));
                }
            }

            return(religiousQuotes);
        }
        public List <ReligiousQuote> GetFavoriteReligiousQuotes(int userId)
        {
            var religiousQuotes           = new List <ReligiousQuote>();
            var religiousQuoteTransformer = new ReligiousQuoteTransformer();

            using (var dbconn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString))
            {
                if (dbconn.State == ConnectionState.Open)
                {
                    dbconn.Close();
                }
                dbconn.Open();

                using (var cmd = new SqlCommand("spGetFavoriteReligiousQuote", dbconn))
                {
                    try
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@userID", userId);


                        var reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            religiousQuotes.Add(religiousQuoteTransformer.Transform(reader));
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }

            return(religiousQuotes);
        }
 public ReligiousQuoteService()
 {
     _religiousQuoteTransformer = new ReligiousQuoteTransformer();
 }