public async Task <ActionResult <int> > DeleteLeave([FromBody] ManageLeaveRequest request) { var user_id = Int32.Parse(User.Identity.Name); if (await UserAccessor.CheckRole(user_id) == Constants.Role.Provider) { return(BadRequest(new { message = "Providers cannot manage leave application." })); } if (request.status == ApplyStatus.Applying) { var ans = await LeaveAccessor.Delete(request.leave_id); return(Ok(1)); } return(Ok(-1)); }
//[AllowAnonymous] public async Task <ActionResult <LeaveResponse> > ProManageLeave(ManageLeaveRequest request) { var pro_id = Int32.Parse(User.Identity.Name); if (await UserAccessor.CheckRole(pro_id) == Constants.Role.Student) { return(BadRequest(new { message = "Students cannot manage leave application." })); } LeaveEntity le = await LeaveAccessor.Read(request.leave_id); if (le == null) { return(BadRequest(new { message = "Leave id not found." })); } if (le.status != Constants.ApplyStatus.Applying) { return(BadRequest(new { message = "The application have been managed." })); } var success_change = await LeaveAccessor.SetLeaveStatus(request.leave_id, request.status); if (success_change > 0) { le.status = request.status; //减少查询 LeaveResponse lr = _mapper.Map <LeaveResponse>(le); // 未检查id是否存在 lr.student_name = await UserAccessor.GetUserName(le.student_id); //lr.teacher_name = await UserAccessor.GetUserName(le.teacher_id); lr.work_name = await WorkAccessor.GetWorkName(le.work_id); if (request.status == Constants.ApplyStatus.Accepted) { // 录用,更新takes await TakesAccessor.UpdateAbsent(le.student_id, le.work_id, le.leave_duration); } return(lr); } return(BadRequest(new { message = "Update failed" })); }