diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamController.cs index 4f08c9e1..570916ac 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamController.cs @@ -100,4 +100,17 @@ public class Ghre_ExamController : BaseController + /// 获取考试状态接口 + /// + /// + /// + [HttpPost("GetStatus/{id}")] + public async Task GetStatus(long id) + { + return await _service.GetStatus(id); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.IServices/BASE/IBaseServices.cs b/Tiobon.Core.IServices/BASE/IBaseServices.cs index 0156eb62..6e0fa4fd 100644 --- a/Tiobon.Core.IServices/BASE/IBaseServices.cs +++ b/Tiobon.Core.IServices/BASE/IBaseServices.cs @@ -83,6 +83,8 @@ namespace Tiobon.Core.IServices.BASE Task AnyAsync(object objId); + Task AnyAsync(Expression> whereExpression); + /// /// 根据ID查询实体数据是否存在 /// diff --git a/Tiobon.Core.IServices/Ghre/IGhre_ExamServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_ExamServices.cs index c732dc05..e35422a0 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_ExamServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_ExamServices.cs @@ -20,5 +20,7 @@ namespace Tiobon.Core.IServices Task> Insert1(long id, DefaultGhre_ExamPageData pageData); Task UpdateStatus(long[] ids, string status); + + Task GetStatus(long id); } } \ No newline at end of file diff --git a/Tiobon.Core.Model/ServiceResult.cs b/Tiobon.Core.Model/ServiceResult.cs index 40d83e14..8c996b7d 100644 --- a/Tiobon.Core.Model/ServiceResult.cs +++ b/Tiobon.Core.Model/ServiceResult.cs @@ -129,7 +129,7 @@ public class ServiceResult { Message = msg, Status = status, - Data = null + Data = null, }; } } diff --git a/Tiobon.Core.Repository/BASE/BaseRepository.cs b/Tiobon.Core.Repository/BASE/BaseRepository.cs index e36757ce..35d3fdcc 100644 --- a/Tiobon.Core.Repository/BASE/BaseRepository.cs +++ b/Tiobon.Core.Repository/BASE/BaseRepository.cs @@ -94,6 +94,11 @@ namespace Tiobon.Core.Repository.Base return _db.Queryable().In(objId).Any(); } + public async Task AnyAsync(Expression> whereExpression) + { + return await _db.Queryable().WhereIF(whereExpression != null, whereExpression).AnyAsync(); + } + /// /// 根据ID查询一条数据 /// diff --git a/Tiobon.Core.Repository/BASE/IBaseRepository.cs b/Tiobon.Core.Repository/BASE/IBaseRepository.cs index 6850697e..d3e814bf 100644 --- a/Tiobon.Core.Repository/BASE/IBaseRepository.cs +++ b/Tiobon.Core.Repository/BASE/IBaseRepository.cs @@ -27,6 +27,8 @@ namespace Tiobon.Core.IRepository.Base /// bool Any(object objId); + Task AnyAsync(Expression> whereExpression); + /// /// 根据Id查询实体 /// diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index da5a21e4..724e24a7 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -57,6 +57,12 @@ public class BaseServices : IBaseServ return data; } + public async Task AnyAsync(Expression> whereExpression) + { + var data = await BaseDal.AnyAsync(whereExpression); + return data; + } + public virtual async Task QueryById(object objId) { var data = new TEntity(); diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs index c9d425a6..283ef95a 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs @@ -27,11 +27,13 @@ public class Ghre_ExamServices : BaseServices dal) { this._dal = dal; @@ -41,6 +43,7 @@ public class Ghre_ExamServices : BaseServices GetModuleInfo(ModuleParam param) { @@ -607,6 +610,10 @@ public class Ghre_ExamServices : BaseServices x.ExamId == id)) + return ServiceResult.OprateFailed("已有学员参与考试,不可取消发布!"); + if (status == "Released" || status == "Disabled" || status == "Draft") { entity.Status = status; @@ -623,4 +630,13 @@ public class Ghre_ExamServices : BaseServices GetStatus(long id) + { + if (await _ghre_ExamRecordServices.AnyAsync(x => x.ExamId == id)) + return ServiceResult.OprateFailed("已有学员参与考试,不可取消发布!"); + + return ServiceResult.OprateSuccess("可以取消发布!"); + + } } \ No newline at end of file