/// <summary> /// 給院管理員添加申请书 /// </summary> /// <param name="ReviewCommentDTO">申请书信息</param> /// <returns> /// 添加成功,返回GetApplicationAssignmentDTO /// 失败,返回ResponseStatus.unknown_error和错误信息 /// </returns> public GetApplicationAssignmentDTO AddApplicationAssignment(AddApplicationAssignmentDTO dto) { ApplicationAssignment reco = Mapper.Map <ApplicationAssignment>(dto); using (var ctx = new AspodesDB()) { var rec = ctx.ApplicationAssignments.Add(reco); ctx.SaveChanges(); return(Mapper.Map <GetApplicationAssignmentDTO>(rec)); } }
/// <summary> /// 修改院管理员申请书项目分类 /// </summary> /// <param name="personId">院管理员ID</param> /// <param name="AssignmentList">项目分类列表</param> /// <returns></returns> public List <GetApplicationAssignmentDTO> UpdateUserApplicationAssignment(int personId, List <ApplicationAssignmentDTO> AssignmentList) { using (var db = new AspodesDB()) { //根据PersonId获取User User u1 = db.Users.FirstOrDefault(c => c.PersonId == personId); if (null == u1) { throw new NotFoundException("用户不存在!"); } //判断用户是否是院管理员 if (db.Authorizes.Any(c => c.UserId == u1.UserId && c.RoleId == 3)) { //获取选中的项目类型列表 AssignmentList = AssignmentList.Where(c => c.Checked == true).ToList(); //删除之前的项目类型分配列表 IQueryable <ApplicationAssignment> oldAssignmentList = db.ApplicationAssignments.Where(c => c.UserId == u1.UserId && c.RoleId == 3); db.ApplicationAssignments.RemoveRange(oldAssignmentList); List <GetApplicationAssignmentDTO> App = new List <GetApplicationAssignmentDTO>(); ApplicationAssignment appASS; foreach (var temp in AssignmentList) { appASS = new ApplicationAssignment(); appASS.RoleId = 3; appASS.UserId = u1.UserId; appASS.ProjectTypeId = temp.ProjectTypeId; App.Add(Mapper.Map <GetApplicationAssignmentDTO>(db.ApplicationAssignments.Add(appASS))); } db.SaveChanges(); return(App); } else { throw new UnauthorizationException("该用户非有效的院管理员!"); } } }