public async Task <int> Getresign([FromBody] FindworkRequest request) { //判断request里是否满足前置条件 if (!ModelState.IsValid) { return(-1); } var user_id = Int32.Parse(User.Identity.Name); if (await UserAccessor.CheckRole(user_id) != Role.Student) { return(-2); } TakesEntity entity = new TakesEntity(); entity.work_id = request.work_id; entity.student_id = user_id; MessageEntity temp_entity = new MessageEntity(); var work_name = await WorkAccessor.GetWorkName(request.work_id); var student_name = await UserAccessor.GetUserName(user_id); temp_entity.message_type = 0; temp_entity.content = student_name + "同学辞去" + work_name + "工作。"; temp_entity.sender_id = user_id; temp_entity.receiver_id = await WorkAccessor.GetTeacher(request.work_id); var num = await TakesAccessor.GetRegion(entity); await MessageAccessor.Create(temp_entity, 1); return(num); }
public async Task <ActionResult <MessageResponse> > CreateMessage([FromBody] MessageRequest request) { //判断request里是否满足前置条件 if (!ModelState.IsValid) { return(BadRequest()); } //取得存在cookie的当前账户id var temp_id = Int32.Parse(User.Identity.Name); if (await UserAccessor.CheckRole(temp_id) == Role.Student) { return(BadRequest(new { message = "Student cannot send message" })); } var temp_entity = _mapper.Map <MessageEntity>(request); temp_entity.sender_id = temp_id; var temp = await MessageAccessor.Create(temp_entity, 0); temp_entity.message_id = temp; temp_entity.sender_name = await UserAccessor.GetUserName(temp_entity.sender_id); temp_entity.receiver_name = await UserAccessor.GetUserName(temp_entity.receiver_id); return(Ok(_mapper.Map <MessageResponse>(temp_entity))); }