示例#1
0
        public async Task <_ <IssueOperationLogEntity> > AddComment(IssueOperationLogEntity model)
        {
            var issue = await this._issueRepo.GetFirstAsync(x => x.UID == model.IssueUID);

            issue = issue ?? throw new ArgumentNullException("issue is null");
            if (issue.OrgUID != model.OrgUID)
            {
                throw new Exception("org is wrong");
            }

            var res = new _ <IssueOperationLogEntity>();

            if (issue.IsClosed > 0)
            {
                res.SetErrorMsg("issue已经被关闭,无法评论");
                return(res);
            }

            res = await this._issueOperaRepo.AddEntity_(model, "op");

            {
                //更新评论数
                var status = new string[] { "open", "close" };
                issue.CommentCount = await this._issueOperaRepo.GetCountAsync(x =>
                                                                              x.OrgUID == issue.OrgUID && x.IssueUID == issue.UID && !status.Contains(x.Operation));

                await this._issueRepo.UpdateAsync(issue);
            }

            return(res);
        }
示例#2
0
        public virtual async Task <_ <string> > OpenOrClose(string issue_uid, string user_uid, bool close)
        {
            return(await this._issueRepo.PrepareSessionAsync(async db =>
            {
                var query = db.Set <IssueEntity>().AsQueryable();
                var res = new _ <string>();
                var now = DateTime.Now;

                var issue = await query.FirstOrDefaultAsync(x => x.UID == issue_uid);
                Com.AssertNotNull(issue, "issue is null");

                if (issue.AssignedUserUID != user_uid && issue.UserUID != user_uid)
                {
                    res.SetErrorMsg("无权操作");
                    return res;
                }
                var status = close.ToBoolInt();
                if (issue.IsClosed == status)
                {
                    res.SetErrorMsg("状态无需改变");
                    return res;
                }
                issue.IsClosed = status;
                if (close)
                {
                    var seconds = (int)(now - (issue.Start ?? issue.CreateTime)).TotalSeconds;
                    if (seconds >= 0)
                    {
                        //处理问题花了多长时间
                        issue.SecondsToTakeToClose = seconds;
                    }
                }
                else
                {
                    issue.SecondsToTakeToClose = 0;
                }

                var log = new IssueOperationLogEntity()
                {
                    UserUID = user_uid,
                    OrgUID = issue.OrgUID,
                    IssueUID = issue.UID,
                    IsClosed = issue.IsClosed,
                    Operation = close ? "close" : "open",
                    Content = string.Empty
                }.InitSelf("op");

                db.Set <IssueOperationLogEntity>().Add(log);

                await db.SaveChangesAsync();

                res.SetSuccessData(string.Empty);
                return res;
            }));
        }
示例#3
0
        public virtual async Task <_ <string> > OpenOrClose(string org_uid, string uid, bool close, string user_uid, string comment)
        {
            var res = new _ <string>();

            var model = await this._issueRepo.GetFirstAsync(x => x.UID == uid);

            Com.AssertNotNull(model, "issue不存在");
            if (model.OrgUID != org_uid)
            {
                res.SetErrorMsg("无权操作");
                return(res);
            }

            var status = close.ToBoolInt();

            if (model.IsClosed == status)
            {
                res.SetErrorMsg("状态无需改变");
                return(res);
            }
            model.IsClosed = status;

            if (close)
            {
                model.SecondsToTakeToClose = (int)(DateTime.Now - model.CreateTime).TotalSeconds;
            }
            else
            {
                model.SecondsToTakeToClose = 0;
            }

            await this._issueRepo.UpdateAsync(model);

            //add log
            var operation_log = new IssueOperationLogEntity()
            {
                OrgUID   = model.OrgUID,
                IssueUID = model.UID,
                IsClosed = model.IsClosed,
                UserUID  = user_uid,
                Content  = comment
            }.InitSelf("iol");

            if (!operation_log.IsValid(out var msg))
            {
                res.SetErrorMsg(msg);
                return(res);
            }
            await this._issueOperaRepo.AddAsync(operation_log);

            res.SetSuccessData(string.Empty);
            return(res);
        }
示例#4
0
 public async Task <_ <IssueOperationLogEntity> > AddComment(IssueOperationLogEntity model) =>
 await this._issueOperaRepo.AddEntity_(model, "op");