示例#1
0
        private E_ReminderCreationStatus TryCreateReminder(ReminderModel model)
        {
            string passwordHash = Security.GetSHA1Hash(model.Password);
            E_ReminderCreationStatus resultStatus = E_ReminderCreationStatus.error;


            E_VerificationStatus verificationStatus = ReminderRepository.GetVerificationStatus(model.Email, passwordHash);
            int      mailID = 0;
            DateTime nextReminder;

            switch (verificationStatus)
            {
            case E_VerificationStatus.emailUnknown:
                Guid verificationCode = Guid.NewGuid();
                int  emailID          = ReminderRepository.InsertUnverifiedEmail(model.Email, passwordHash, verificationCode);
                MessageService.SendVerificationEmail(model.Email, verificationCode);
                nextReminder = GetNextRemindingDate(model, DateTime.Now);
                ReminderRepository.AddReminder(model, emailID, nextReminder);

                resultStatus = E_ReminderCreationStatus.successVerifyEmail;

                Logger.LogInfo(
                    string.Format("unkown address remindii for:'{0}', Name: {1}"
                                  , model.Email, model.Name));
                break;

            case E_VerificationStatus.emailNotYetVerified:
                mailID       = ReminderRepository.GetEmailID(model.Email);
                nextReminder = GetNextRemindingDate(model, DateTime.Now);
                ReminderRepository.AddReminder(model, mailID, nextReminder);
                resultStatus = E_ReminderCreationStatus.successVerifyEmail;

                Logger.LogInfo(
                    string.Format("not verified remindii for:'{0}', Name: {1}"
                                  , model.Email, model.Name));
                break;

            case E_VerificationStatus.successfull:
                mailID       = ReminderRepository.GetEmailID(model.Email);
                nextReminder = GetNextRemindingDate(model, DateTime.Now);
                ReminderRepository.AddReminder(model, mailID, nextReminder);
                resultStatus = E_ReminderCreationStatus.successfull;
                Logger.LogInfo(
                    string.Format("verified remindii for:'{0}', Name: {1}"
                                  , model.Email, model.Name));
                break;

            case E_VerificationStatus.wrongPassword:
                resultStatus = E_ReminderCreationStatus.wrongPassword;
                Logger.LogInfo("Wrong password for email: " + model.Email);
                break;
            }

            if (resultStatus == E_ReminderCreationStatus.error)
            {
                throw new ApplicationException("Fehler");
            }
            return(resultStatus);
        }