Esempio n. 1
0
        public async Task <IHttpActionResult <PollView <TUserView> > > GetPoll(int id)
        {
            var poll = await session.LoadAsync <Poll <TUser> >(id, x => x.Author);

            if (poll.Deleted)
            {
                return(NotFound <PollView <TUserView> >());
            }

            return(Ok(pollDataMapping.ToPollDto(poll)));
        }
Esempio n. 2
0
        public async Task <IEnumerable <CommentView <TUserView> > > GetComments(TUser account, int newsId, bool descending = false)
        {
            var news = await session.LoadAsync <TThread>(newsId);

            var comments = (await session.SelectAllFrom <TCommentInThread>(x => x.Comment, x => x.Comment.Author).Where(c => c.Commentable == news).ToListAsync()).Select(x => x.Comment);

            if (descending)
            {
                return(comments.OrderByDescending(c => c.CreationDate).Select(c => commentMapping.ToCommentView(c)));
            }

            return(comments.OrderBy(c => c.CreationDate).Select(c => commentMapping.ToCommentView(c)));
        }
        public async Task <IHttpActionResult <PrivateMessageView <TUserView> > > Get(int id)
        {
            var user = await accountService.GetCurrentUserAsync();

            var message = await session.LoadAsync <PrivateMessage <TUser> >(id);

            if (!await accountService.IsUser(user, message.Author))
            {
                return(Unauthorized <PrivateMessageView <TUserView> >());
            }
            return(Ok(forumsDataMapping.ToPrivateMessageView(message)));
        }
Esempio n. 4
0
        public async Task <IHttpActionResult <IEnumerable <ThreadView <TUserView> > > > GetFromForum(int forumId, [FromQuery] int offset = 0, [FromQuery] int limit = 10)
        {
            var forum = await session.LoadAsync <Data.Forums.Forum>(forumId);

            var account = await accountService.GetCurrentUserAsync();

            if (forum.ReadRole != null && !await accountService.HasRole(account, forum.ReadRole))
            {
                return(Unauthorized <IEnumerable <ThreadView <TUserView> > >());
            }

            if (account != null)
            {
                using (var transaction = session.BeginTransaction())
                {
                    var lastViewed = await session.SelectAllFrom <LastForumView <TUser> >().Where(l => l.Forum == forum && l.Account.Equals(account)).FirstOrDefaultAsync();

                    if (lastViewed == null)
                    {
                        lastViewed = new LastForumView <TUser> {
                            Account = account, Forum = forum, LastView = DateTime.UtcNow
                        };
                        await session.SaveAsync(lastViewed);
                    }
                    else
                    {
                        lastViewed.LastView = DateTime.UtcNow;
                        await session.UpdateAsync(lastViewed);
                    }
                    transaction.Commit();
                }

                var query = session.Select <ThreadBean>().All(x => x.Thread).All(x => x.LastViewed).All(x => x.Thread.Author).From(x => x.Thread).LeftJoin(x => x.LastViewed).On(x => x.Thread == x.LastViewed.Thread)
                            .AndOn(t => t.LastViewed.Account.Equals(account))
                            .LeftJoinOnId(x => x.Thread.Author)
                            .Where(t => t.Thread.Forum == forum).OrderBy(t => t.Thread.Sticky).Desc().OrderBy(t => t.Thread.CreationDate).Desc().Limit(offset, limit);

                var results = await query.ToListAsync();

                return(Ok(results.Select(b => forumsDataMapping.ToThreadView(b.Thread, b.LastViewed))));
            }
            else
            {
                var query = session.SelectAllFrom <Thread <TUser> >(x => x.Author).Where(t => t.Forum == forum).OrderBy(t => t.Sticky).Desc().OrderBy(t => t.CreationDate).Desc().Limit(offset, limit);
                return(Ok((await query.ToListAsync()).Select(t => forumsDataMapping.ToThreadView(t, null))));
            }
        }
Esempio n. 5
0
 public async Task <Adjective> ReadAsync(Guid id)
 {
     return(await _session.LoadAsync <Adjective>(id));
 }
Esempio n. 6
0
 public async Task <ChatView <TUserView> > Get(int id)
 {
     return(chatDataMapping.ToChatDto(await session.LoadAsync <Chat <TUser> >(id)));
 }
Esempio n. 7
0
 public async Task <Noun> ReadAsync(Guid id)
 {
     return(await _session.LoadAsync <Noun>(id));
 }
 public async Task <PollChosenAnswerView <TUserView> > GetAnswer(int id)
 {
     return(pollDataMapping.ToPollChosenAnswerDto(await session.LoadAsync <PollChosenAnswer <TUser> >(id)));
 }
Esempio n. 9
0
 public async Task <ExternalLinkView> Get(int id)
 {
     return(miscDataMapping.ToExternalLinkDto(await session.LoadAsync <ExternalLink>(id)));
 }
Esempio n. 10
0
 public async Task <CommentView <TUserView> > Get(int id)
 {
     return(forumsDataMapping.ToCommentView(await session.LoadAsync <Comment <TUser> >(id)));
 }
Esempio n. 11
0
 public async Task <ForumView> Get(int id)
 {
     return(forumDataMapping.ToForumView(await session.LoadAsync <Data.Forums.Forum>(id), 0));
 }