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));
        }
        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));
        }
        public ActionResult AwaitingPayment(string courseNiceUrl)
        {
            Course             course       = _coursesContent.GetCourseByNiceUrl(courseNiceUrl);
            string             username     = User.Identity.Name;
            CourseSubscription subscription = _subscriptions.GetSubscription(username, course.Id);

            if (subscription.Status != SubscriptionStatus.AwaitingPayment)
            {
                return(Redirect("/"));
            }

            AwaitingPaymentViewModel viewModel = new AwaitingPaymentViewModel
            {
                CourseName     = course.Title,
                SubscriptionId = subscription.Id,
                CoursePrice    = course.Price
            };

            return(View(viewModel));
        }
Ejemplo n.º 4
0
 public void Update(Course course)
 {
     this.courses.Update(course);
     this.courses.SaveChanges();
 }
Ejemplo n.º 5
0
 public void Delete(Course course)
 {
     this.courses.Delete(course);
     this.courses.SaveChanges();
 }
Ejemplo n.º 6
0
 public void Create(Course course)
 {
     this.courses.Add(course);
     this.courses.SaveChanges();
 }
Ejemplo n.º 7
0
 private void SetRelatedItemsInViewBag(Course course)
 {
     ViewBag.PossibleCategories =
         _categories.GetAll().Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Title, Selected = (course != null && course.CategoryId == x.Id) });
 }