示例#1
0
        public IActionResult Detail(string id, bool isCouponInvalid = false)
        {
            try
            {
                var selectedCourse = _courseCtrl?.GetCourseDetail(id);
                if (selectedCourse == null)
                {
                    ViewBag.ErrorMessage = _errorMsgs.CourseNotFound;
                    return(View("Error"));
                }

                var allUserCourses              = Enumerable.Empty <string>();
                var isAlreadyLoggedIn           = User?.Identity?.IsAuthenticated ?? false;
                var isAlreadyHaveSelectedCourse = isAlreadyLoggedIn ? !_myCourseCtrl.CanAddNewCourseCatalog(User.Identity.Name, selectedCourse.id, out allUserCourses) : false;

                ViewBag.IsAlreadyHaveThisCourse = isAlreadyHaveSelectedCourse;
                ViewBag.IsCouponInvalid         = isCouponInvalid;
                ViewBag.MindSageUrl             = _appConfig.MindSageUrl;

                return(View(selectedCourse));
            }
            catch (Exception e)
            {
                _logger.LogError($"MongoDB: { e.ToString() }");
                ViewBag.ErrorMessage = _errorMsgs.CanNotConnectToTheDatabase;
                return(View("Error"));
            }
        }
        public IActionResult Index(string id)
        {
            try
            {
                var selectedCourse = _courseCtrl.GetCourseDetail(id);
                if (selectedCourse == null)
                {
                    ViewBag.ErrorMessage = _errorMsgs.CourseNotFound;
                    return(View("Error"));
                }

                var selectedUserProfile = _userprofileRepo.GetUserProfileById(User.Identity.Name);
                if (selectedUserProfile == null)
                {
                    _logger.LogCritical($"User profile { User.Identity.Name } not found.");
                    ViewBag.ErrorMessage = _errorMsgs.AccountNotFound;
                    return(View("Error"));
                }

                var selectedClassRoom = _classRoomRepo.GetPublicClassRoomByCourseCatalogId(id);
                if (selectedClassRoom == null)
                {
                    _logger.LogCritical($"ClassRoom of CourseId: { id } not found.");
                    ViewBag.ErrorMessage = _errorMsgs.SelectedCourseIsNotAvailableForPurchase;
                    return(View("Error"));
                }

                var isAlreadyHaveTheSelectedCourse = !_myCourseCtrl.CanAddNewCourseCatalog(User.Identity.Name, id);
                if (isAlreadyHaveTheSelectedCourse)
                {
                    return(RedirectToAction("entercourse", "my", new { @id = id }));
                }

                var model = new PurchaseCourseViewModel
                {
                    CourseId          = id,
                    TotalChargeAmount = selectedCourse.PriceUSD
                };
                return(View(model));
            }
            catch (Exception e)
            {
                _logger.LogError($"MongoDB: { e.ToString() }");
                ViewBag.ErrorMessage = _errorMsgs.CanNotConnectToTheDatabase;
                return(View("Error"));
            }
        }
示例#3
0
        public IActionResult Detail(string id, bool isCouponInvalid = false)
        {
            var selectedCourse = _courseCtrl.GetCourseDetail(id);

            if (selectedCourse == null)
            {
                return(RedirectToAction("Error"));
            }

            var allUserCourses = Enumerable.Empty <string>();
            var isAlreadyHaveSelectedCourse = _myCourseCtrl.CanAddNewCourseCatalog(User.Identity.Name, selectedCourse.id, out allUserCourses);

            ViewBag.IsAlreadyHaveThisCourse = isAlreadyHaveSelectedCourse;
            ViewBag.HaveAnyCourse           = allUserCourses.Any();
            ViewBag.IsCouponInvalid         = isCouponInvalid;

            return(View(selectedCourse));
        }
        public IActionResult Index(PurchaseCourseViewModel model)
        {
            if (ModelState.IsValid)
            {
                // HACK: Validate tracking form
                var selectedCourse = _courseCtrl.GetCourseDetail(model.CourseId);
                if (selectedCourse == null)
                {
                    return(View("Error"));
                }

                var data = new PurchaseCourseConfirmViewModel(model)
                {
                    TotalChargeAmount = selectedCourse.Price
                };
                return(View("Confirm", data));
            }
            return(View(model));
        }