Exemplo n.º 1
0
        public async Task UpdatePushChannelAsync(Guid userId, string channel)
        {
            var user = await dbContext.Users.FirstOrDefaultAsync(u => u.UserId == userId);

            user.PushChannel = channel;
            dbContext.Update(user);
            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task <NotificationModel> AddUserNotification(NotificationEventModel notication)
        {
            var template = dbContext.Templates.FirstOrDefault(x => x.EventType == notication.Type);

            if (template == null)
            {
                return(null);
            }

            var entity = new NotificationEntity
            {
                UserId    = notication.UserId,
                DateAdded = DateTime.Now,
                EventType = notication.Type
            };

            entity.Message = template.Body;

            entity.Message = entity.Message.Replace("{Firstname}", notication.Data.FirstName);
            entity.Message = entity.Message.Replace("{OrganisationName}", notication.Data.OrganisationName);
            entity.Message = entity.Message.Replace("{AppointmentDateTime}", notication.Data.AppointmentDateTime);
            entity.Message = entity.Message.Replace("{Reason}", notication.Data.Reason);

            await dbContext.Notifications.AddAsync(entity).ConfigureAwait(false);

            await dbContext.SaveChangesAsync().ConfigureAwait(false);

            return(new NotificationModel()
            {
                Id = entity.Id,
                Message = entity.Message,
                EventType = entity.EventType,
                UserId = entity.UserId
            });
        }
Exemplo n.º 3
0
        public async Task RegisterAsync(Guid userId, string password)
        {
            var passwordHash = encrypter.GetHash(password);
            var token        = encrypter.GetToken(userId, passwordHash);
            var user         = new User(userId, passwordHash, token);

            dbContext.Add(user);
            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <NotificationModel> AddNotificationAsync(NotificationModel notificationModel)
        {
            // todo: more validation
            if (notificationModel == null)
            {
                throw new ArgumentNullException();
            }

            await dbContext.Notifications.AddAsync(mapper.Map <NotificationEntity>(notificationModel));

            await dbContext.SaveChangesAsync();

            return(notificationModel);
        }
        public async Task <IActionResult> Notify(int userId, [FromBody] NotifyRequest request)
        {
            if (!await usersClient.DoesUserExistAsync(userId))
            {
                return(BadRequest(string.Format(UserDoesNotExist, userId)));
            }
            var notification = new Notification
            {
                RedirectPath = request.RedirectPath,
                CreatedAt    = DateTime.Now,
                Body         = request.Body,
                Subject      = request.Subject,
                UserId       = userId
            };

            db.Notifications.Add(notification);
            await db.SaveChangesAsync();

            var proxy = hub.Clients.User(userId.ToString());

            await proxy.SendAsync("notification", notification);

            return(Ok(notification.NotificationId));
        }
Exemplo n.º 6
0
        public static async Task PublishForUser(this NotificationsDbContext ns,
                                                int userId,
                                                string entityType,
                                                string entityKey,
                                                string summary,
                                                string description)
        {
            var notification = new Notifications.Notification(
                new EntityReference(NotificationRecipientType.UserId.Value, userId.ToString()),
                new EntityReference(entityType, entityKey),
                summary,
                description);

            ns.Notifications.Add(notification);
            await ns.SaveChangesAsync();
        }
        public async Task <NotificationModel> SaveNotification(NotificationModel notificationModel)
        {
            var notificationEntity = mapper.Map <NotificationEntity>(notificationModel);

            if (notificationModel.Id == Guid.Empty)
            {
                dbContext.Notifications.Add(notificationEntity);
            }
            else
            {
                dbContext.Notifications.Update(notificationEntity);
            }

            await dbContext.SaveChangesAsync();

            return(mapper.Map <NotificationModel>(notificationEntity));
        }
Exemplo n.º 8
0
        public async Task SaveToken(string accessToken)
        {
            var token = dbContext.Tokens.FirstOrDefault();

            if (token == null)
            {
                dbContext.Tokens.Add(new Models.Token()
                {
                    WNSToken = accessToken
                });
            }
            else
            {
                token.WNSToken = accessToken;
                dbContext.Tokens.Update(token);
            }
            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 9
0
        public static async Task PublishForUser <T>(
            this NotificationsDbContext ns,
            string description,
            T entity,
            int sendToUserId,
            string summary,
            NotificationCategory category)
            where T : DomainEntity
        {
            var notification = new Notification(
                new EntityReference(NotificationRecipientType.UserId.Value, sendToUserId.ToString()),
                new EntityReference(typeof(T).FullName, entity.Key.ToString()),
                summary,
                description,
                category.Id);

            ns.Notifications.Add(notification);
            await ns.SaveChangesAsync();
        }