예제 #1
0
        public async Task <PasswordReset> RequestResetAsync(MoxUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException($"Parameter {nameof(user)} cannot be null!");
            }

            var httpContext = this._httpContextAccessor.HttpContext;
            var resetToken  = await this._userManager.GeneratePasswordResetTokenAsync(user);

            var reset = new PasswordReset()
            {
                UserId                = user.Id,
                ResetToken            = resetToken,
                Completed             = false,
                CreatedOn             = DateTime.Now,
                RequestedByClientInfo = httpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Okänt",
                CompletedOn           = null,
                ValidUntil            = DateTime.Today.AddDays(1)
            };

            this._context.Add(reset);
            await this._context.SaveChangesAsync();

            return(reset);
        }
        public async Task MarkAllReadAsync(MoxUser me)
        {
            var notifications = this._context.Notifications.Where(x => x.RecieverId == me.Id && !x.IsRead);

            foreach (var notification in notifications)
            {
                notification.IsRead = true;
            }
            await this._context.SaveChangesAsync();
        }
예제 #3
0
        public async Task Send(Notification notification, MoxUser reciever)
        {
            var mailMessage = new MailMessage
            {
                Subject = notification.SubjectId,
                Body    = $"{notification.ShortDescription}, {notification.URL}"
            };

            mailMessage.To.Add(reciever.Email);
            await this._emailSender.SendAsync(mailMessage);
        }
        public async Task SendAsync(MoxUser me, string subject, string shortDescription, string url, int?entityId = null)
        {
            var subscribers = this._subscriber.Subscriptions(subject, entityId, me);

            foreach (var subscription in await subscribers.Include(x => x.Subscriber).ToListAsync())
            {
                var notification = new Notification(subject, entityId, subscription.SubscriberId, shortDescription, url);
                this._context.Add(notification);
                await Task.WhenAll(this._messengerProvider.Messengers.Select(x => x.Send(notification, subscription.Subscriber)));
            }
            await this._context.SaveChangesAsync();
        }
        public async Task SubscribeToAsync(MoxUser me, string subjectId, int?entityId = null, MoxUser userToWatch = null)
        {
            if (await this._context.Subscriptions.AnyAsync(x => x.SubscriberId == me.Id && x.SubjectId == subjectId))
            {
                return;
            }

            var sub = new Data.Models.Subscription()
            {
                SubscriberId = me.Id,
                SubjectId    = subjectId,
                EntityId     = entityId,
                SenderId     = userToWatch?.Id
            };

            this._context.Add(sub);
            await this._context.SaveChangesAsync();
        }
예제 #6
0
 public async Task Send(Notification notification, MoxUser reciever)
 {
     //throw new Exception("(#/)asjdalwjdlaiwjo");
 }
 public IQueryable <Notification> FetchUnread(MoxUser me)
 {
     return(this._context.Notifications.Where(x => x.RecieverId == me.Id && !x.IsRead).OrderByDescending(x => x.SentTime));
 }
 public Task SendToUserAsync(MoxUser me, MoxUser reciever, string subject, string shortDescription, string url)
 {
     throw new NotImplementedException();
 }
 public Task SendToEveryoneAsync(MoxUser me, string subject, string shortDescription, string url)
 {
     throw new NotImplementedException();
 }
 public async Task UnsubscribeFromAsync(MoxUser me, string subjectId, int?entityId = null, MoxUser user = null)
 {
     throw new NotImplementedException();
 }
 public IQueryable <Subscription> Subscriptions(MoxUser me)
 {
     return(this._context.Subscriptions.Where(x => x.SubscriberId == me.Id));
 }
        public IQueryable <Subscription> Subscriptions(string subjectId, int?entityId = null, MoxUser sender = null)
        {
            var s = this._context.Subscriptions.Where(x => x.SubjectId == subjectId);

            if (entityId.HasValue)
            {
                s = s.Where(x => x.EntityId == null || x.EntityId == entityId);
            }
            else
            {
                s = s.Where(x => x.EntityId == null);
            }

            if (sender != null)
            {
                s = s.Where(x => x.SenderId == null || x.SenderId == sender.Id);
            }
            else
            {
                s = s.Where(x => x.SenderId == null);
            }

            return(s);
        }