/// <summary> /// Get catalog item that matches the catalog code. /// </summary> /// <param name="code">Catalog code</param> /// <returns>CatalogItem object that contains the details of a catalog item. If no matching catalog code is found, null will be returned.</returns> public static CatalogItem GetCatalogItem(string code) { CatalogItem item = null; // get catalog items from DB SqlConnection conn = FoeServerDb.OpenDb(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from CatalogRss where Code=@code"; cmd.Parameters.Add("@code", SqlDbType.NVarChar, 10); cmd.Prepare(); cmd.Parameters["@code"].Value = code; // get item SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { // populate the data item = new CatalogItem(); item.Code = FoeServerDb.GetString(reader, "Code"); item.ContentType = FoeServerDb.GetString(reader, "ContentType"); item.Description = FoeServerDb.GetString(reader, "Description"); item.Location = FoeServerDb.GetString(reader, "Location"); } reader.Close(); conn.Close(); return(item); }
/// <summary> /// Get all catalog items available. /// </summary> /// <returns>A list of catalog items that are available.</returns> public static List <CatalogItem> GetCatalog() { List <CatalogItem> items = new List <CatalogItem>(); // get catalog items from DB SqlConnection conn = FoeServerDb.OpenDb(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from CatalogRss order by Name"; // get items SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { // create a new item and populate the data CatalogItem item = new CatalogItem(); item.Code = FoeServerDb.GetString(reader, "Code"); item.ContentType = FoeServerDb.GetString(reader, "ContentType"); item.Description = FoeServerDb.GetString(reader, "Description"); item.Location = FoeServerDb.GetString(reader, "Location"); // add to list items.Add(item); } reader.Close(); conn.Close(); return(items); }
/// <summary> /// Get the RSS cache. /// </summary> /// <param name="catalogCode">Catalog code representing the RSS</param> public static FoeServerRssFeed GetRssFeedCache(string catalogCode) { FoeServerRssFeed feed = null; SqlConnection conn = FoeServerDb.OpenDb(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from RssFeeds where Code=@code"; cmd.Parameters.Add("@code", SqlDbType.NVarChar, 10); cmd.Prepare(); cmd.Parameters["@code"].Value = catalogCode; SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { feed = new FoeServerRssFeed(); feed.Id = (int)FoeServerDb.GetInt32(reader, "Id"); feed.Rss = FoeServerDb.GetString(reader, "Rss"); feed.Code = FoeServerDb.GetString(reader, "Code"); feed.DtLastUpdated = (DateTime)FoeServerDb.GetDateTime(reader, "DtLastUpdated"); } reader.Close(); conn.Close(); return(feed); }
/// <summary> /// Get the next available request. /// </summary> /// <returns>The next available request. If no more request is available, null will be returned.</returns> public FoeRequester GetNextRequest() { FoeRequester req = null; // check if we are currently connected to DB if ((_conn != null) && (_conn.State != System.Data.ConnectionState.Open)) { _conn.Close(); } LoadRequests(); // Load request messages while (_reader.Read()) { req = new FoeRequester(); req.Id = (int)FoeServerDb.GetInt32(_reader, "Id"); req.Type = _requestType; req.UserEmail = FoeServerDb.GetString(_reader, "UserEmail"); req.RequestId = FoeServerDb.GetString(_reader, "RequestId"); req.ProcessorEmail = FoeServerDb.GetString(_reader, "ProcessorEmail"); req.RequestMessage = FoeServerDb.GetString(_reader, "RequestMessage"); req.DtReceived = (DateTime)FoeServerDb.GetDateTime(_reader, "DtReceived"); req.DtProcessed = null; req.Status = FoeServerDb.GetString(_reader, "Status"); } return(req); }
/// <summary> /// Return a FoeServerAutoSubscriber object extract from next record in the SqlDataReader object provided. /// </summary> /// <param name="reader">SqlDataReader object that contains the query results.</param> /// <returns>The FoeServerAutoSubscriber object representing the next record in the SqlDataReader object.</returns> public static FoeServerAutoSubscriber GetNextAutoSubscriberFromSqlReader(SqlDataReader reader) { FoeServerAutoSubscriber sub = null; if ((reader != null) && (reader.Read())) { sub = new FoeServerAutoSubscriber(); sub.Id = (int)FoeServerDb.GetInt32(reader, "Id"); sub.UserEmail = FoeServerDb.GetString(reader, "UserEmail"); sub.CatalogCode = FoeServerDb.GetString(reader, "CatalogCode"); sub.RequestId = FoeServerDb.GetString(reader, "RequestId"); sub.DtSubscribed = (DateTime)FoeServerDb.GetDateTime(reader, "DtSubscribed"); sub.DtLastUpdated = FoeServerDb.GetDateTime(reader, "DtLastUpdated"); } return(sub); }
/// <summary> /// Get user information in an FoeUser object. /// </summary> /// <param name="userEmail">user's email address</param> /// <returns>A FoeUser object populated with user info. If user is not found, then null is returned.</returns> public static FoeUser GetUser(string userEmail) { FoeUser user = null; // open connection to FOE DB SqlConnection conn = FoeServerDb.OpenDb(); SqlCommand cmd = conn.CreateCommand(); // get user string sql = "select * from Users where Email=@email"; cmd.CommandText = sql; cmd.Parameters.Add("@email", SqlDbType.NVarChar, 256); cmd.Prepare(); cmd.Parameters["@email"].Value = userEmail.Trim().ToLower(); SqlDataReader reader = cmd.ExecuteReader(); // see if user exists if (reader.HasRows) { reader.Read(); // create a new user object; user = new FoeUser(); // populate user information user.Id = FoeServerDb.GetInt32(reader, "Id"); user.Email = FoeServerDb.GetString(reader, "Email"); user.UserId = FoeServerDb.GetString(reader, "UserId"); user.DtCreated = FoeServerDb.GetDateTime(reader, "DtCreated"); user.ProcessorEmail = FoeServerDb.GetString(reader, "ProcessorEmail"); } reader.Close(); conn.Close(); return(user); }
/// <summary> /// Get the RSS cache. /// </summary> /// <param name="catalogCode">Catalog code representing the RSS</param> public static string GetRssCache(string catalogCode) { string rss = null; SqlConnection conn = FoeServerDb.OpenDb(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "select Rss from RssFeeds where Code=@code"; cmd.Parameters.Add("@code", SqlDbType.NVarChar, 10); cmd.Prepare(); cmd.Parameters["@code"].Value = catalogCode; SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { rss = FoeServerDb.GetString(reader, "Rss"); } reader.Close(); conn.Close(); return(rss); }