示例#1
0
        // Delete a speciality.
        public async Task <ActionResult> DeleteSpeciality(int?id)
        {
            // Check id.
            if (!int.TryParse(id.ToString(), out int intId))
            {
                return(RedirectToAction("Index"));
            }
            // Get SpecialityDTO object.
            SpecialityDTO specialityDTO = await SpecialityService.GetAsync(intId);

            if (specialityDTO == null)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.SubjectName = specialityDTO.Subject.SubjectName;
            ViewBag.ParentId    = specialityDTO.SubjectId;
            // AutoMapper Setup.
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <SpecialityDTO, SpecialityViewModel>()
                .ForMember("Id", opt => opt.MapFrom(obj => obj.SpecialityId))
                .ForMember("Name", opt => opt.MapFrom(obj => obj.SpecialityName));
            });
            IMapper             iMapper    = config.CreateMapper();
            SpecialityViewModel speciality = iMapper.Map <SpecialityDTO, SpecialityViewModel>(specialityDTO);

            return(PartialView("~/Views/Admin/Speciality/DeleteSpeciality.cshtml", speciality));
        }
示例#2
0
        public async Task <ActionResult> DeleteSpeciality(int id)
        {
            string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if (currentUserId == null)
            {
                return(new HttpUnauthorizedResult());
            }
            SpecialityDTO specialityDTO = await SpecialityService.GetAsync(id);

            ViewBag.SubjectName = specialityDTO.Subject.SubjectName;
            ViewBag.ParentId    = specialityDTO.SubjectId;
            ViewBag.Action      = "SubjectSpecialities";
            if (specialityDTO != null)
            {
                OperationDetails operationDetails = await SpecialityService.DeleteAsync(id, currentUserId);

                if (operationDetails.Succedeed)
                {
                    return(PartialView("Report", operationDetails));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                    return(PartialView("Report", operationDetails));
                }
            }
            ViewBag.Message = "Non valid";
            return(PartialView("~/Views/Admin/Speciality/DeleteSpeciality.cshtml", specialityDTO));
        }
        public async Task <ActionResult> CreateCourse(int?specialityId)
        {
            try
            {
                // I. Checks.
                // Check id.
                if (!int.TryParse(specialityId.ToString(), out int intSpecialityId))
                {
                    return(RedirectToAction("Index"));
                }
                // Get a SpecialityDTO object.
                SpecialityDTO speciality = await SpecialityService.GetAsync(intSpecialityId);

                if (speciality == null)
                {
                    return(RedirectToAction("Index"));
                }

                // II. Set ViewBag properties.
                ViewBag.ParentId       = intSpecialityId;
                ViewBag.SpecialityName = speciality.SpecialityName;

                // III.
                return(PartialView());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public async Task <ActionResult> CreateCourse(CourseViewModel course)
        {
            try
            {
                // I. Checks.
                string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId();
                if (currentUserId == null)
                {
                    return(new HttpUnauthorizedResult());
                }

                // II. Set ViewBag properties.
                ViewBag.SpecialityName = (await SpecialityService.GetAsync(course.SpecialityId)).SpecialityName;
                ViewBag.ParentId       = course.SpecialityId;
                ViewBag.Action         = "SpecialityCourses";

                // III. Create a new course.
                if (ModelState.IsValid)
                {
                    CourseDTO courseDTO = new CourseDTO
                    {
                        UserProfileId             = currentUserId,
                        SpecialityId              = course.SpecialityId,
                        CourseTitle               = course.Name,
                        Description               = course.Description,
                        CourseTestQuestionsNumber = course.CourseTestQuestionsNumber,
                        TopicTestQuestionsNumber  = course.TopicTestQuestionsNumber,
                        TimeToAnswerOneQuestion   = course.TimeToAnswerOneQuestion,
                        AttemptsNumber            = course.AttemptsNumber,
                        PassingScore              = course.PassingScore,
                        IsApproved = course.IsApproved,
                        IsFree     = course.IsFree
                    };
                    OperationDetails operationDetails = await CourseService.CreateAsync(courseDTO, currentUserId);

                    if (operationDetails.Succedeed)
                    {
                        return(PartialView("Report", operationDetails));
                    }
                    else
                    {
                        ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                        return(PartialView("Report", operationDetails));
                    }
                }

                // IV.
                ViewBag.Message = "Non valid";
                return(PartialView(course));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#5
0
        // Create a course.
        public async Task <ActionResult> CreateCourse(int?specialityId)
        {
            // Check id.
            if (!int.TryParse(specialityId.ToString(), out int intId))
            {
                return(RedirectToAction("Index"));
            }
            // Get SpecialityDTO object.
            SpecialityDTO speciality = await SpecialityService.GetAsync(intId);

            if (speciality == null)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.ParentId       = intId;
            ViewBag.SpecialityName = speciality.SpecialityName;
            return(PartialView("~/Views/Admin/Course/CreateCourse.cshtml"));
        }
示例#6
0
        // Speciality courses list.
        public async Task <ActionResult> SpecialityCourses(int?id)
        {
            // I. Checks.
            // Check id.
            if (!int.TryParse(id.ToString(), out int intId))
            {
                return(RedirectToAction("Index"));
            }
            // Get SpecialityDTO object.
            SpecialityDTO specialityDTO = await SpecialityService.GetAsync(intId);

            if (specialityDTO == null)
            {
                return(RedirectToAction("Index"));
            }

            // II. Set ViewBag properties and Session[ParentParentIdForAdminController].
            ViewBag.ParentId       = intId;
            ViewBag.SpecialityName = specialityDTO.SpecialityName;
            ViewBag.ParentParentId = specialityDTO.SubjectId;
            // Set Session[ParentParentIdForAdminController].
            Session["ParentParentIdForAdminController"] = intId;

            // III. Get data for a view.
            // AutoMapper Setup.
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <CourseDTO, CourseViewModel>()
                .ForMember("Id", opt => opt.MapFrom(obj => obj.CourseId))
                .ForMember("Name", opt => opt.MapFrom(obj => obj.CourseTitle));
            });
            IMapper          iMapper = config.CreateMapper();
            List <CourseDTO> source  = CourseService.Find(dto => dto.SpecialityId == intId)
                                       .OrderBy(o => o.CourseTitle)
                                       .OrderBy(o => o.IsApproved).ToList();
            IEnumerable <CourseViewModel> courseOrderedList = iMapper.Map <IEnumerable <CourseDTO>, IEnumerable <CourseViewModel> >(source);

            return(View(courseOrderedList));
        }
示例#7
0
        public async Task <ActionResult> EditSpeciality(SpecialityViewModel speciality)
        {
            string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if (currentUserId == null)
            {
                return(new HttpUnauthorizedResult());
            }
            ViewBag.SubjectName = (await SpecialityService.GetAsync(speciality.Id)).Subject.SubjectName;
            ViewBag.ParentId    = speciality.SubjectId;
            ViewBag.Action      = "SubjectSpecialities";
            if (ModelState.IsValid)
            {
                SpecialityDTO specialityDTO = new SpecialityDTO
                {
                    SpecialityId   = speciality.Id,
                    SubjectId      = speciality.SubjectId,
                    SpecialityName = speciality.Name,
                    Description    = speciality.Description,
                    IsApproved     = speciality.IsApproved
                };
                OperationDetails operationDetails = await SpecialityService.UpdateAsync(specialityDTO, currentUserId);

                if (operationDetails.Succedeed)
                {
                    return(PartialView("Report", operationDetails));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                    return(PartialView("Report", operationDetails));
                }
            }
            ViewBag.Message = "Non valid";
            return(PartialView("~/Views/Admin/Speciality/EditSpeciality.cshtml", speciality));
        }
        // Speciality courses list.
        public async Task <ActionResult> SpecialityCourses(int?id)
        {
            try
            {
                // I.Checks.
                // Check id.
                if (!int.TryParse(id.ToString(), out int intId))
                {
                    return(RedirectToAction("Index"));
                }
                // Get SpecialityDTO object.
                SpecialityDTO specialityDTO = await SpecialityService.GetAsync(intId);

                if (specialityDTO == null)
                {
                    return(RedirectToAction("Index"));
                }

                // II. AutoMapper Setup.
                // Get Id for the current user.
                string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId();
                var    config        = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <CourseDTO, CourseViewModel>()
                    .ForMember("Id", opt => opt.MapFrom(obj => obj.CourseId))
                    .ForMember("Name", opt => opt.MapFrom(obj => obj.CourseTitle))
                    .ForMember("IsSubscribed", opt => opt.MapFrom(course =>
                                                                  course.Subscriptions.Where(subscription =>
                                                                                             currentUserId != null &&
                                                                                             subscription.UserProfileId == currentUserId &&
                                                                                             subscription.CourseId == course.CourseId &&
                                                                                             (DateTime.Now - subscription.StartDate < TimeSpan.FromDays(subscription.SubscriptionPeriod)) &&
                                                                                             subscription.IsApproved).Count() == 1))
                    .ForMember("IsInApproving", opt => opt.MapFrom(course =>
                                                                   course.Subscriptions.Where(subscription =>
                                                                                              currentUserId != null &&
                                                                                              subscription.UserProfileId == currentUserId &&
                                                                                              subscription.CourseId == course.CourseId &&
                                                                                              (DateTime.Now - subscription.StartDate < TimeSpan.FromDays(subscription.SubscriptionPeriod)) &&
                                                                                              !subscription.IsApproved).Count() == 1));
                    cfg.CreateMap <TestResultDTO, TestResultViewModel>()
                    .ForMember("Id", opt => opt.MapFrom(tr => tr.TestResultId))
                    .ForMember("TestTitle", opt => opt.MapFrom(tr => tr.TestResultDetails.FirstOrDefault().Question.Topic.Course.CourseTitle));
                    cfg.CreateMap <TestResultDetailDTO, TestResultDetailViewModel>()
                    .ForMember("Question", opt => opt.MapFrom(trd => trd.Question.QuestionText))
                    .ForMember("Topic", opt => opt.MapFrom(trd => trd.Question.Topic.TopicTitle));
                });
                IMapper iMapper = config.CreateMapper();

                // III. Set ViewBag properties.
                // Get a role name for the current user.
                if (currentUserId != null)
                {
                    ViewBag.RoleName = UserService.FindUserRoleById(currentUserId);
                }
                else
                {
                    ViewBag.RoleName = null;
                }
                ViewBag.ParentId       = intId;
                ViewBag.SpecialityName = specialityDTO.SpecialityName;
                ViewBag.ParentParentId = specialityDTO.SubjectId;
                IEnumerable <TestResultDTO> testResultDTOs = TestResultService.Find(tr =>
                                                                                    tr.UserProfileId == currentUserId &&
                                                                                    !tr.IsTopicTest);
                IEnumerable <TestResultViewModel> userTestResults = iMapper.Map <IEnumerable <TestResultDTO>, IEnumerable <TestResultViewModel> >(testResultDTOs);
                ViewBag.UserTestResults = userTestResults;

                // IV. Get data for a view.
                IEnumerable <CourseDTO> source = CourseService.Find(dto => dto.SpecialityId == intId && dto.IsApproved)
                                                 .OrderBy(o => o.CourseTitle).OrderByDescending(o => o.IsFree);
                IEnumerable <CourseViewModel> courseOrderedList = iMapper.Map <IEnumerable <CourseDTO>, IEnumerable <CourseViewModel> >(source);

                // V.
                return(View(courseOrderedList));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        // Speciality courses list.
        public async Task <ActionResult> SpecialityCourses(int?id)
        {
            try
            {
                // I. Checks.
                // Get Id for the current user.
                string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId();
                if (currentUserId == null)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                // Check id.
                if (!int.TryParse(id.ToString(), out int intId))
                {
                    return(RedirectToAction("Index"));
                }
                // Get SubjectDTO.
                SpecialityDTO specialityDTO = await SpecialityService.GetAsync(intId);

                if (specialityDTO == null)
                {
                    return(RedirectToAction("Index"));
                }

                // II. Set ViewBag properties.
                ViewBag.ParentId       = intId;
                ViewBag.SpecialityName = specialityDTO.SpecialityName;
                ViewBag.ParentParentId = specialityDTO.SubjectId;
                // If a current user is Admin.
                if (UserService.FindUserRoleById(currentUserId).ToLower() == "admin")
                {
                    ViewBag.IsAllowToAddCourses = true;
                    ViewBag.IsAdmin             = true;
                }
                else
                {
                    ViewBag.IsAdmin = false;
                    PLRepository.SetViewBagProperiesForModeratorSubscription(UserService, currentUserId,
                                                                             SubscriptionForModeratorService,
                                                                             out bool?viewBagIsAllowedToSuggest,
                                                                             out bool?viewBagGoToTrialSubscription,
                                                                             out bool?viewBagGoToSubscription);
                    ViewBag.GoToTrialSubscription = viewBagGoToTrialSubscription;
                    ViewBag.GoToSubscription      = viewBagGoToSubscription;
                    // Count of existed courses.
                    int existedCourseCount = CourseService.Find(dto => dto.UserProfileId == currentUserId).Count();
                    // Get count of allowed courses according to the active subscription.
                    IEnumerable <SubscriptionForModeratorDTO> subscriptions = SubscriptionForModeratorService.Find(obj =>
                                                                                                                   obj.UserProfileId == currentUserId &&
                                                                                                                   obj.IsApproved);
                    if (subscriptions.Count() == 0)
                    {
                        ViewBag.IsAllowToAddCourses = false;
                    }
                    else
                    {
                        int allowedCourseCount = (from sub in subscriptions
                                                  where sub.StartDate < DateTime.Now &&
                                                  (DateTime.Now - sub.StartDate < TimeSpan.FromDays(sub.SubscriptionPeriod) &&
                                                   sub.IsApproved)
                                                  select sub).FirstOrDefault().CourseCount;
                        bool isAllowToAddCourses = allowedCourseCount > existedCourseCount;
                        if (isAllowToAddCourses)
                        {
                            ViewBag.MessageAboutAllowedCourses = string.Format("According to terms of your subscription you are allowed {0} course(s). You can add {1} more course(s).",
                                                                               allowedCourseCount, allowedCourseCount - existedCourseCount);
                        }
                        else
                        {
                            ViewBag.MessageAboutAllowedCourses = "According to terms of your subscription you can't add a new course. Delete an unnecessary course or upgrade to a new subscription.";
                        }
                        ViewBag.IsAllowToAddCourses = isAllowToAddCourses;
                    }
                }

                // III. AutoMapper Setup.
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <CourseDTO, CourseViewModel>()
                    .ForMember("Id", opt => opt.MapFrom(obj => obj.CourseId))
                    .ForMember("Name", opt => opt.MapFrom(obj => obj.CourseTitle));
                });
                IMapper iMapper = config.CreateMapper();

                // IV. Get data for a view.
                IEnumerable <CourseDTO> source = CourseService.Find(dto => dto.SpecialityId == intId && dto.UserProfileId == currentUserId)
                                                 .OrderBy(o => o.CourseTitle)
                                                 .OrderBy(o => o.IsApproved);
                IEnumerable <CourseViewModel> courseOrderedList = iMapper.Map <IEnumerable <CourseDTO>, IEnumerable <CourseViewModel> >(source);

                // V.
                return(View(courseOrderedList));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }