Exemple #1
0
        public virtual ActionResult Profiles(string username)
        {
            var user = userService.FindByUsername(username);

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

            var packages = (from p in packageService.FindPackagesByOwner(user) where p.Listed orderby p.Version descending group p by p.PackageRegistration.Id).Select(c => new PackageViewModel(c.First()))
                           .ToList();

            var packagesInModeration =
                (from p in packageService.FindPackagesByOwner(user) where p.Status == PackageStatusType.Submitted orderby p.Version descending group p by p.PackageRegistration.Id).Select(
                    c => new PackageViewModel(c.First())).ToList();

            //var userProfiles = profilesService.GetUserProfiles(user).ToList();
            var userProfiles     = (from p in profilesService.GetUserProfiles(user) orderby p.Name select p).Select(c => new UserSiteProfileViewModel(c)).ToList();
            var completedCourses = (from p in courseAchievementsService.GetUserCourseAchievements(user) orderby p.CompletedDate select p).Select(c => new CourseAchievementViewModel(c)).ToList();
            var model            = new UserProfileModel
            {
                Username                  = user.Username,
                EmailAddress              = user.EmailAddress,
                Packages                  = packages,
                PackagesModerationQueue   = packagesInModeration,
                TotalPackageDownloadCount = packages.Sum(p => p.TotalDownloadCount),
                UserProfiles              = userProfiles,
                CompletedCourses          = completedCourses,
            };

            return(View("~/Views/Users/Profiles.cshtml", model));
        }
        public virtual ActionResult Courses()
        {
            var courseModules = courseModuleRepo.GetAll()
                                .Include(cm => cm.Course)
                                .ToList();

            var courseModulesView = new List <CourseModuleViewModel>();

            // TODO need some automapper action here
            foreach (var module in courseModules.OrEmptyListIfNull())
            {
                courseModulesView.Add(
                    new CourseModuleViewModel()
                {
                    CourseKey               = module.CourseKey,
                    CourseModuleKey         = module.Key,
                    CourseModuleDescription = module.Description,
                    CourseModuleName        = module.Name,
                    ModuleOrder             = module.Order,
                    ModuleNameType          = module.CourseModuleNameType,
                });
            }

            var model = new CourseViewModel
            {
                CourseModules = courseModulesView,
            };

            if (Request.IsAuthenticated)
            {
                var user = userService.FindByUsername(currentUser.Identity.Name);
                var userCourseAchievements = (from p in courseAchievementsService.GetUserCourseAchievements(user) orderby p.CompletedDate select p)
                                             .Select(c => new CourseAchievementViewModel(c))
                                             .ToList();

                model.Username = user.Username;
                model.UserKey  = user.Key;
                model.UserCourseAchievements = userCourseAchievements;

                TempData.Clear();
            }

            return(View("~/Views/Courses/Home.cshtml", model));
        }