/// <summary> /// Enter to the user's course /// </summary> /// <param name="id">Course catalog id</param> public IActionResult EnterCourse(string id) { var userprofile = _userprofileRepo?.GetUserProfileById(User.Identity.Name); if (userprofile == null) { _logger.LogCritical($"User profile { User.Identity.Name } not found."); ViewBag.ErrorMessage = _errorMsgs.AccountNotFound; return(View("Error")); } var lastActiveSubscription = userprofile.Subscriptions? .Where(it => !it.DeletedDate.HasValue) .Where(it => it.CourseCatalogId == id) .OrderBy(it => it.LastActiveDate) .LastOrDefault(); var isAnyActivatedSubscription = lastActiveSubscription != null; if (!isAnyActivatedSubscription) { ViewBag.ErrorMessage = _errorMsgs.NoLastActivatedCourse; return(View("Error")); } var courseInfo = _myCourseCtrl?.ChangeCourse(new Repositories.Models.ChangeCourseRequest { UserProfileId = User.Identity.Name, ClassRoomId = lastActiveSubscription.ClassRoomId }); return(RedirectToAction("Preparing", "My")); }