/// <summary>
        /// 审批通告
        /// </summary>
        /// <param name="model">审批model</param>
        /// <param name="userId">用户Id</param>
        /// <returns>审批通告成功或者失败</returns>
        public bool Audit(AuditAnnouncementModel model, int userId, string userName)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var annocumentEntity = dbContext.Announcements.Where(it => it.Id == model.announcementID && it.Status == (int)AnnouncementStatus.Apply).FirstOrDefault();
                if (annocumentEntity == null)
                {
                    throw new Exception("此通告不存在");
                }

                annocumentEntity.AuditReason = model.AuditReason;
                annocumentEntity.CreatedTime = DateTime.Now;

                if (model.auditStatus)
                {
                    annocumentEntity.Status = (int)AnnouncementStatus.AllowPublish;
                    var notificationModel = new NotificationModel()
                    {
                        //MessageType = NotificationType.PushMessage,
                        MessageType    = NotificationType.Email,
                        CreatedUserId  = annocumentEntity.CreateUserId,
                        Scope          = NotificationScope.Public,
                        Title          = annocumentEntity.Title,
                        MessageContent = annocumentEntity.Content,
                        BusinessType   = BusinessType.AdministrationEventAnnounce
                    };
                    this._notificationService.Add(notificationModel, Global.IsProduction);
                }
                else
                {
                    annocumentEntity.Status = (int)AnnouncementStatus.RejectPublish;
                    var applyUserEntity = dbContext.Users.Where(it => it.Id == annocumentEntity.CreateUserId).FirstOrDefault();
                    if (applyUserEntity == null)
                    {
                        throw new Exception("通告申请用户不存在");
                    }

                    var notificationModel = new NotificationModel()
                    {
                        Target = applyUserEntity.Email,
                        //MessageType = NotificationType.PushMessage,
                        MessageType    = NotificationType.Email,
                        CreatedUserId  = annocumentEntity.CreateUserId,
                        Scope          = NotificationScope.User,
                        Title          = "通告审批消息",
                        MessageContent = "您的申请通告'" + annocumentEntity.Title + "',已经被" + userName + "拒绝,拒绝理由:" + model.AuditReason,
                        BusinessType   = BusinessType.AnnocumentAuditMessage,
                        TargetUserIds  = new List <int> {
                            applyUserEntity.Id
                        }
                    };
                    this._notificationService.Add(notificationModel, Global.IsProduction);
                }
                dbContext.SaveChanges();
                return(true);
            }
        }
示例#2
0
        public ApiResponse <bool> Audit(AuditAnnouncementModel model)
        {
            if (model == null || model.announcementID < 1)
            {
                throw new Exception("无效的参数");
            }
            if (model.auditStatus == false && String.IsNullOrEmpty(model.AuditReason))
            {
                throw new Exception("请输入拒绝理由");
            }
            RoleModel role = RoleService.SearchRole(this.Member.Role);

            if (!role.RoleName.Contains("行政"))
            {
                throw new Exception("没有审批通告权限");
            }
            ApiResponse <bool> response = new ApiResponse <bool>()
            {
                Result = this.AnnouncementService.Audit(model, this.Member.Id, this.Member.EnglishName)
            };

            return(response);
        }