private static string GetNewsFeedGroupUsersLink(HtmlHelper html, NewsFeedItemModel item) { var type = item.NewsFeedTypeId == (int)NewsFeedTypes.NewsFeed ? NewsFeedListViews.MyNews : NewsFeedListViews.AllNews; return(new UrlHelper(html.ViewContext.RequestContext).Action(MVC.NewsFeed.GetNewsFeedGroupUsers(type, item.ActionTypeId, item.ObjectId, item.Date, item.RelatedObjectId, item.OrganizationId, item.RawText.LimitLength(TextLengthInQueryString, null), item.IsPrivate))); }
public async Task<NewsFeedQueryResult> NewsFeedPostSelect(int userId, NewsFeedItemModel.NewsFeedTypeId? newsFeedTypeIdFilter, string searchFilterText, ImageFinder courseImageFinder, ImageFinder userImageLocator) { const int takeAmount = 20; var newsFeedItems = new List<NewsFeedItemModel>(); int newCourseCount; int newRoundCount; //grab the user's friends var usersFriendIds = await FriendsDataProvider.GetUsersFriendList(DbContext, userId).ToArrayAsync(); //let's go grab the round query var roundQuery = RoundGet().AsNoTracking() .Where(x => x.UserId == userId || usersFriendIds.Contains(x.UserId)) .OrderByDescending(x => x.RoundDate) .Take(takeAmount); //go build the course query var courseQuery = CourseGet().AsNoTracking() .OrderByDescending(x => x.CreatedDate) .Take(takeAmount); //add the filters now if (!string.IsNullOrEmpty(searchFilterText)) { //round query filter roundQuery = roundQuery.Where(x => x.User.FirstName.Contains(searchFilterText) || x.User.LastName.Contains(searchFilterText) || x.Course.Name.Contains(searchFilterText)); //course query filter courseQuery = courseQuery.Where(x => x.Name.Contains(searchFilterText) || x.Description.Contains(searchFilterText) || x.City.Contains(searchFilterText)); } //grab the count of records we have before we go filter by news feed filter type, we always want the count of all items newRoundCount = await roundQuery.CountAsync(); newCourseCount = await courseQuery.CountAsync(); //do they want to filter one or the other? //only rounds? if (ShouldRunQuery(NewsFeedItemModel.NewsFeedTypeId.NewRound, newsFeedTypeIdFilter)) { newsFeedItems.AddRange(await RoundSelect(roundQuery, userId, courseImageFinder, userImageLocator)); } if (ShouldRunQuery(NewsFeedItemModel.NewsFeedTypeId.NewCourse, newsFeedTypeIdFilter)) { newsFeedItems.AddRange(await CourseSelect(courseQuery, userId, courseImageFinder)); } //now return the model return new NewsFeedQueryResult(newsFeedItems.OrderByDescending(x => x.PostDate).ToArray(), newRoundCount, newCourseCount, usersFriendIds.Length); }
public async Task<bool> AddOrRemoveLike(int areaId, NewsFeedItemModel.NewsFeedTypeId newsFeedTypeId, int userId) { //so you like the item already? var alreadyLikeItem = await GetLikesByIdAndUserId(areaId, newsFeedTypeId, userId); //did we find this record? if so we delete it if (alreadyLikeItem != null) { //we want to remove this record return await Delete(alreadyLikeItem); } //else we don't have a record, we are in add mode return await Add(new NewsFeedLike { AreaId = areaId, NewsFeedTypeId = (int)newsFeedTypeId, UserIdThatLikedItem = userId, CreatedDate = DateTime.Now }); }
public async Task<bool> Delete(int areaId, NewsFeedItemModel.NewsFeedTypeId newsFeedTypeId) { return await Delete(x => x.AreaId == areaId && x.NewsFeedTypeId == (int)newsFeedTypeId); }
public async Task<NewsFeedLike> GetLikesByIdAndUserId(int areaId, NewsFeedItemModel.NewsFeedTypeId newsFeedTypeId, int userId) { return await GetLikes().Where(x => x.UserIdThatLikedItem == userId && x.AreaId == areaId && x.NewsFeedTypeId == (int)newsFeedTypeId).FirstOrDefaultAsync(); }
private static bool ShouldRunQuery(NewsFeedItemModel.NewsFeedTypeId itemToTest, NewsFeedItemModel.NewsFeedTypeId? filterValue) { return !filterValue.HasValue || filterValue.Value == itemToTest; }
public static MvcHtmlString GetNewsFeedEntry(this HtmlHelper html, NewsFeedItemModel item) { var user = string.Empty; if (item.NewsFeedTypeId == (int)NewsFeedTypes.UserActivity) { user = item.UserFullName.Substring(0, item.UserFullName.IndexOf(" ")); } else if (item.NewsFeedTypeId == (int)NewsFeedTypes.OrganizationActivity) { user = html.ActionLinkWithReturnUrl(item.UserFullName, MVC.Account.Details(item.UserObjectId, item.UserFullName.ToSeoUrl(), null), new Dictionary <string, object>() { { "target", "_blank" } }).ToString(); } else { var isOrganization = !string.IsNullOrEmpty(item.OrganizationId) && !string.IsNullOrEmpty(item.OrganizationName) && !item.IsPrivate && ((ActionTypes)item.ActionTypeId).In(ActionTypes.IdeaCreated, ActionTypes.IdeaVersionAdded, ActionTypes.IssueCreated, ActionTypes.ProblemCreated); user = GetGroupedUsers(html, isOrganization ? item.OrganizationName : item.UserFullName, isOrganization ? item.OrganizationId : item.UserObjectId, item.Users, item.ActionTypeId != (int)ActionTypes.OrganizationMemberAdded ? item.UserCount : null, isOrganization, item); } string str = string.Format(item.ActionDescription, user, "{1}", "{2}", "{3}", "{4}", "{5}"); if (item.IsRead == false) { str = string.Format("<b>{0}</b>", str); } if (!item.Link.IsNullOrEmpty()) { str = string.Format(str, string.Empty, string.Format("<a href='{0}' target='_blank'>{1}</a>", item.Link, item.Subject.GetSafeHtml()), "{2}", "{3}", "{4}", "{5}"); } else { str = string.Format(str, string.Empty, item.Subject, "{2}", "{3}", "{4}", "{5}"); } if (!item.RelatedUserObjectId.IsNullOrEmpty()) { if (item.ActionTypeId == (int)ActionTypes.OrganizationMemberAdded) { str = string.Format(str, string.Empty, string.Empty, GetGroupedUsers(html, item.RelatedUserFullName, item.RelatedUserObjectId, item.RelatedUsers, item.UserCount, false, item), "{3}", "{4}", "{5}"); } else if (item.RelatedUserObjectId.Trim() == "-1") { str = string.Format(str, string.Empty, string.Empty, " " + Resource.ForTaking + " ", "{3}", "{4}", "{5}"); } else if (item.RelatedUserObjectId == item.UserObjectId && ((ActionTypes)item.ActionTypeId).In(ActionTypes.ToDoAdded, ActionTypes.ToDoEdited, ActionTypes.ToDoFinished, ActionTypes.ToDoCommentAdded)) { str = string.Format(str, string.Empty, string.Empty, " " + Resource.ForHimself + " ", "{3}", "{4}", "{5}"); } else { if (!item.RelatedUserFullName.IsNullOrEmpty()) { str = string.Format(str, string.Empty, string.Empty, html.ActionLinkWithReturnUrl(item.RelatedUserFullName, MVC.Account.Details(item.RelatedUserObjectId, item.RelatedUserFullName. ToSeoUrl(), null), new Dictionary <string, object>() { { "target", "_blank" } }), "{3}", "{4}", "{5}"); } else { str = string.Format(str, string.Empty, string.Empty, string.Empty, "{3}", "{4}", "{5}"); } } } if (((ActionTypes)item.ActionTypeId).In(ActionTypes.ToDoAdded, ActionTypes.ToDoEdited, ActionTypes.OrganizationToDoAdded, ActionTypes.OrganizationToDoEdited)) { str = string.Format(str, string.Empty, string.Empty, " " + Resource.ForTheTeam + " ", "{3}", "{4}", "{5}"); } if (item.CategoryNames.Count > 0) { str = string.Format(str, string.Empty, string.Empty, string.Empty, item.CategoryNames.Concatenate(", ")); } if (!item.RelatedLink.IsNullOrEmpty() && !item.RelatedSubject.IsNullOrEmpty()) { str = string.Format(str, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("<a href='{0}'>{1}</a>", item.RelatedLink, item.RelatedSubject), string.Empty); } if (!item.OrganizationId.IsNullOrEmpty() && !item.OrganizationName.IsNullOrEmpty()) { str = string.Format(str, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, html.ActionLink(item.OrganizationName, MVC.Organization.Details(item.OrganizationId, item.OrganizationName.ToSeoUrl(), null, null, null, null))); } return(MvcHtmlString.Create(str)); }
private static string GetGroupedUsers(HtmlHelper html, string name, string objectId, List <UserLinkModel> explicitUsers, int?userCount, bool isOrganization, NewsFeedItemModel item) { string user; if (!userCount.HasValue || userCount == 0) { if (isOrganization) { return(html.ActionLinkWithReturnUrl(name, MVC.Organization.Details(objectId, name.ToSeoUrl(), null, null, null, null)).ToString()); } else { return(html.ActionLinkWithReturnUrl(name, MVC.Account.Details(objectId, name.ToSeoUrl(), null)).ToString()); } } else { if (explicitUsers != null && explicitUsers.Count > 0) { user = explicitUsers.Concatenate( itm => html.ActionLinkWithReturnUrl(itm.FullName, MVC.Account.Details(itm.ObjectId, itm.FullName.ToSeoUrl(), null)).ToString(), ", "); if (userCount > 0) { user += " " + string.Format(Resource.AndSomeMore, GlobalizedSentences.GetUsersString(userCount.Value), GetNewsFeedGroupUsersLink(html, item)); } } else { user = string.Format(Resource.NumberUsers, GlobalizedSentences.GetUsersString(userCount.Value), GetNewsFeedGroupUsersLink(html, item)); } } return(user); }
public static MvcHtmlString GetNewsFeedEntry(NewsFeedItemModel item) { var isOrganization = !string.IsNullOrEmpty(item.OrganizationId) && !string.IsNullOrEmpty(item.OrganizationName) && !item.IsPrivate && ((ActionTypes)item.ActionTypeId).In(ActionTypes.IdeaCreated, ActionTypes.IdeaVersionAdded, ActionTypes.IssueCreated, ActionTypes.ProblemCreated); var user = isOrganization ? item.OrganizationName : item.UserFullName; string str = string.Format(item.ActionDescription, user, "{1}", "{2}", "{3}", "{4}", "{5}"); if (item.IsRead == false) { str = string.Format("<b>{0}</b>", str); } if (!item.Link.IsNullOrEmpty()) { str = string.Format(str, string.Empty, string.Format("<a href='https://www.lietuva2.lt{0}'>{1}</a>", item.Link, item.Subject), "{2}", "{3}", "{4}", "{5}"); } else { str = string.Format(str, string.Empty, item.Subject, "{2}", "{3}", "{4}", "{5}"); } if (!item.RelatedUserObjectId.IsNullOrEmpty()) { if (item.RelatedUserObjectId == item.UserObjectId && ((ActionTypes)item.ActionTypeId).In(ActionTypes.ToDoAdded, ActionTypes.ToDoEdited, ActionTypes.ToDoFinished, ActionTypes.ToDoCommentAdded)) { str = string.Format(str, string.Empty, string.Empty, " " + Resource.ForHimself + " ", "{3}", "{4}", "{5}"); } else { str = string.Format(str, string.Empty, string.Empty, item.RelatedUserFullName, "{3}", "{4}", "{5}"); } } if (((ActionTypes)item.ActionTypeId).In(ActionTypes.ToDoAdded, ActionTypes.ToDoEdited, ActionTypes.OrganizationToDoAdded, ActionTypes.OrganizationToDoEdited)) { str = string.Format(str, string.Empty, string.Empty, " " + Resource.ForTheTeam + " ", "{3}", "{4}", "{5}"); } if (item.CategoryNames.Count > 0) { str = string.Format(str, string.Empty, string.Empty, string.Empty, item.CategoryNames.Concatenate(", ")); } if (!item.RelatedLink.IsNullOrEmpty() && !item.RelatedSubject.IsNullOrEmpty()) { str = string.Format(str, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("<a href='{0}'>{1}</a>", item.RelatedLink, item.RelatedSubject), string.Empty); } if (!item.OrganizationId.IsNullOrEmpty() && !item.OrganizationName.IsNullOrEmpty()) { str = string.Format(str, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, item.OrganizationName); } return(MvcHtmlString.Create(str)); }