Exemple #1
0
        private async Task <IActionResult> ShowLandingPageAsync(Site site, SiteStage siteStage)
        {
            string siteName = HttpContext.Items[ItemKey.SiteName]?.ToString();

            PageTitle = siteName;
            switch (siteStage)
            {
            case SiteStage.BeforeRegistration:
                var viewModel = new BeforeRegistrationViewModel
                {
                    SignUpSource = nameof(SiteStage.BeforeRegistration),
                    SiteName     = siteName
                };
                if (site != null)
                {
                    viewModel.CollectEmail = await _siteLookupService
                                             .GetSiteSettingBoolAsync(site.Id,
                                                                      SiteSettingKey.Users.CollectPreregistrationEmails);

                    if (site.RegistrationOpens != null)
                    {
                        viewModel.RegistrationOpens
                                  = ((DateTime)site.RegistrationOpens).ToString("D");
                        PageTitle = _sharedLocalizer[Annotations.Title.RegistrationOpens,
                                                     siteName,
                                                     viewModel.RegistrationOpens];
                    }
                }
                return(View(ViewTemplates.BeforeRegistration, viewModel));

            case SiteStage.RegistrationOpen:
                PageTitle = _sharedLocalizer[Annotations.Title.JoinNow, siteName];
                return(View(ViewTemplates.RegistrationOpen, siteName));

            case SiteStage.ProgramEnded:
                return(View(ViewTemplates.ProgramEnded, siteName));

            case SiteStage.AccessClosed:
                var acViewModel = new AccessClosedViewModel
                {
                    SignUpSource = nameof(SiteStage.AccessClosed),
                };
                if (site != null)
                {
                    acViewModel.SiteName     = site.Name;
                    acViewModel.CollectEmail = await _siteLookupService
                                               .GetSiteSettingBoolAsync(site.Id,
                                                                        SiteSettingKey.Users.CollectAccessClosedEmails);
                }
                return(View(ViewTemplates.AccessClosed, acViewModel));

            default:
                PageTitle = _sharedLocalizer[Annotations.Title.JoinNow, siteName];
                return(View(ViewTemplates.ProgramOpen, siteName));
            }
        }
Exemple #2
0
        public async Task <IActionResult> Index()
        {
            var site = await GetCurrentSiteAsync();

            if (site != null)
            {
                PageTitle = site.Name;
            }
            if (AuthUser.Identity.IsAuthenticated)
            {
                // signed-in users can view the dashboard
                var user = await _userService.GetDetails(GetActiveUserId());

                var badges = await _userService.GetPaginatedBadges(user.Id, 0, BadgesToDisplay);

                foreach (var badge in badges.Data)
                {
                    badge.Filename = _pathResolver.ResolveContentPath(badge.Filename);
                }

                var pointTranslation = await _activityService.GetUserPointTranslationAsync();

                DashboardViewModel viewModel = new DashboardViewModel()
                {
                    FirstName                 = user.FirstName,
                    CurrentPointTotal         = user.PointsEarned,
                    SingleEvent               = pointTranslation.IsSingleEvent,
                    ActivityDescriptionPlural = pointTranslation.ActivityDescriptionPlural,
                    Badges            = badges.Data,
                    DisableSecretCode = await GetSiteSettingBoolAsync(SiteSettingKey.SecretCode.Disable)
                };

                var program = await _siteService.GetProgramByIdAsync(user.ProgramId);

                if (program.DailyLiteracyTipId.HasValue)
                {
                    var day = _siteLookupService.GetSiteDay(site);
                    if (day.HasValue)
                    {
                        var image = await _dailyLiteracyTipService.GetImageByDayAsync(
                            program.DailyLiteracyTipId.Value, day.Value);

                        if (image != null)
                        {
                            var imagePath = Path.Combine($"site{site.Id}", "dailyimages",
                                                         $"dailyliteracytip{program.DailyLiteracyTipId}",
                                                         $"{image.Id}{image.Extension}");
                            if (System.IO.File.Exists(_pathResolver.ResolveContentFilePath(imagePath)))
                            {
                                var dailyLiteracyTip = await _dailyLiteracyTipService
                                                       .GetByIdAsync(program.DailyLiteracyTipId.Value);

                                viewModel.DailyImageMessage = dailyLiteracyTip.Message;
                                viewModel.DailyImagePath    = _pathResolver.ResolveContentPath(imagePath);
                            }
                        }
                    }
                }

                if (TempData.ContainsKey(TempDataKey.UserJoined))
                {
                    TempData.Remove(TempDataKey.UserJoined);
                    viewModel.SitePath    = site.Path;
                    viewModel.ProgramName = program.Name;
                    viewModel.UserJoined  = true;
                }

                var userAvatar = await _avatarService.GetUserAvatarAsync();

                if (userAvatar?.Count > 0)
                {
                    var avatarElements = userAvatar;
                    foreach (var element in avatarElements)
                    {
                        element.Filename = _pathResolver.ResolveContentPath(element.Filename);
                    }
                    viewModel.AvatarElements = avatarElements;
                }

                var dashboardPage = await _dashboardContentService.GetCurrentContentAsync();

                if (dashboardPage != null && !string.IsNullOrWhiteSpace(dashboardPage.Content))
                {
                    viewModel.DashboardPageContent = CommonMark.CommonMarkConverter
                                                     .Convert(dashboardPage.Content);
                }

                if (TempData.ContainsKey(ModelData))
                {
                    var model = Newtonsoft.Json.JsonConvert
                                .DeserializeObject <DashboardViewModel>((string)TempData[ModelData]);
                    viewModel.ActivityAmount = model.ActivityAmount;
                    viewModel.Title          = model.Title;
                    viewModel.Author         = model.Author;
                }
                if (TempData.ContainsKey(ActivityErrorMessage))
                {
                    ModelState.AddModelError("ActivityAmount", (string)TempData[ActivityErrorMessage]);
                    viewModel.ActivityAmount = null;
                }
                if (TempData.ContainsKey(TitleErrorMessage))
                {
                    ModelState.AddModelError("Title", (string)TempData[TitleErrorMessage]);
                }
                if (TempData.ContainsKey(AuthorErrorMessage))
                {
                    ModelState.AddModelError("Author", (string)TempData[AuthorErrorMessage]);
                }
                if (TempData.ContainsKey(SecretCodeMessage))
                {
                    viewModel.SecretCodeMessage = (string)TempData[SecretCodeMessage];
                }

                if (user.DailyPersonalGoal.HasValue)
                {
                    var programDays = (int)Math.Ceiling((
                                                            site.ProgramEnds.Value - site.ProgramStarts.Value).TotalDays);
                    viewModel.TotalProgramGoal = programDays * user.DailyPersonalGoal.Value;
                    viewModel.ActivityEarned   = await _activityService.GetActivityEarnedAsync();

                    viewModel.PercentComplete = Math.Min(
                        (int)(viewModel.ActivityEarned * 100 / viewModel.TotalProgramGoal), 100);
                }

                return(View("Dashboard", viewModel));
            }
            else
            {
                // TODO handle pages if they are assigned in lieu of views
                switch (GetSiteStage())
                {
                case SiteStage.BeforeRegistration:
                    var viewModel = new BeforeRegistrationViewModel
                    {
                        SignUpSource = "BeforeRegistration"
                    };
                    if (site != null)
                    {
                        viewModel.CollectEmail = await _siteLookupService
                                                 .GetSiteSettingBoolAsync(site.Id,
                                                                          SiteSettingKey.Users.CollectPreregistrationEmails);

                        if (site.RegistrationOpens != null)
                        {
                            viewModel.RegistrationOpens
                                = ((DateTime)site.RegistrationOpens).ToString("D");
                        }
                    }
                    return(View("IndexBeforeRegistration", viewModel));

                case SiteStage.RegistrationOpen:
                    return(View("IndexRegistrationOpen"));

                case SiteStage.ProgramEnded:
                    return(View("IndexProgramEnded"));

                case SiteStage.AccessClosed:
                    var acViewModel = new AccessClosedViewModel
                    {
                        SignUpSource = "AccessClosed"
                    };
                    if (site != null)
                    {
                        acViewModel.CollectEmail = await _siteLookupService
                                                   .GetSiteSettingBoolAsync(site.Id,
                                                                            SiteSettingKey.Users.CollectAccessClosedEmails);
                    }
                    return(View("IndexAccessClosed", acViewModel));

                case SiteStage.ProgramOpen:
                default:
                    return(View("IndexProgramOpen"));
                }
            }
        }