public void SendDigest(int userId)
 {
     try
     {
         var user = _db.Users.Find(userId);
         if (user.TsMailDigest.AddDays(user.DigestDaysSpan) < DateTime.UtcNow)
         {
             var services = new List <IDigestService>
             {
                 new NewsSrv(),
                 new DiscussionSrv(),
                 //new BlogSrv(),
                 new EventSrv(),
                 //new JobSrv(),
                 //new MentorSrv(),
                 //new MessageSrv(),
             };
             var userSrv = new UserDigest(userId, services);
             MailSrv.SendNewsletterAsync(user, userSrv.GetDigest(), "NITCAA Newsletter", null);
             //user.TsMailDigest = DateTime.UtcNow;
             //UpdateUser(user);
         }
     }
     catch (Exception ex)
     {
         AddLog(userId + "#SendDigest-Failure#" + ex.Message, LogTypes.Error, "Server");
     }
 }
Beispiel #2
0
        public void SendPasswordResetToken(string email)
        {
            var user = FindUserByEmail(email);

            if (user == null)
            {
                throw new SimpleException(Strings.EmailNotReg);
            }
            user.PasswordResetToken = _hashService.CreateTokenWithUserId(user.UserId, Constants.PasswordResetTokenLen);
            user.PasswordExpiryTime = DateTime.UtcNow.Add(TimeSpan.FromHours(Constants.PasswordExpTimeHrs));
            UpdateUser(user);
            MailSrv.SendPreDefMailAsync(user, MailType.ForgotPassword, null);
        }
        public void SendEmailValidationToken(User user)
        {
            if (user.EmailConfirmedOn != null)
            {
                throw new SimpleException(string.Format("The email '{0}' is already confirmed", user.Email));
            }
            var token = _hashService.CreateTokenWithUserId(user.UserId, Constants.EmailVerificationTokenLen);

            user.EmailConfirmationToken = token;
            UpdateUser(user);
            MailSrv.SendPreDefMailAsync(user, MailType.EmailConfirmation, null);
            AddUserLog(user.UserId, "Email validation token send");
        }
        public User UpdateRegStatus(int userId, UserRegisterStatus status)
        {
            var user = _db.Users.Find(userId);

            if (user == null)
            {
                new SimpleException(Strings.UserNotFoundById, userId);
            }
            user.AccountStatus = status;
            user.ApprovedOn    = DateTime.UtcNow;
            _db.SaveChanges();
            if (status == UserRegisterStatus.Approved)
            {
                MailSrv.SendPreDefMailAsync(user, MailType.RegApproved, null);
            }
            AddUserLog(user.UserId, "Registration status updated : " + status.ToString());
            return(user);
        }
Beispiel #5
0
        public void SendEmailNotification(int eventId)
        {
            var evt     = _db.Events.Include(e => e.Invitees).Single(e => e.EventId == eventId);
            var user    = _db.Users.Find(CurrUserId);
            var comment = new EventComment
            {
                Text       = "Email notification send by " + user.FullName,
                SenderId   = user.UserId,
                SenderName = user.FullName,
                EventId    = eventId
            };

            _db.EventComments.Add(comment);
            _db.SaveChanges();

            var users    = _db.Users.ToList();
            var ivtIds   = evt.Invitees.Select(i => i.UserId).ToList();
            var code     = evt.GetVisibilityCode();
            var invitees = users.Where(u => ivtIds.Contains(u.UserId) || ((u.GetVisibilityCode() & code)) > 0).ToList();

            MailSrv.SendMailToManyAsync(invitees, evt.EmailMessage, "NITCAA Event | " + evt.EventName);
        }