/// <summary> /// Adds the topic. /// </summary> /// <param name="category">The category.</param> /// <param name="name">The name.</param> /// <param name="longTitle">The long title.</param> /// <param name="description">The description.</param> /// <returns></returns> public Topic AddTopic(TopicCategory category, string name, string longTitle, string description) { try { Topic topic = new Topic(category, name.Trim()); topic.LongTitle = longTitle.Trim(); topic.Description = description.Trim(); using (var session = Provider.SessionFactory.OpenSession()) { using (var trans = session.BeginTransaction()) { if (!topic.IsPersisted) { session.SaveOrUpdate(topic); } else { session.Merge(topic); } trans.Commit(); } } return(topic); } catch (Exception ex) { Logger.Write(ex, "Error adding topic {0} to category {1}", name, category); return(null); } }
/// <summary> /// Adds the topic category. /// </summary> /// <param name="category">The category.</param> /// <param name="longTitle">The long title.</param> /// <param name="description">The description.</param> /// <returns></returns> public TopicCategory AddTopicCategory(string category, string longTitle, string description) { try { var topicCategory = new TopicCategory(category.Trim()) { LongTitle = longTitle.Trim(), Description = description.Trim() }; using (var session = Provider.SessionFactory.OpenSession()) { using (var trans = session.BeginTransaction()) { if (!topicCategory.IsPersisted) { session.SaveOrUpdate(topicCategory); } else { session.Merge(topicCategory); } trans.Commit(); } } return(topicCategory); } catch (Exception ex) { Logger.Write(ex, "Error adding topic category {0}", category); return(null); } }
/// <summary> /// Gets the topic category. /// </summary> /// <param name="category">The category.</param> /// <returns></returns> public TopicCategory GetTopicCategory(string category) { using (ISession session = Provider.SessionFactory.OpenSession()) { try { TopicCategory topicCategory = (from categories in session.Query <TopicCategory>() where categories.Name == category.Trim() select categories).SingleOrDefault(); return(topicCategory); } catch (Exception ex) { Logger.Write(ex, "Error getting topic category with name {0}", category); return(null); } } }