public ActionResult JoinCourse(JoinCourseViewModel model)
        {
            if (ModelState.IsValid)
            {
                Course course = _coursesContent.GetCourseByNiceUrl(model.CourseNiceUrl);
                if (course == null)
                {
                    return(HttpNotFound());
                }

                string username = User.Identity.Name;
                if (model.BillingInfo != null)
                {
                    var user = _users.GetByUsername(username);
                    user.BillingInfo = Mapper.Map(model.BillingInfo, user.BillingInfo);
                    _users.UpdateUser(user);
                }

                SubscriptionStatus status = _subscriptions.JoinCourse(username, course.Id);

                if (status == SubscriptionStatus.Active)
                {
                    IPublishedContent coursesPage = _coursesContent.GetCoursePublishedContentByNiceUrl(model.CourseNiceUrl);
                    return(Redirect(coursesPage.Url));
                }
                else
                {
                    return(RedirectToAction(nameof(AwaitingPayment), new { courseNiceUrl = model.CourseNiceUrl }));
                }
            }

            return(JoinCourse(model.CourseNiceUrl));
        }
예제 #2
0
        public async Task <IActionResult> Join(JoinCourseViewModel courseModel)
        {
            var currentUser      = User;
            var currentUserEmail = currentUser.FindFirst(ClaimTypes.Email).Value;

            var user = await _accountRepository.FindByEmailAsync(currentUserEmail);

            var course = _courseRepository.GetCourseById(courseModel.Id);

            if (course.InstructorId == user.Id)
            {
                ModelState.AddModelError("", "You cant join your own course as a student!");
                return(View());
            }

            var result = await _courseRepository.JoinCourseWithId(course, user);

            if (result < 1)
            {
                ModelState.AddModelError("", "Could not create!");
                return(View());
            }

            ModelState.Clear();
            return(RedirectToAction("JoinedCourses", "Course"));
        }
        public ActionResult JoinCourse(string courseNiceUrl)
        {
            Course course = _coursesContent.GetCourseByNiceUrl(courseNiceUrl);

            if (course == null)
            {
                return(HttpNotFound());
            }

            string             username           = User.Identity.Name;
            SubscriptionStatus subscriptionStatus = _subscriptions.GetSubscriptionStatus(username, course.Id);

            if (subscriptionStatus == SubscriptionStatus.Active)
            {
                IPublishedContent coursesPage = _coursesContent.GetCoursePublishedContentByNiceUrl(courseNiceUrl);
                return(Redirect(coursesPage.Url));
            }
            else if (subscriptionStatus == SubscriptionStatus.AwaitingPayment)
            {
                return(RedirectToAction(nameof(AwaitingPayment), new { courseNiceUrl = courseNiceUrl }));
            }

            JoinCourseViewModel viewModel = new JoinCourseViewModel
            {
                CourseName          = course.Title,
                CoursePrice         = course.Price,
                RequiresBillingInfo = _courses.IsPaidCourse(course)
            };

            if (viewModel.RequiresBillingInfo)
            {
                User user = _users.GetByUsername(username);
                viewModel.BillingInfo = Mapper.Map <BillingInfoViewModel>(user.BillingInfo);
            }

            IPublishedContent legalPage = Umbraco.TypedContentAtRoot().DescendantsOrSelf(nameof(LegalContent)).FirstOrDefault();
            int licenseAgreement        = legalPage.GetPropertyValue <int>(nameof(LegalContent.LicenseTerms));

            if (licenseAgreement != default(int))
            {
                IPublishedContent licenseAgreementPage = Umbraco.TypedContent(licenseAgreement);
                viewModel.LicenseTermsUrl = licenseAgreementPage.Url;
            }



            return(View(viewModel));
        }