public Feed GetFeed(long id) { using (var tx = dbManager.BeginTransaction()) { var list = dbManager .ExecuteList(Query("events_feed").Select("Id", "FeedType", "Caption", "Text", "Date", "Creator").Select(GetFeedReadedQuery()).Where("Id", id)) .ConvertAll(r => Mappers.ToNewsOrPoll(r)); var feed = 0 < list.Count ? list[0] : null; if (feed == null || feed is FeedNews) { return(feed); } var poll = (FeedPoll)feed; dbManager.ExecuteList(Query("events_poll").Select("PollType", "StartDate", "EndDate").Where("Id", id)) .ForEach(row => { poll.PollType = (FeedPollType)Convert.ToInt32(row[0]); poll.StartDate = TenantUtil.DateTimeFromUtc(Convert.ToDateTime(row[1])); poll.EndDate = TenantUtil.DateTimeFromUtc(Convert.ToDateTime(row[2])); }); dbManager.ExecuteList( Query("events_pollvariant v").Select("v.Id", "v.Name", "a.User") .LeftOuterJoin("events_pollanswer a", Exp.EqColumns("v.Id", "a.Variant")) .Where("v.Poll", id)) .ForEach(row => { var variantId = Convert.ToInt64(row[0]); if (!poll.Variants.Exists(v => v.ID == variantId)) { poll.Variants.Add(new FeedPollVariant() { ID = variantId, Name = Convert.ToString(row[1]) }); } if (row[2] != null) { poll.answers.Add(new FeedPollAnswer(variantId, Convert.ToString(row[2]))); } }); tx.Commit(); return(poll); } }
public List <Feed> SearchFeeds(string s, FeedType feedType, Guid userId, int count, int offset) { if (s != null && s.Length < MinSearchLength) { return(new List <Feed>()); } var select = Query("events_feed") .Select("Id", "FeedType", "Caption", "Date", "Creator") .Select(GetFeedReadedQuery()) .Where(GetWhere(s, feedType, userId)) .OrderBy("Id", false) .SetFirstResult(offset) .SetMaxResults(count); return(dbManager .ExecuteList(select) .ConvertAll(r => Mappers.ToFeed(r))); }
public List <FeedComment> GetFeedComments(long feedId) { return(dbManager .ExecuteList(GetFeedCommentQuery(Exp.Eq("Feed", feedId))) .ConvertAll(r => Mappers.ToFeedComment(r))); }