public override async Task AfterSaveAsync(IDbConnection connection, SaveAction action, IUser user) { if (action == SaveAction.Insert) { var workItem = await connection.FindAsync <WorkItem>(WorkItemId); workItem.ActivityId = ToActivityId; workItem.LastHandOffId = Id; if (ToUserId.HasValue) { var activity = await connection.FindAsync <Activity>(ToActivityId); Responsibility.SetWorkItemUserActions[activity.ResponsibilityId].Invoke(workItem, ToUserId.Value); } await connection.SaveAsync(workItem, user); var toActivity = await connection.FindAsync <Activity>(ToActivityId); var fromActivity = await connection.FindAsync <Activity>(FromActivityId); string displayUser = await OrganizationUser.GetUserDisplayNameAsync(connection, workItem.OrganizationId, FromUserId, user); string text = $"{displayUser} handed off work item {workItem.Number} from {fromActivity.Name} to {toActivity.Name}"; if (ToUserId.HasValue) { var assignedToUser = await connection.FindAsync <UserProfile>(ToUserId.Value); string assignedToName = await OrganizationUser.GetUserDisplayNameAsync(connection, workItem.OrganizationId, ToUserId.Value, assignedToUser); text += $", assigned to {assignedToName}"; } int eventLogId = await EventLog.WriteAsync(connection, new EventLog(WorkItemId, user) { TeamId = workItem.TeamId, EventId = (IsForward) ? SystemEvent.HandOffForward : SystemEvent.HandOffBackward, IconClass = GetIconClass(IsForward), IconColor = GetColor(IsForward), HtmlBody = text, TextBody = text, SourceId = Id, SourceTable = nameof(HandOff) }); await Notification.CreateFromActivitySubscriptions(connection, eventLogId); } }
private async Task ReplaceMentionNameAsync(IDbConnection connection, Comment comment, string mentionName, OrganizationUser orgUser) { string result = comment.HtmlBody; result = result.Replace(mentionName, $"<a href=\"mailto:{orgUser.Email}\">{orgUser.DisplayName ?? orgUser.UserName}</a>"); comment.HtmlBody = result; comment.TextBody = new Converter().Convert(comment.HtmlBody); await connection.SaveAsync(comment); }
private async Task AddMentionEventInnerAsync(IDbConnection connection, Comment comment, string senderName, OrganizationUser mentionedUser) { string mentionName = mentionedUser.DisplayName ?? mentionedUser.Email; int eventLogId = await CreateEventLogFromMentionAsync(connection, comment, senderName, mentionName); await Notification.CreateFromMentionAsync(connection, eventLogId, comment, senderName, mentionedUser); }
private static async Task CreateFromCommentAsync( IDbConnection connection, int eventLogId, Comment comment, DeliveryMethod method, string senderName, OrganizationUser mentionUser, Func <OrganizationUser, string> addressGetter, Func <Comment, string> contentGetter) { string sendTo = addressGetter.Invoke(mentionUser); if (string.IsNullOrEmpty(sendTo)) { return; } await connection.SaveAsync(new Notification() { EventLogId = eventLogId, SendTo = sendTo, DateCreated = comment.DateCreated, Method = method, Content = $"{senderName} writes: {contentGetter.Invoke(comment)}", SourceId = comment.Id, SourceTable = nameof(Comment) }); }
internal static async Task CreateFromMentionAsync(IDbConnection connection, int eventLogId, Comment comment, string senderName, OrganizationUser mentionUser) { if (mentionUser.SendEmail) { await CreateFromCommentAsync(connection, eventLogId, comment, DeliveryMethod.Email, senderName, mentionUser, (ou) => ou.Email, (c) => c.HtmlBody); } if (mentionUser.SendText) { await CreateFromCommentAsync(connection, eventLogId, comment, DeliveryMethod.Text, senderName, mentionUser, (ou) => ou.PhoneNumber, (c) => c.TextBody); } // todo: app notification }
public override bool Equals(object obj) { OrganizationUser test = obj as OrganizationUser; return((test != null) ? test.OrganizationId == OrganizationId && test.UserId == UserId : false); }