示例#1
0
        public override async Task AfterSaveAsync(IDbConnection connection, SaveAction action, IUser user)
        {
            await base.AfterSaveAsync(connection, action, user);

            if (action == SaveAction.Insert)
            {
                if (ObjectType == ObjectType.WorkItem)
                {
                    var workItem = await connection.FindAsync <WorkItem>(ObjectId);

                    if (IsImpediment.HasValue)
                    {
                        workItem.HasImpediment = IsImpediment.Value;
                        await connection.UpdateAsync(workItem, user, r => r.HasImpediment);
                    }

                    await EventLog.WriteAsync(connection, new EventLog(ObjectId, user)
                    {
                        TeamId    = workItem.TeamId,
                        EventId   = (IsImpediment ?? false) ? SystemEvent.ImpedimentAdded : SystemEvent.CommentAdded,
                        IconClass = IconClass,
                        IconColor = (IsImpediment ?? false) ? "darkred" : "auto",
                        HtmlBody  = HtmlBody,
                        TextBody  = TextBody
                    });
                }

                await PendingWorkLog.FromCommentAsync(connection, this, user as UserProfile);
                await ParseMentionsAsync(connection, this, user as UserProfile);
            }
        }
示例#2
0
        public static async Task FromCommentAsync(IDbConnection connection, Comment comment, IUser user)
        {
            if (comment.ObjectType != ObjectType.WorkItem && comment.ObjectType != ObjectType.Project)
            {
                return;
            }
            var currentUser = user as UserProfile;

            if (currentUser == null)
            {
                throw new Exception("Couldn't determine the current user profile when creating work log.");
            }

            if (ParseHoursFromText(comment.TextBody, out decimal hours))
            {
                var link = await FindProjectAndWorkItemIdAsync(connection, comment);

                var workLog = new PendingWorkLog()
                {
                    OrganizationId = link.OrganizationId,
                    TeamId         = link.TeamId,
                    ApplicationId  = link.ApplicationId,
                    ProjectId      = link.ProjectId,
                    WorkItemId     = link.WorkItemId,
                    UserId         = currentUser.UserId,
                    Date           = comment.DateCreated,
                    Hours          = hours,
                    TextBody       = comment.TextBody,
                    HtmlBody       = comment.HtmlBody,
                    SourceType     = HoursSourceType.Comment,
                    SourceId       = comment.Id
                };

                await connection.SaveAsync(workLog, user ?? new SystemUser()
                {
                    UserName = "******", LocalTime = DateTime.UtcNow
                });
            }
        }