Пример #1
0
        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"));
            }
        }