public IActionResult SearchStudentGroup(DeleteStudentGroupRequest request) { //宿舍id校验 if (!request.StudentGroupId.HasValue) { //宿舍编号获取为空 return(Failure(ResultCode.PARAM_IS_INVALLD)); } //宿舍id条件查询 var command = _demoContext.DB.Queryable <Student_Group>().Where(it => it.StudentGroupId == request.StudentGroupId && it.IsDelete == 0).ToList(); //判断是否查询到 if (command.Count == 0) { //宿舍不存在 return(Failure(ResultCode.RESULT_DATA_NOT)); } //var json = new //{ // code = 0, // msg = "", // count = command.Count, // data = command //}; return(Success(command, command.Count)); }
public IActionResult DelStudentGroup(DeleteStudentGroupRequest request) { // 参数校验 if (!request.StudentGroupId.HasValue) { return(Ok("宿舍编号必填,不可为空")); } // 判断是否存在 Student_Group studentGroup = _demoContext.DB.Queryable <Student_Group>().InSingle(request.StudentGroupId.Value); if (studentGroup == null) { return(Ok("该宿舍不存在")); } // 判断是否已删除 if (studentGroup.IsDelete == 1) { return(Ok("该宿舍已删除")); } // 若宿舍中有人员则不可删除 var number = _demoContext.DB.Queryable <Student_Group_Detail>().Where(it => it.StudentGroupId == request.StudentGroupId && it.IsDelete == 0).ToList(); if (number.Count == 0) { // 0=未删除;1已删除 studentGroup.IsDelete = 1; // 记录更新时间 // 记录操作日志 // 数据库影响行数 int command = _demoContext.DB.Updateable <Student_Group>(studentGroup).ExecuteCommand(); return(Ok(command > 0 ? "删除成功" : "删除失败")); } return(Ok("不可以删除")); }