Exemple #1
0
        private async Task SendEmail(ApplicationUser user)
        {
            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var callbackUrl = _urlHelper.EmailConfirmationLink(_ravenDBIdUtil.GetUrlId(user.Id), code, _httpContextAccessor.HttpContext.Request.Scheme);
            await _emailSender.SendEmailConfirmationAsync(user.Email, user.UserName, callbackUrl);
        }
        public async Task <TossLastQueryItem> Handle(SponsoredTossQuery request, CancellationToken cancellationToken)
        {
            var resCollection = (await _session.Query <SponsoredTossEntity>()
                                 .Where(s => s.Tags.Contains(request.Hashtag))
                                 .Where(s => s.DisplayedCount > 0)
                                 .Select(t => new TossLastQueryItem()
            {
                Content = t.Content,
                CreatedOn = t.CreatedOn,
                Id = t.Id,
                UserName = t.UserName,
                Tags = t.Tags
            })
                                 .ToListAsync())
                                .ToLookup(t => t.UserName)
                                .ToArray();

            if (!resCollection.Any())
            {
                return(null);
            }
            var index    = random.NewRandom(resCollection.Length - 1);
            var userToss = resCollection[index].ToArray();
            var res      = userToss[random.NewRandom(userToss.Count() - 1)];
            await mediator.Publish(new SponsoredTossDisplayed(res.Id));

            res.Id = ravenDBIdUtil.GetUrlId(res.Id);
            return(res);
        }
Exemple #3
0
        public async Task <TossConversationQueryResult> Handle(TossConversationQuery request, CancellationToken cancellationToken)
        {
            var currentUser = await mediator.Send(new CurrentUserQuery());

            var tossId = _ravenDbIdUtil.GetRavenDbIdFromUrlId <TossEntity>(request.TossId);
            var toss   = await _session.LoadAsync <TossEntity>(tossId);

            IQueryable <TossConversation> queryable = _session.Query <TossConversation>()
                                                      .Where(c => c.TossId == tossId);

            if (!toss.IsCreator(currentUser))
            {
                queryable = queryable.Where(c => c.CreatorUserId == currentUser.Id);
            }

            var items = await(from c in queryable
                              let u = RavenQuery.Load <ApplicationUser>(c.CreatorUserId)
                                      select new TossConversationQueryResultItem()
            {
                Id = c.Id,
                CreatorUserName = u.UserName,
                MessageCount    = c.Messages.Count()
            }).ToListAsync();

            items.ForEach(c => c.Id = _ravenDbIdUtil.GetUrlId(c.Id));
            return(new TossConversationQueryResult()
            {
                Conversations = items,
                TossCreatorUserId = toss.UserId
            });
        }
Exemple #4
0
        public async Task Handle(ConversationStarted notification, CancellationToken cancellationToken)
        {
            var toss = await documentSession.LoadAsync <TossEntity>(notification.Conversation.TossId);

            var users = await documentSession.LoadAsync <ApplicationUser>(new[] { notification.Conversation.CreatorUserId, toss.UserId });

            await _emailSender.SendNewConversationAsync(
                users[toss.UserId].Email,
                users[toss.UserId].UserName,
                users[notification.Conversation.CreatorUserId].UserName,
                _urlHelper.TossLink(ravenDBIdUtil.GetUrlId(toss.Id), httpContextAccessor.HttpContext.Request.Scheme)
                );
        }
        public async Task <Unit> Handle(ForgotPasswordCommand request, CancellationToken cancellationToken)
        {
            var user = await _userManager.FindByEmailAsync(request.Email);

            if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
            {
                // Don't reveal that the user does not exist or is not confirmed
                return(Unit.Value);
            }

            // For more information on how to enable account confirmation and password reset please
            // visit https://go.microsoft.com/fwlink/?LinkID=532713
            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            var callbackUrl = _urlHelper.ResetPasswordCallbackLink(_ravenDBIdUtil.GetUrlId(user.Id), code, _httpContextAccessor.HttpContext.Request.Scheme);
            await _emailSender.SendPasswordForgetAsync(request.Email, user.UserName, callbackUrl);

            return(Unit.Value);
        }
        public async Task <IEnumerable <UserTossListViewResult> > Handle(UserTossListViewQuery request, CancellationToken cancellationToken)
        {
            List <UserTossListViewResult> list = await _session.Query <TossEntity>()
                                                 .Where(t => t.UserName == request.UserName)
                                                 .OrderByDescending(t => t.CreatedOn)
                                                 .Select(t => new UserTossListViewResult()
            {
                Content   = t.Content.Substring(0, 100),
                CreatedOn = t.CreatedOn,
                Id        = t.Id,
                Tags      = t.Tags
            })
                                                 .Paginate(request.Page, TossLastQuery.TossPerPage)
                                                 .ToListAsync();

            foreach (var item in list)
            {
                item.Id = ravenDBIdUtil.GetUrlId(item.Id);
            }
            return(list);
        }
        public async Task <IEnumerable <TossLastQueryItem> > Handle(TossLastQuery request, CancellationToken cancellationToken)
        {
            List <TossLastQueryItem> list = await _session.Query <TossEntity>()
                                            .Where(t => t.Tags.Contains(request.HashTag))
                                            .OrderByDescending(t => t.CreatedOn)
                                            .Select(t => new TossLastQueryItem()
            {
                Content   = t.Content.Substring(0, 100),
                CreatedOn = t.CreatedOn,
                Id        = t.Id,
                UserName  = t.UserName
            })
                                            .Skip(TossLastQuery.TossPerPage * request.Page)
                                            .Take(TossLastQuery.TossPerPage)

                                            .ToListAsync();

            foreach (var item in list)
            {
                item.Id = ravenDBIdUtil.GetUrlId(item.Id);
            }
            return(list);
        }