Ejemplo n.º 1
0
        private async Task JoinedProgramNotificationBadge(User registeredUser)
        {
            var program = await _programRepository.GetByIdAsync(registeredUser.ProgramId);

            var site = await _siteRepository.GetByIdAsync(registeredUser.SiteId);

            var notification = new Notification
            {
                PointsEarned = 0,
                Text         = $"<span class=\"fa fa-thumbs-o-up\"></span> You've successfully joined <strong>{site.Name}</strong>!",
                UserId       = registeredUser.Id,
                IsJoining    = true
            };

            if (program.JoinBadgeId != null)
            {
                var badge = await _badgeRepository.GetByIdAsync((int)program.JoinBadgeId);

                await _badgeRepository.AddUserBadge(registeredUser.Id, badge.Id);

                await _userLogRepository.AddAsync(registeredUser.Id, new UserLog
                {
                    UserId       = registeredUser.Id,
                    PointsEarned = 0,
                    IsDeleted    = false,
                    BadgeId      = badge.Id,
                    Description  = $"Joined {site.Name}!"
                });

                notification.BadgeId       = badge.Id;
                notification.BadgeFilename = badge.Filename;
            }
            await _notificationRepository.AddSaveAsync(registeredUser.Id, notification);
        }
        private async Task QuestionnaireNotificationBadge(Questionnaire questionnaire, int userId)
        {
            var badge = await _badgeRepository.GetByIdAsync(questionnaire.BadgeId.Value);

            await _badgeRepository.AddUserBadge(userId, badge.Id);

            await _userLogRepository.AddAsync(userId, new UserLog
            {
                UserId       = userId,
                PointsEarned = 0,
                IsDeleted    = false,
                BadgeId      = badge.Id,
                Description  = string.IsNullOrEmpty(questionnaire.BadgeNotificationMessage)
                    ? $"You completed the questionnaire: {questionnaire.Name}"
                    : questionnaire.BadgeNotificationMessage
            });

            var notification = new Notification
            {
                PointsEarned  = 0,
                Text          = questionnaire.BadgeNotificationMessage,
                UserId        = userId,
                BadgeId       = badge.Id,
                BadgeFilename = badge.Filename
            };

            await _notificationRepository.AddSaveAsync(userId, notification);
        }
        public async Task AddAsync(UserLogModel userLogModel)
        {
            var userLogEntity = UserLogFactory.Create(userLogModel);

            await _userLogRepository.AddAsync(userLogEntity);

            await _unitOfWork.SaveChangesAsync();
        }
        public async Task <IResult> AddAsync(UserLogModel userLogModel)
        {
            var validation = new UserLogModelValidator().Validate(userLogModel);

            if (validation.Failed)
            {
                return(Result.Fail(validation.Message));
            }

            var userLogEntity = UserLogFactory.Create(userLogModel);

            await _userLogRepository.AddAsync(userLogEntity);

            await _unitOfWork.SaveChangesAsync();

            return(Result.Success());
        }
Ejemplo n.º 5
0
        private async Task <User> AddPointsSaveAsync(int authUserId,
                                                     int activeUserId,
                                                     int whoEarnedUserId,
                                                     int pointsEarned)
        {
            if (pointsEarned < 0)
            {
                throw new GraException($"Cannot log negative points!");
            }

            var earnedUser = await _userRepository.GetByIdAsync(whoEarnedUserId);

            if (earnedUser == null)
            {
                throw new Exception($"Could not find a user with id {whoEarnedUserId}");
            }

            earnedUser.PointsEarned    += pointsEarned;
            earnedUser.IsActive         = true;
            earnedUser.LastActivityDate = DateTime.Now;

            // update the user's achiever status if they've crossed the threshhold
            var program = await _programRepository.GetByIdAsync(earnedUser.ProgramId);

            if (!earnedUser.IsAchiever &&
                earnedUser.PointsEarned >= program.AchieverPointAmount)
            {
                earnedUser.IsAchiever = true;

                var notification = new Notification
                {
                    PointsEarned = 0,
                    Text         = $"<span class=\"fa fa-certificate\"></span> Congratulations! You've achieved <strong>{program.AchieverPointAmount} points</strong> reaching the goal of the program!",
                    UserId       = earnedUser.Id,
                    IsAchiever   = true
                };

                var badge = await AwardBadgeAsync(activeUserId, program.AchieverBadgeId);

                if (badge != null)
                {
                    await _userLogRepository.AddAsync(activeUserId, new UserLog
                    {
                        UserId       = whoEarnedUserId,
                        PointsEarned = 0,
                        IsDeleted    = false,
                        BadgeId      = badge.Id,
                        Description  = $"You reached the goal of {program.AchieverPointAmount} points!"
                    });

                    notification.Text         += " You've also earned a badge!";
                    notification.BadgeId       = badge.Id;
                    notification.BadgeFilename = badge.Filename;
                }

                await _notificationRepository.AddSaveAsync(authUserId, notification);
            }

            // save user's changes
            if (activeUserId == earnedUser.Id ||
                authUserId == earnedUser.HouseholdHeadUserId)
            {
                earnedUser = await _userRepository.UpdateSaveNoAuditAsync(earnedUser);
            }
            else
            {
                earnedUser = await _userRepository.UpdateSaveAsync(activeUserId, earnedUser);
            }

            await AwardTriggersAsync(earnedUser.Id);

            return(earnedUser);
        }
Ejemplo n.º 6
0
        public async Task AddAsync(UserLogModel userLogModel)
        {
            var userLogEntity = UserLogFactory.Create(userLogModel);

            await _userLogRepository.AddAsync(userLogEntity);
        }