Beispiel #1
0
        /// <summary>
        ///  The student takes the next assignment.
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="newAssignment"></param>
        /// <returns></returns>
        public async Task TakeAssignmentAsync(Guid Id, AddStudentAssignmentDTO newAssignment)
        {
            Func <IIncludable <Student>, IIncludable> include = i => i.Include(p => p.OldAssignments);

            var currentUser = await _studentRepository.GetAllAsync(include, i => i.AppUser.UserName == _loggedUser).ConfigureAwait(false);

            var currentStudent = currentUser.First();

            currentStudent.ThrowIfNullForGuidObject();

            var lastAssignment = currentStudent.OldAssignments.Where(i => i.FinishedDate >= DateTime.UtcNow);

            if (lastAssignment.Count() > 0)
            {
                throw new MilvaUserFriendlyException("UndeliveredHomework");
            }

            var toBeTakeAssignment = await _assignmentRepository.GetByIdAsync(Id, i => i.Level == currentStudent.Level).ConfigureAwait(false);

            toBeTakeAssignment.ThrowIfNullForGuidObject();

            var studentAssignment = new StudentAssigment
            {
                IsApproved                = false,
                AssigmentId               = toBeTakeAssignment.Id,
                StudentId                 = currentStudent.Id,
                AdditionalTime            = newAssignment.AdditionalTime,
                AdditionalTimeDescription = newAssignment.AdditionalTimeDescription,
                Status = Entity.Enum.EducationStatus.InProgress
            };

            await _studentAssignmentRepository.AddAsync(studentAssignment).ConfigureAwait(false);

            await _milvaMailSender.MilvaSendMailAsync(currentStudent.Mentor.AppUser.Email, Helpers.Enums.MailSubject.Information, currentStudent.Name + currentStudent.Surname + " isimli öğrencinin yeni bir ödev isteği var.");
        }
Beispiel #2
0
        /// <summary>
        /// Sends email to logged-in user's email.
        /// Please make sure <paramref name="localizedMailBodyContents"/> dictionary parameter taken from <see cref="PrepareMailBodyDictionary(string[])"/>.
        /// </summary>
        /// <param name="localizedMailBodyContents"></param>
        /// <param name="urlPath"></param>
        /// <param name="accountActivity"></param>
        /// <param name="newInfo"> Could be new phone number or new email. </param>
        /// <param name="username"></param>
        /// <returns></returns>
        private async Task SendActivityMailAsync(Dictionary <string, string> localizedMailBodyContents,
                                                 string urlPath,
                                                 AccountActivity accountActivity,
                                                 string newInfo  = null,
                                                 string username = null)
        {
            var uName = username ?? _userName;

            var user = await _userRepository.GetFirstOrDefaultAsync(a => a.UserName == _userName).ConfigureAwait(false)
                       ?? throw new MilvaUserFriendlyException(MilvaException.CannotFindEntity);

            if (string.IsNullOrWhiteSpace(user?.Email))
            {
                throw new MilvaUserFriendlyException("IdentityInvalidEmail");
            }

            string token = "";

            switch (accountActivity)
            {
            case AccountActivity.EmailVerification:
                token = await _userManager.GenerateEmailConfirmationTokenAsync(user).ConfigureAwait(false);

                break;

            case AccountActivity.EmailChange:
                token = await _userManager.GenerateChangeEmailTokenAsync(user, newInfo).ConfigureAwait(false);

                break;

            case AccountActivity.PasswordReset:
                token = await _userManager.GeneratePasswordResetTokenAsync(user).ConfigureAwait(false);

                break;

            case AccountActivity.PhoneNumberChange:
                token = await _userManager.GenerateChangePhoneNumberTokenAsync(user, newInfo).ConfigureAwait(false);

                break;
            }

            var confirmationUrl = $"{GlobalConstants.ApplicationSiteUrl}/{urlPath}?userName={username ?? _userName}&token={token}";

            var htmlContent = await File.ReadAllTextAsync(Path.Combine(GlobalConstants.RootPath, "StaticFiles", "HTML", "mail_content.html")).ConfigureAwait(false);

            foreach (var localizedMailBodyContent in localizedMailBodyContents)
            {
                htmlContent = htmlContent.Replace(localizedMailBodyContent.Key, localizedMailBodyContent.Value);
            }

            htmlContent = htmlContent.Replace("~BodyButtonLink", confirmationUrl);

            await _milvaMailSender.MilvaSendMailAsync(user.Email, localizedMailBodyContents["~MailTitle"], htmlContent, true);
        }
Beispiel #3
0
        /// <summary>
        /// Saves the log at fatal level. And sends mail to producer.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="mailSubjectsEnum"></param>
        public async Task LogFatalAsync(string message, MailSubject mailSubjectsEnum)
        {
            _logger.Fatal(message);

            await _milvaMailSender.MilvaSendMailAsync("*****@*****.**", mailSubjectsEnum, message).ConfigureAwait(false);
        }