Ejemplo n.º 1
0
        private async Task SetLastViewed(int threadId, int count)
        {
            var account = await accountService.GetCurrentUserAsync();

            using (var transaction = session.BeginTransaction())
            {
                var thread = await session.LoadAsync <Thread <TUser> >(threadId);

                var was = await session.SelectAllFrom <ThreadLastViewed <TUser> >().Where(t => t.Thread == thread && t.Account.Equals(account)).FirstOrDefaultAsync();

                if (was == null)
                {
                    was = new ThreadLastViewed <TUser> {
                        Account = account, Thread = thread, NumberOfComments = count
                    };
                    await session.SaveAsync(was);

                    transaction.Commit();
                }
                else if (was.NumberOfComments != count)
                {
                    was.NumberOfComments = count;
                    await session.UpdateAsync(was);

                    transaction.Commit();
                }
            }
        }
Ejemplo n.º 2
0
 public ThreadView <TUserView> ToThreadView(Thread <TUser> thread, ThreadLastViewed <TUser> lastViewed)
 {
     return(new ThreadView <TUserView>
     {
         Id = thread.Id,
         CreationDate = thread.CreationDate,
         Author = forumUserService.MapToUserView(thread.Author),
         Title = thread.Title,
         Text = thread.Text,
         Sticky = thread.Sticky,
         NumberOfComments = thread.NumberOfComments,
         NumberOfViewedComments = lastViewed?.NumberOfComments ?? 0,
         LastViewedId = lastViewed?.Id ?? 0
     });
 }
Ejemplo n.º 3
0
 public ThreadFullView <TUserView> ToThreadFullView(Thread <TUser> thread,
                                                    ThreadLastViewed <TUser> lastViewed)
 {
     return(new ThreadFullView <TUserView>
     {
         Id = thread.Id,
         CreationDate = thread.CreationDate,
         Author = forumUserService.MapToUserView(thread.Author),
         Title = thread.Title,
         Text = thread.Text,
         Sticky = thread.Sticky,
         NumberOfComments = thread.NumberOfComments,
         NumberOfViewedComments = lastViewed?.NumberOfComments ?? 0,
         LastViewedId = lastViewed?.Id ?? 0,
         Photos = thread.Photos.Select(x => ToPhotoView(x.Photo)).ToList()
     });
 }