예제 #1
0
        private static void CheckNotificationClaUsers(DefaultContext db, DateTime currentDbDate, ClaAccessNotification claAccessNotification)
        {
            DateTime checkDbDate = UserProfile.GetCheckDbDateForClaAccessNotification(claAccessNotification, currentDbDate);
            UserProfileWithRole[] userProfileWithRoles = db.Database.SqlQuery<UserProfileWithRole>(String.Format(GetNotificationClaUsersProcedureTemplate, checkDbDate)).ToArray();
            if (userProfileWithRoles.Length == 0)
                return;

            var modifiedUserIds = new List<int>();
            foreach (UserProfileWithRole userProfileWithRole in userProfileWithRoles)
            {
                if (userProfileWithRole.IsAdmin)
                    continue;

                if (userProfileWithRole.ClaAccessNotification == claAccessNotification)
                    continue;

                decimal amountRemains = userProfileWithRole.ClaAccessYearlyAccess - userProfileWithRole.ClaAccessAmount;
                string paymentInformation = BankAccountCache.GetPaymentInfo(db, userProfileWithRole.ClaAccessCurrency, userProfileWithRole.LyonessId, amountRemains);
                string textBody = String.Format(MailResource.TaskSchedulerController_NotificationAccessExpiration_TextBody, checkDbDate, paymentInformation);
                Mail.SendEmail(userProfileWithRole.Email1, MailResource.TaskSchedulerController_NotificationAccessExpiration_Subject, textBody, true, true);
                modifiedUserIds.Add(userProfileWithRole.UserId);
            }

            if (modifiedUserIds.Count == 0)
                return;

            var sqlCommand = new StringBuilder();
            foreach (int modifiedUserId in modifiedUserIds)
            {
                sqlCommand.AppendLine(String.Format(SetNotificationClaUsersProcedureTemplate, modifiedUserId, (int)claAccessNotification));
            }
            db.Database.ExecuteSqlCommand(sqlCommand.ToString());
        }
예제 #2
0
        public static DateTime GetCheckDbDateForClaAccessNotification(ClaAccessNotification claAccessNotification, DateTime currentDateTime)
        {
            switch (claAccessNotification)
            {
                case ClaAccessNotification.Monthly:
                    return currentDateTime.AddMonths(1);

                case ClaAccessNotification.Fortnightly:
                    return currentDateTime.AddDays(14);

                case ClaAccessNotification.ThreeDays:
                    return currentDateTime.AddDays(3);

                case ClaAccessNotification.Current:
                    return currentDateTime.AddDays(0);

                default:
                    throw new ArgumentOutOfRangeException("claAccessNotification");
            }
        }