/// <summary> /// 将学生加入讨论课小组. /// </summary> /// <param name="userId">学生的id</param> /// <param name="groupId">要加入讨论课小组的id</param> /// <returns>long 该条记录的id</returns> /// <exception cref="T:System.ArgumentException">id格式错误</exception> /// <exception cref="T:Xmu.Crms.Shared.Exceptions.GroupNotFoundException">未找到小组</exception> /// <exception cref="T:Xmu.Crms.Shared.Exceptions.UserNotFoundException">不存在该学生</exception> /// <exception cref="T:System.InvalidOperationException">待添加学生已经在小组里了</exception> public long InsertSeminarGroupMemberById(long userId, long groupId) { UserInfo _user; SeminarGroup _sg; //id <= 0 if (userId <= 0 || groupId <= 0) { throw new ArgumentException("id格式错误"); } //未找到小组 if ((_sg = _db.SeminarGroup.Find(groupId)) == null) { throw new GroupNotFoundException(); } //不存在该学生 if ((_user = _db.UserInfo.Find(userId)) == null) { throw new UserNotFoundException(); } //待添加学生已经在小组里 if (_db.SeminarGroupMember .Include(sgt => sgt.SeminarGroup) .Include(sgt => sgt.Student) .Where(_sgm => _sgm.SeminarGroup.Id == groupId && _sgm.Student.Id == userId) .ToList().Count != 0) { throw new System.InvalidOperationException("待添加学生已经在小组里了"); } //新建SeminarGroupMember对象 SeminarGroupMember sgm = new SeminarGroupMember(); sgm.SeminarGroup = _sg; sgm.Student = _user; _db.SeminarGroupMember.Add(sgm); _db.SaveChanges(); return(sgm.Id); }
/// <summary> /// 创建小组成员信息. /// 将小组成员加入某一小组 /// </summary> /// <param name="groupId">小组的id</param> /// <param name="seminarGroupMember">小组成员信息</param> /// <returns>long 返回该小组成员表的id</returns> public long InsertSeminarGroupMemberByGroupId(long groupId, SeminarGroupMember seminarGroupMember) { if (groupId <= 0) { throw new ArgumentException("groupId格式错误"); } SeminarGroup sg = _db.SeminarGroup.Find(groupId); if (sg == null) { throw new GroupNotFoundException(); } seminarGroupMember.SeminarGroup = sg; _db.SeminarGroupMember.Add(seminarGroupMember); _db.SaveChanges(); return(seminarGroupMember.Id); }