public async Task <IActionResult> ShowTestsInTopicToUser(int topicId, string search, int page = 1, int size = 5) { string userEmail = User.Identity.Name; int userId = await _userManager.GetUserIdAsync(userEmail); if (!await _testManager.IsUserTopicExistsAsync(userId, topicId)) { var userTopic = new DomainUserTopic { UserId = userId, TopicId = topicId, Status = TopicStatus.NotStarted, Points = 0 }; await _testManager.CreateUserTopicAsync(userTopic); } List <int> topicTestIds = (await _testManager.GetTestsInTopicAsync(topicId)) .Select(x => x.Id) .ToList(); List <int> userTopicTestIds = (await _testManager.GetUserTestsInTopicAsync(topicId, userId)) .Select(x => x.TestId).ToList(); foreach (int testId in topicTestIds) { if (!userTopicTestIds.Contains(testId)) { var domainUserTest = new DomainUserTest { Status = TestStatus.NotStarted, TestId = testId, UserId = userId, }; if (!await _testManager.IsUserTestExistsAsync(userId, testId)) { await _testManager.CreateUserTestAsync(domainUserTest); } } } IReadOnlyCollection <UserTestModel> userTopicTests = (await _testManager.GetUserTestsInTopicAsync(topicId, userId)) .Select(x => _mapper.Map <UserTestModel>(x)).ToList(); ViewData["TopicId"] = topicId; ViewData["Search"] = search == null ? string.Empty : search; ViewData["Page"] = page; ViewData["Size"] = size; return(View(userTopicTests)); }
public async Task <IActionResult> ConfirmEmail(int userId, string confirmationToken) { if (!User.Identity.IsAuthenticated) { var domainUser = await _userManager.GetUserByIdAsync(userId); if (!domainUser.IsConfirmed) { if (domainUser.ConfirmationToken.ToString() == confirmationToken) { await _userManager.UpdateUserConfirmStatus(userId, true); List <DomainTopic> domainTopics = await _testManager.GetTopicsAsync(null).ToListAsync(); foreach (var domainTopic in domainTopics) { var userTopic = new DomainUserTopic { UserId = userId, TopicId = domainTopic.Id, Status = TopicStatus.NotStarted, IsTopicAsigned = domainTopic.TopicType == TopicType.Public ? true : false, Points = 0 }; await _testManager.CreateUserTopicAsync(userTopic); } return(RedirectToAction("Login", "Account")); } else { return(RedirectToAction("ConfirmEmailPage", "Account", new { @UserId = domainUser.Id })); } } } return(BadRequest()); }