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 string GetLikesCountString(int supportingUserCount) { return(GlobalizedSentences.GetSupportingUsersString(supportingUserCount)); }
/// <summary> /// Sends the query email. /// </summary> private void SendMyNewsEmails() { var stopwatchEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableStopWatch"] ?? "false"); var threshold = Convert.ToInt32(ConfigurationManager.AppSettings["Threshold"] ?? "10"); var watch = Stopwatch.StartNew(); var globalWatch = Stopwatch.StartNew(); if (!stopwatchEnabled) { watch.Stop(); globalWatch.Stop(); } var userIds = userService.GetNewsLetterUserIds(); if (stopwatchEnabled) { watch.Stop(); if (watch.ElapsedMilliseconds > threshold) { Log.Information("GetNewsLetterUserIds elapsed time: " + watch.ElapsedMilliseconds); } } Log.Information(string.Format("Preparing to send email to {0} users...", userIds.Count)); int userCount = 0; foreach (var userId in userIds) { if (stopwatchEnabled) { watch.Restart(); } var emails = userService.GetUserEmails(userId); if (stopwatchEnabled) { watch.Stop(); if (watch.ElapsedMilliseconds > threshold) { Log.Information(string.Format("GetUserEmails elapsed time: {0}, userId={1}", watch.ElapsedMilliseconds, userId)); } } if (emails.Count == 0) { continue; } if (stopwatchEnabled) { watch.Restart(); } var count = newsFeedService.GetUnreadNewsCount(userId); if (stopwatchEnabled) { watch.Stop(); if (watch.ElapsedMilliseconds > threshold) { Log.Information(string.Format("GetUnreadNewsCount elapsed time: {0}, userId={1}", watch.ElapsedMilliseconds, userId)); } } if (count == 0) { continue; } var user = userService.GetUser(userId); if (stopwatchEnabled) { watch.Restart(); } var list = newsFeedService.GetNewsFeedPage(userId, user.LastNewsLetterSendDate).List.List.Where(l => !l.IsRead).ToList(); if (stopwatchEnabled) { watch.Stop(); if (watch.ElapsedMilliseconds > threshold) { Log.Information(string.Format("GetNewsFeedPage elapsed time: {0}, userId={1}", watch.ElapsedMilliseconds, userId)); } watch.Restart(); } if (!list.Any()) { continue; } if (count < list.Count()) { count = list.Count(); } foreach (var email in emails) { notification.To = email; notification.News = string.Empty; notification.NewsCount = count; notification.NewsCountText = GlobalizedSentences.GetNewsCountText(count); notification.NewsLetterFreq = Globalization.Resources.Services.NewsLetterFreq.ResourceManager.GetString(user.Settings.NewsLetterFrequency.ToString()).ToLower(); foreach (var item in list) { notification.News += Web.Helpers.SpecificHtmlHelpers.GetNewsFeedEntry(item) + "<br/>" + (item.Problem != null ? item.Subject : "") + "<br/>" + item.Text.NewLineToHtml(); notification.News += "<br/><br/>"; } using (var session = usersContextFactory.CreateContext()) { var not = session.Notifications.Single(n => n.Id == (int)NotificationTypes.NewsLetter); notification.MessageTemplate = not.Message; notification.Subject = not.Subject; if (notification.Execute()) { userService.UpdateNewsLetterDate(userId); userCount++; } } } if (stopwatchEnabled) { watch.Stop(); if (watch.ElapsedMilliseconds > threshold) { Log.Information(string.Format("Send mail elapsed time: {0}, userId={1}", watch.ElapsedMilliseconds, userId)); } } } if (stopwatchEnabled) { globalWatch.Stop(); Log.Information("Total elapsed time: " + globalWatch.ElapsedMilliseconds); } Log.Information(string.Format("Sent {0} emails...", userCount)); }