Exemplo n.º 1
0
        private async Task <bool> TryFinishTopicAndIfTopicIsFinishedSendEmail(int userId, int topicId) // fasle if topic is finished
        {
            if ((await _testManager.GetUserTopicAsync(userId, topicId)).Status == TopicStatus.Finished)
            {
                return(false);
            }

            List <DomainUserTest> userTestsInTopic = (await _testManager.GetUserTestsInTopicAsync(topicId, userId)).ToList();

            if (userTestsInTopic.All(x => x.Status == TestStatus.Finished))
            {
                await _testManager.UpdateUserTopicStatus(userId, topicId, TopicStatus.Finished);

                int         userPoints = userTestsInTopic.Sum(x => x.Points);
                DomainTopic topic      = await _testManager.GetTopicByIdAsync(topicId);

                await _testManager.UpdateUserTopicPoints(userId, topic.Id, userPoints);

                SendEmailToUserAboutPassingTheTopicAsync(User.Identity.Name, topic, userPoints);

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        private async Task SendEmailToUserAboutPassingTheTopicAsync(string userEmail, DomainTopic topic, int userPoints)
        {
            string subject    = "Test System";
            string senderName = "Test System Administration";

            if (userPoints >= topic.PassingPoints)
            {
                string messgae = $"You succesfully passed all tests in {topic.Name}! Your points: {userPoints} / {topic.PassingPoints}";

                _emailService.SendEmailAsync(senderName, WebExtensions.SenderEmail, WebExtensions.SenderEmailPassword, WebExtensions.SmtpHost,
                                             WebExtensions.SmtpPort, userEmail, subject, messgae);
            }
            else
            {
                string messgae = $"Sorry, you haven't gained enough points in {topic.Name}! Your points: {userPoints} / {topic.PassingPoints}";

                _emailService.SendEmailAsync(senderName, WebExtensions.SenderEmail, WebExtensions.SenderEmailPassword, WebExtensions.SmtpHost,
                                             WebExtensions.SmtpPort, userEmail, subject, messgae);
            }
        }