コード例 #1
0
        public HttpResponseMessage Post(AddReviewCommentDTO dto)
        {
            try
            {
                var userInfo = UserHelper.GetCurrentUser();
                var result   = repository.AddOrUpdateReviewComment(dto, ra => ra.ExpertId == userInfo.UserId);

                ////当一封申请书的指派专家全部评审完毕后
                //if (_noticeService.CompleteReview(
                //        _noticeService.GetApplicationIdByAssignmentId(
                //            dto.ReviewAssignmentId)))
                //{
                //    //申请书指派的所有专家评审结束
                //    //通知打点:院管理员
                //    _noticeService.AddNoticeList(
                //        _noticeService.GetDeptMIdListByAssignmentId(dto.ReviewAssignmentId), 19);
                //}

                return(ResponseWrapper.SuccessResponse(result));
            }
            catch (Exception e)
            {
                return(ResponseWrapper.ExceptionResponse(e));
            }
        }
コード例 #2
0
        /// <summary>
        /// 添加评审结果
        /// </summary>
        /// <param name="ReviewCommentDTO">评审结果信息</param>
        /// <returns>
        /// 添加成功,返回ResponseStatus.success
        /// 失败,返回ResponseStatus.unknown_error和错误信息
        /// </returns>
        public GetReviewCommentDTO AddOrUpdateReviewComment(AddReviewCommentDTO dto, Func <ReviewAssignment, bool> privilege)
        {
            using (var ctx = new AspodesDB())
            {
                //权限验证
                var assignment = ctx.ReviewAssignments.FirstOrDefault(ra => ra.ReviewAssignmentId == dto.ReviewAssignmentId);
                if (null == assignment)
                {
                    throw new NotFoundException();
                }
                if (assignment.Overdue.Value)
                {
                    throw new OtherException("不允许执行操作");
                }
                if (!privilege(assignment))
                {
                    throw new UnauthorizationException();
                }


                //补全信息
                var newComment = Mapper.Map <ReviewComment>(dto);
                newComment.ExpertId        = assignment.ExpertId;
                newComment.ApplicationId   = assignment.ApplicationId;
                newComment.Status          = ReviwerCommentStatus.SAVE;
                newComment.Year            = SystemConfig.ApplicationStartYear;
                newComment.ReviewCommentId = null;
                //添加或者更改
                var oldComment  = ctx.ReviwerComments.FirstOrDefault(rc => rc.ReviewAssignmentId == dto.ReviewAssignmentId);
                var transaction = ctx.Database.BeginTransaction();
                try
                {
                    if (null == oldComment)
                    {
                        newComment.Status = ReviwerCommentStatus.SAVE;
                        ctx.ReviwerComments.Add(newComment);
                        assignment.Status = ReviewAssignmentStatus.ALREADY_REVIEW;
                        ctx.SaveChanges();

                        bool reviewFinish = ctx.ReviewAssignments
                                            .Where(ra => ra.ApplicationId == assignment.ApplicationId && !ra.Overdue.Value && ra.Status != ReviewAssignmentStatus.CHANGE && ra.Status != ReviewAssignmentStatus.REFUSE)
                                            .All(ra => ra.Status == Model.ReviewAssignmentStatus.ALREADY_REVIEW);
                        if (reviewFinish)
                        {
                            assignment.Application.Status = Model.ApplicationStatus.FINISH_REVIEW;
                        }
                    }
                    else
                    {
                        //检查是否允许更改

                        //不允许更改的字段
                        newComment.ReviewCommentId = oldComment.ReviewCommentId;
                        newComment.Status          = oldComment.Status;
                        newComment.ExpertId        = oldComment.ExpertId;
                        newComment.ApplicationId   = oldComment.ApplicationId;
                        //更新
                        ctx.Entry(oldComment).CurrentValues.SetValues(newComment);
                    }

                    ctx.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }

                return(Mapper.Map <GetReviewCommentDTO>(newComment));
            }
        }