新增已发布的课程的课件不允许删除

master
xiaochanghai 10 months ago
parent 435fa2f359
commit 17a3e69079
  1. 109
      Tiobon.Core.Services/Ghre/Ghre_CourseWareServices.cs

@ -97,44 +97,44 @@ public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_Course
// string sql = "SELECT Id,QuestionId from Ghre_QuestionAnswer where AnswerContent='单选题'";
// var questionAnswers = await Db.Ado.SqlQueryAsync<Ghre_QuestionAnswer>(sql);
// for (int i = 0; i < questionAnswers.Count; i++)
// {
// await Db.Deleteable(new Ghre_QuestionAnswer() { Id = questionAnswers[i].Id }).ExecuteCommandAsync();
// sql = $@"UPDATE A
//SET A.TaxisNo = B.NUM
//FROM Ghre_QuestionAnswer A
// JOIN
// (SELECT ID, NUM * 100 NUM
// FROM (SELECT *, ROW_NUMBER () OVER (ORDER BY TaxisNo) NUM
// FROM (SELECT *
// FROM (SELECT *
// FROM Ghre_QuestionAnswer
// WHERE QuestionId = '{questionAnswers[i].QuestionId}') A) B) C) B
// ON A.ID = b.ID;
//UPDATE Ghre_QuestionAnswer
//SET QuestionNo =
// CASE TaxisNo
// WHEN 100 THEN 'A'
// WHEN 200 THEN 'B'
// WHEN 300 THEN 'C'
// WHEN 400 THEN 'D'
// WHEN 500 THEN 'E'
// WHEN 600 THEN 'F'
// WHEN 700 THEN 'G'
// WHEN 800 THEN 'H'
// WHEN 900 THEN 'I'
// WHEN 1000 THEN 'J'
// WHEN 1100 THEN 'K'
// WHEN 1200 THEN 'L'
// END
//WHERE QuestionId = '{questionAnswers[i].QuestionId}'";
// await Db.Ado.SqlQueryAsync<Ghre_QuestionAnswer>(sql);
// }
// string sql = "SELECT Id,QuestionId from Ghre_QuestionAnswer where AnswerContent='单选题'";
// var questionAnswers = await Db.Ado.SqlQueryAsync<Ghre_QuestionAnswer>(sql);
// for (int i = 0; i < questionAnswers.Count; i++)
// {
// await Db.Deleteable(new Ghre_QuestionAnswer() { Id = questionAnswers[i].Id }).ExecuteCommandAsync();
// sql = $@"UPDATE A
//SET A.TaxisNo = B.NUM
//FROM Ghre_QuestionAnswer A
// JOIN
// (SELECT ID, NUM * 100 NUM
// FROM (SELECT *, ROW_NUMBER () OVER (ORDER BY TaxisNo) NUM
// FROM (SELECT *
// FROM (SELECT *
// FROM Ghre_QuestionAnswer
// WHERE QuestionId = '{questionAnswers[i].QuestionId}') A) B) C) B
// ON A.ID = b.ID;
//UPDATE Ghre_QuestionAnswer
//SET QuestionNo =
// CASE TaxisNo
// WHEN 100 THEN 'A'
// WHEN 200 THEN 'B'
// WHEN 300 THEN 'C'
// WHEN 400 THEN 'D'
// WHEN 500 THEN 'E'
// WHEN 600 THEN 'F'
// WHEN 700 THEN 'G'
// WHEN 800 THEN 'H'
// WHEN 900 THEN 'I'
// WHEN 1000 THEN 'J'
// WHEN 1100 THEN 'K'
// WHEN 1200 THEN 'L'
// END
//WHERE QuestionId = '{questionAnswers[i].QuestionId}'";
// await Db.Ado.SqlQueryAsync<Ghre_QuestionAnswer>(sql);
// }
return result;
@ -237,4 +237,37 @@ public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_Course
}
}
}
#region 删除
// <summary>
/// 删除指定ID的数据
/// </summary>
/// <param name="id">主键ID</param>
/// <returns></returns>
public override async Task<bool> DeleteById1(object id)
{
if (await Db.Queryable<Ghre_Course>().AnyAsync(x => x.CourseWareId == (long)id))
throw new Exception($"该课件已与课程关联,暂不可删除!");
return await base.DeleteById1(id);
}
/// <summary>
/// 删除指定ID集合的数据(批量删除)
/// </summary>
/// <param name="ids">主键ID集合</param>
/// <returns></returns>
public override async Task<bool> DeleteByIds1(long[] ids)
{
foreach (var id in ids)
{
if (await Db.Queryable<Ghre_Course>().AnyAsync(x => x.CourseWareId == (long)id))
throw new Exception($"课件已与课程关联,暂不可删除!");
}
return await base.DeleteByIds1(ids);
}
#endregion
}
Loading…
Cancel
Save