Exemplo n.º 1
0
        public async Task<IViewComponentResult> InvokeAsync(int count, Guid? gameId, Guid? userId, Guid? oldestId, DateTime? oldestDate, bool? articlesOnly)
        {
            UserPreferencesViewModel preferences = _userPreferencesAppService.GetByUserId(CurrentUserId);

            ActivityFeedRequestViewModel vm = new ActivityFeedRequestViewModel
            {
                CurrentUserId = CurrentUserId,
                Count = count,
                GameId = gameId,
                UserId = userId,
                Languages = preferences.Languages,
                OldestId = oldestId,
                OldestDate = oldestDate,
                ArticlesOnly = articlesOnly
            };

            List<UserContentViewModel> model = _userContentAppService.GetActivityFeed(vm).ToList();

            ApplicationUser user = await UserManager.FindByIdAsync(CurrentUserId.ToString());
            bool userIsAdmin = user != null && await UserManager.IsInRoleAsync(user, Roles.Administrator.ToString());

            foreach (UserContentViewModel item in model)
            {
                if (item.UserContentType == UserContentType.TeamCreation)
                {
                    FormatTeamCreationPost(item);
                }
                if (item.UserContentType == UserContentType.JobPosition)
                {
                    FormatJobPositionPostForTheFeed(item);
                }
                else
                {
                    item.Content = ContentHelper.FormatContentToShow(item.Content);
                }

                foreach (CommentViewModel comment in item.Comments)
                {
                    comment.Text = ContentHelper.FormatHashTagsToShow(comment.Text);
                }

                item.Permissions.CanEdit = !item.HasPoll && (item.UserId == CurrentUserId || userIsAdmin);

                item.Permissions.CanDelete = item.UserId == CurrentUserId || userIsAdmin;
            }

            if (model.Any())
            {
                UserContentViewModel oldest = model.OrderByDescending(x => x.CreateDate).Last();

                ViewData["OldestPostGuid"] = oldest.Id;
                ViewData["OldestPostDate"] = oldest.CreateDate.ToString("o");
            }

            ViewData["IsMorePosts"] = oldestId.HasValue;

            ViewData["UserId"] = userId;

            return await Task.Run(() => View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Languages()
        {
            UserPreferencesViewModel vm = userPreferencesAppService.GetByUserId(CurrentUserId);

            vm.StatusMessage = StatusMessage;

            return(await Task.Run(() => View(vm)));
        }
Exemplo n.º 3
0
        private void SetLanguage()
        {
            PostFromHomeViewModel postModel = new PostFromHomeViewModel();

            RequestCulture requestLanguage = Request.HttpContext.Features.Get <IRequestCultureFeature>().RequestCulture;

            string lang = GetCookieValue(SessionValues.PostLanguage);

            if (lang != null)
            {
                SupportedLanguage langEnum = (SupportedLanguage)Enum.Parse(typeof(SupportedLanguage), lang);
                postModel.DefaultLanguage = langEnum;
            }
            else
            {
                if (!User.Identity.IsAuthenticated)
                {
                    SetAspNetCultureCookie(requestLanguage);
                    postModel.DefaultLanguage = base.SetLanguageFromCulture(requestLanguage.UICulture.Name);
                }
                else
                {
                    UserPreferencesViewModel userPrefs = userPreferencesAppService.GetByUserId(CurrentUserId);

                    if (userPrefs != null && userPrefs.Id != Guid.Empty)
                    {
                        SetAspNetCultureCookie(userPrefs.UiLanguage);

                        SetCookieValue(SessionValues.PostLanguage, postModel.DefaultLanguage.ToString(), 7);

                        postModel.DefaultLanguage = userPrefs.UiLanguage;
                    }
                    else
                    {
                        SetAspNetCultureCookie(requestLanguage);
                        postModel.DefaultLanguage = base.SetLanguageFromCulture(requestLanguage.UICulture.Name);
                    }
                }
            }

            ViewBag.PostFromHome = postModel;
        }
Exemplo n.º 4
0
        public async Task <IViewComponentResult> InvokeAsync(int count, Guid?gameId, Guid?userId, Guid?oldestId, DateTime?oldestDate, bool?articlesOnly)
        {
            UserPreferencesViewModel preferences = _userPreferencesAppService.GetByUserId(CurrentUserId);

            ActivityFeedRequestViewModel vm = new ActivityFeedRequestViewModel
            {
                CurrentUserId = CurrentUserId,
                Count         = count,
                GameId        = gameId,
                UserId        = userId,
                Languages     = preferences.Languages,
                OldestId      = oldestId,
                OldestDate    = oldestDate,
                ArticlesOnly  = articlesOnly
            };

            List <UserContentViewModel> model = _userContentAppService.GetActivityFeed(vm).ToList();

            bool userIsAdmin = User.Identity.IsAuthenticated && User.IsInRole(Roles.Administrator.ToString());

            foreach (UserContentViewModel item in model)
            {
                if (item.UserContentType == UserContentType.TeamCreation)
                {
                    FormatTeamCreationPost(item);
                }
                if (item.UserContentType == UserContentType.JobPosition)
                {
                    FormatJobPositionPostForTheFeed(item);
                }
                else
                {
                    item.Content = ContentFormatter.FormatContentToShow(item.Content);
                    if (item.FeaturedMediaType == MediaType.Youtube)
                    {
                        item.FeaturedImageResponsive = ContentFormatter.GetYoutubeVideoId(item.FeaturedImage);
                        item.FeaturedImageLquip      = ContentHelper.SetFeaturedImage(Guid.Empty, Constants.DefaultFeaturedImageLquip, ImageRenderType.LowQuality);
                    }
                }

                foreach (CommentViewModel comment in item.Comments)
                {
                    comment.Text = ContentFormatter.FormatHashTagsToShow(comment.Text);
                }

                item.Permissions.CanEdit = !item.HasPoll && (item.UserId == CurrentUserId || userIsAdmin);

                item.Permissions.CanDelete = item.UserId == CurrentUserId || userIsAdmin;
            }

            if (model.Any())
            {
                UserContentViewModel oldest = model.OrderByDescending(x => x.CreateDate).Last();

                ViewData["OldestPostGuid"] = oldest.Id;
                ViewData["OldestPostDate"] = oldest.CreateDate.ToString("yyyy-MM-ddTHH:mm:ss.fffffff");
            }

            ViewData["IsMorePosts"] = oldestId.HasValue;

            ViewData["UserId"] = userId;

            return(await Task.Run(() => View(model)));
        }