/// <summary> /// 按courseId删除Seminar. /// @author zhouzhongjun /// </summary> /// 先根据CourseId获得所有的seminar的信息,然后根据seminar信息删除相关topic的记录,然后再根据SeminarId删除SeminarGroup表记录,最后再将seminar的信息删除 /// <param name="courseId">课程Id</param> /// <returns>true删除成功 false删除失败</returns> /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarService.ListSeminarByCourseIdAsync(System.Int64)" /> /// <seealso cref="M:Xmu.Crms.Shared.Service.ITopicService.DeleteTopicBySeminarIdAsync(System.Int64)" /> /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarGroupService.DeleteSeminarGroupBySeminarIdAsync(System.Int64)" /> /// <exception cref="ArgumentException">格式错误时抛出</exception> /// <exception cref="CourseNotFoundException">该课程不存在时抛出</exception> public async Task DeleteSeminarByCourseIdAsync(long courseId) { if (courseId < 0) { throw new ArgumentException(); } var seminars = await _db.Seminar.Where(_seminar => _seminar.Course.Id == courseId).ToListAsync(); if (seminars == null) { throw new SeminarNotFoundException(); } for (var i = 0; i <= seminars.Count; i++) { _db.Seminar.Remove(seminars[i]); } await _db.SaveChangesAsync(); }