Exemplo n.º 1
0
        public static List <Sitelet> GetSiteletsByToken(string token)
        {
            SqlConnection  conn     = null;
            SqlCommand     command  = null;
            SqlDataReader  reader   = null;
            List <string>  clients  = new List <string>();
            string         result   = string.Empty;
            List <Sitelet> Sitelets = new List <Sitelet>();

            try
            {
                // create and open a connection object
                using (conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MLBStyleGuideConnectionString1"].ConnectionString))
                {
                    conn.Open();
                    using (command = new SqlCommand("[mlbstyleguide].[uspGetSiteletsByToken]", conn))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.Add("@token", SqlDbType.UniqueIdentifier).Value = new Guid(token);
                        reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        while (reader.Read())
                        {
                            var sitelet = new Sitelet();
                            sitelet.id          = Convert.ToInt32(reader[0].ToString());
                            sitelet.description = reader[1].ToString();
                            Sitelets.Add(sitelet);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorEmailer.SendEmail(ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
                if (command != null)
                {
                    command.Dispose();
                }

                if (conn != null)
                {
                    conn.Close();
                }
            }
            //return clients;
            return(Sitelets);
        }
Exemplo n.º 2
0
        public static void SaveDownload(string token, int siteletID, string year, string file, string dateDownloaded)
        {
            SqlConnection conn    = null;
            SqlCommand    command = null;

            try
            {
                // create and open a connection object
                using (conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MLBStyleGuideConnectionString1"].ConnectionString))
                {
                    conn.Open();
                    using (command = new SqlCommand("[mlbstyleguide].[uspSaveDownload]", conn))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.Add("@Token", SqlDbType.UniqueIdentifier).Value = new Guid(token);
                        command.Parameters.AddWithValue("@Section", GetSectionNameBySiteletID(siteletID));
                        command.Parameters.AddWithValue("@Year", year);
                        command.Parameters.AddWithValue("@File", file);
                        command.Parameters.AddWithValue("@DateDownloaded", Convert.ToDateTime(dateDownloaded));
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorEmailer.SendEmail(ex);
                throw ex;
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }

                if (conn != null)
                {
                    conn.Close();
                }
            }
            //return clients;
        }