public async Task <IActionResult> Save(UserContentViewModel vm) { try { bool isNew = vm.Id == Guid.Empty; ProfileViewModel profile = await ProfileAppService.GetByUserId(CurrentUserId, ProfileType.Personal); SetAuthorDetails(vm); OperationResultVo <Guid> saveResult = userContentAppService.Save(CurrentUserId, vm); if (!saveResult.Success) { return(Json(saveResult)); } else { NotifyFollowers(profile, vm.GameId, vm.Id); string url = Url.Action("Index", "Home", new { area = string.Empty, id = vm.Id, pointsEarned = saveResult.PointsEarned }); if (isNew && EnvName.Equals(ConstantHelper.ProductionEnvironmentName)) { await NotificationSender.SendTeamNotificationAsync("New complex post!"); } return(Json(new OperationResultRedirectVo(url))); } } catch (Exception ex) { return(Json(new OperationResultVo(ex.Message))); } }
public async Task <IActionResult> SimplePost(string text, string images, IEnumerable <PollOptionViewModel> pollOptions, SupportedLanguage?language, Guid?gameId) { UserContentViewModel vm = new UserContentViewModel { Language = language ?? SupportedLanguage.English, Content = text, Poll = new PollViewModel { PollOptions = pollOptions.ToList() }, GameId = gameId }; ProfileViewModel profile = await ProfileAppService.GetByUserId(CurrentUserId, ProfileType.Personal); SetAuthorDetails(vm); SetContentImages(vm, images); OperationResultVo <Guid> result = userContentAppService.Save(CurrentUserId, vm); NotifyFollowers(profile, vm.GameId, vm.Id); if (EnvName.Equals(ConstantHelper.ProductionEnvironmentName)) { await NotificationSender.SendTeamNotificationAsync("New simple post!"); } return(Json(result)); }
private void FormatTeamCreationPost(UserContentViewModel item) { string[] teamData = item.Content.Split('|'); string id = teamData[0]; string name = teamData[1]; string motto = teamData[2]; string memberCount = teamData[3]; bool recruiting = false; if (teamData.Length > 4) { recruiting = bool.Parse(teamData[4] ?? "False"); } string postTemplate = ContentHelper.FormatUrlContentToShow(item.UserContentType); string translatedText = SharedLocalizer["A new team has been created with {0} members.", memberCount].ToString(); if (recruiting) { translatedText = SharedLocalizer["A team is recruiting!", memberCount].ToString(); } item.Content = String.Format(postTemplate, translatedText, name, motto); item.Url = Url.Action("Details", "Team", new { teamId = id }); item.Language = SupportedLanguage.English; }
private void SetContentImages(UserContentViewModel vm, string images) { if (images != null) { string[] imgSplit = images.Split('|'); vm.Images = new List <ImageListItemVo>(); for (int i = 0; i < imgSplit.Length; i++) { if (!string.IsNullOrWhiteSpace(imgSplit[i])) { if (string.IsNullOrWhiteSpace(vm.FeaturedImage)) { vm.FeaturedImage = imgSplit[i]; } else { vm.Images.Add(new ImageListItemVo { Language = SupportedLanguage.English, Image = imgSplit[i] }); } } } } }
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)); }
private void GenerateFeedPost(JobPositionViewModel vm) { if (vm != null && vm.Status == JobPositionStatus.OpenForApplication) { string json = JsonConvert.SerializeObject(vm); UserContentViewModel newContent = new UserContentViewModel { UserId = CurrentUserId, UserContentType = UserContentType.JobPosition, Content = json, Language = vm.Language }; OperationResultListVo <Application.ViewModels.Search.UserContentSearchViewModel> searchContentResult = userContentAppService.Search(CurrentUserId, vm.Id.ToString()); if (searchContentResult.Success && searchContentResult.Value.Any()) { Application.ViewModels.Search.UserContentSearchViewModel existing = searchContentResult.Value.FirstOrDefault(); if (existing != null) { newContent.Id = existing.ContentId; } } userContentAppService.Save(CurrentUserId, newContent); } }
public async Task <IActionResult> Details(Guid id, Guid notificationclicked) { notificationAppService.MarkAsRead(notificationclicked); OperationResultVo <UserContentViewModel> serviceResult = userContentAppService.GetById(CurrentUserId, id); if (!serviceResult.Success) { TempData["Message"] = SharedLocalizer["Content not found!"].Value; return(RedirectToAction("Index", "Home")); } UserContentViewModel vm = serviceResult.Value; vm.Content = ContentHelper.FormatContentToShow(vm.Content); SetAuthorDetails(vm); if (vm.GameId.HasValue && vm.GameId.Value != Guid.Empty) { OperationResultVo <Application.ViewModels.Game.GameViewModel> gameServiceResult = gameAppService.GetById(CurrentUserId, vm.GameId.Value); Application.ViewModels.Game.GameViewModel game = gameServiceResult.Value; vm.GameTitle = game.Title; vm.GameThumbnail = UrlFormatter.Image(game.UserId, ImageType.GameThumbnail, game.ThumbnailUrl); } vm.Content = vm.Content.Replace("image-style-align-right", "image-style-align-right float-right p-10"); vm.Content = vm.Content.Replace("image-style-align-left", "image-style-align-left float-left p-10"); vm.Content = vm.Content.Replace("<img src=", @"<img class=""img-fluid"" src="); if (string.IsNullOrEmpty(vm.Title)) { vm.Title = SharedLocalizer["Content posted on"] + " " + vm.CreateDate.ToString(); } if (string.IsNullOrWhiteSpace(vm.Introduction)) { vm.Introduction = SharedLocalizer["Content posted on"] + " " + vm.CreateDate.ToShortDateString(); } ApplicationUser user = await UserManager.FindByIdAsync(CurrentUserId.ToString()); bool userIsAdmin = user != null && await UserManager.IsInRoleAsync(user, Roles.Administrator.ToString()); vm.Permissions.CanEdit = vm.UserId == CurrentUserId || userIsAdmin; vm.Permissions.CanDelete = vm.UserId == CurrentUserId || userIsAdmin; ViewData["IsDetails"] = true; return(View(vm)); }
public UserContent() { this.InitializeComponent(); UCVM = new UserContentViewModel(); UCVM.LoadUser(); UCVM.LoadVarer(); Products.IsEnabled = false; Køb.IsEnabled = false; Cancel.IsEnabled = false; }
private void GenerateTeamPost(TeamViewModel vm, bool newTeam, bool recruiting) { if ((newTeam && vm.Members.Count > 1) || recruiting) { UserContentViewModel newContent = new UserContentViewModel { AuthorName = GetSessionValue(SessionValues.FullName), UserId = CurrentUserId, UserContentType = UserContentType.TeamCreation, Content = String.Format("{0}|{1}|{2}|{3}|{4}", vm.Id, vm.Name, vm.Motto, vm.Members.Count, recruiting) }; userContentAppService.Save(CurrentUserId, newContent); } }
private static void SetFeaturedImage(UserContentViewModel item) { string selectedFeaturedImage = item.FeaturedImage; if (string.IsNullOrWhiteSpace(item.FeaturedImage) && item.Images.Any(x => x.Language == item.Language)) { selectedFeaturedImage = item.Images.FirstOrDefault(x => x.Language == item.Language)?.Image; } else if (string.IsNullOrWhiteSpace(item.FeaturedImage) && item.Images.Any()) { selectedFeaturedImage = item.Images.FirstOrDefault()?.Image; } item.FeaturedImage = ContentHelper.SetFeaturedImage(item.UserId, selectedFeaturedImage, ImageRenderType.Full); item.FeaturedImageResponsive = ContentHelper.SetFeaturedImage(item.UserId, selectedFeaturedImage, ImageRenderType.Responsive); item.FeaturedImageLquip = ContentHelper.SetFeaturedImage(item.UserId, selectedFeaturedImage, ImageRenderType.LowQuality); }
public IActionResult Edit(Guid id) { OperationResultVo <UserContentViewModel> serviceResult = userContentAppService.GetById(CurrentUserId, id); UserContentViewModel vm = serviceResult.Value; IEnumerable <SelectListItemVo> games = gameAppService.GetByUser(vm.UserId); List <SelectListItem> gamesDropDown = games.ToSelectList(); ViewBag.UserGames = gamesDropDown; if (!vm.HasFeaturedImage) { vm.FeaturedImage = Constants.DefaultFeaturedImage; } return(View("CreateEdit", vm)); }
public OperationResultVo <UserContentViewModel> GetById(Guid currentUserId, Guid id) { try { UserContent model = userContentDomainService.GetById(id); UserProfile authorProfile = GetCachedProfileByUserId(model.UserId); UserContentViewModel vm = mapper.Map <UserContentViewModel>(model); if (authorProfile == null) { vm.AuthorName = Constants.UnknownSoul; } else { vm.AuthorName = authorProfile.Name; } vm.HasFeaturedImage = !string.IsNullOrWhiteSpace(vm.FeaturedImage) && !vm.FeaturedImage.Contains(Constants.DefaultFeaturedImage); vm.FeaturedMediaType = GetMediaType(vm.FeaturedImage); if (vm.FeaturedMediaType != MediaType.Youtube) { vm.FeaturedImage = ContentHelper.SetFeaturedImage(vm.UserId, vm.FeaturedImage, ImageRenderType.Full); vm.FeaturedImageLquip = ContentHelper.SetFeaturedImage(vm.UserId, vm.FeaturedImage, ImageRenderType.LowQuality); } vm.LikeCount = vm.Likes.Count; vm.CommentCount = vm.Comments.Count; vm.Poll = SetPoll(currentUserId, vm.Id); LoadAuthenticatedData(currentUserId, vm); return(new OperationResultVo <UserContentViewModel>(vm)); } catch (Exception ex) { return(new OperationResultVo <UserContentViewModel>(ex.Message)); } }
public IActionResult Add(Guid?gameId) { UserContentViewModel vm = new UserContentViewModel { UserId = CurrentUserId, FeaturedImage = Constants.DefaultFeaturedImage }; IEnumerable <SelectListItemVo> games = gameAppService.GetByUser(vm.UserId); List <SelectListItem> gamesDropDown = games.ToSelectList(); ViewBag.UserGames = gamesDropDown; if (gameId.HasValue) { vm.GameId = gameId; } return(View("CreateEdit", vm)); }
private void CreatePoll(UserContentViewModel contentVm) { Poll newPoll = new Poll { UserId = contentVm.UserId, UserContentId = contentVm.Id }; foreach (PollOptionViewModel o in contentVm.Poll.PollOptions) { PollOption newOption = new PollOption { UserId = contentVm.UserId, Text = o.Text }; newPoll.Options.Add(newOption); } pollDomainService.Add(newPoll); }
private void SetContentImages(UserContentViewModel vm, string images) { if (images != null) { string[] imgSplit = images.Split('|'); vm.Images = new List <string>(); for (int i = 0; i < imgSplit.Length; i++) { if (!string.IsNullOrWhiteSpace(imgSplit[i])) { if (string.IsNullOrWhiteSpace(vm.FeaturedImage)) { vm.FeaturedImage = imgSplit[i]; } else { vm.Images.Add(imgSplit[i]); } } } } }
private void FormatJobPositionPostForTheFeed(UserContentViewModel item) { JobPositionViewModel obj = JsonConvert.DeserializeObject<JobPositionViewModel>(item.Content); SupportedLanguage language = SupportedLanguage.English; if (obj.Remote) { obj.Location = SharedLocalizer["remote"]; } if (obj.Language != 0) { language = obj.Language; } string postTemplate = ContentHelper.FormatUrlContentToShow(item.UserContentType); string translatedText = SharedLocalizer["A new job position for {0}({1}) is open for applications.", SharedLocalizer[obj.WorkType.ToDisplayName()], obj.Location].ToString(); item.Content = String.Format(postTemplate, translatedText, SharedLocalizer[obj.WorkType.ToDisplayName()], obj.Location); item.Url = Url.Action("Details", "JobPosition", new { area = "Work", id = obj.Id.ToString() }); item.Language = language; }
public OperationResultVo <Guid> Save(Guid currentUserId, UserContentViewModel viewModel) { try { int pointsEarned = 0; UserContent model; bool isSpam = CheckSpam(viewModel.Id, viewModel.Content); bool isNew = viewModel.Id == Guid.Empty; if (isSpam) { return(new OperationResultVo <Guid>("Calm down! You cannot post the same content twice in a row.")); } string youtubePattern = @"(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+"; viewModel.Content = Regex.Replace(viewModel.Content, youtubePattern, delegate(Match match) { string v = match.ToString(); if (match.Index == 0 && String.IsNullOrWhiteSpace(viewModel.FeaturedImage)) { viewModel.FeaturedImage = v; } return(v); }); UserContent existing = userContentDomainService.GetById(viewModel.Id); if (existing != null) { model = mapper.Map(viewModel, existing); } else { model = mapper.Map <UserContent>(viewModel); } if (model.PublishDate == DateTime.MinValue) { model.PublishDate = model.CreateDate; } if (isNew) { userContentDomainService.Add(model); PlatformAction action = viewModel.IsComplex ? PlatformAction.ComplexPost : PlatformAction.SimplePost; pointsEarned += gamificationDomainService.ProcessAction(viewModel.UserId, action); unitOfWork.Commit().Wait(); viewModel.Id = model.Id; if (viewModel.Poll != null && viewModel.Poll.PollOptions != null && viewModel.Poll.PollOptions.Any()) { CreatePoll(viewModel); pointsEarned += gamificationDomainService.ProcessAction(viewModel.UserId, PlatformAction.PollPost); } } else { userContentDomainService.Update(model); } unitOfWork.Commit().Wait(); return(new OperationResultVo <Guid>(model.Id, pointsEarned)); } catch (Exception ex) { return(new OperationResultVo <Guid>(ex.Message)); } }
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))); }