public IHttpActionResult GoInRoom([FromBody] GoInRoom_Ac_Request RequestMod) { try { if (RequestMod.RoomId < 1 || RequestMod.LocationId < 1) { throw new ArgumentException("非法访问"); } using (MysqlDbContext db = new MysqlDbContext()) { var room = db.Rooms.Where(t => t.RoomId == RequestMod.RoomId & t.IsQuit == false).FirstOrDefault(); var roomroles = db.RoomRoles.Where(t => t.Rid == RequestMod.RoomId && t.LocationId == RequestMod.LocationId).FirstOrDefault(); if (room == null || roomroles == null) { throw new ArgumentException("房间不存在"); } GoInRoom_Ac_Response ResponseMod = new GoInRoom_Ac_Response() { RoomID = room.RoomId, Pnum = room.PersonsNum, Victory = room.VictoryCondition, Role = roomroles.RoleEnum.ToString(), Location = roomroles.LocationId }; return(Ok(new AjaxResult() { state = ResultType.success.ToString(), data = ResponseMod })); } } catch (MySqlException e) { LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + ":房间进入失败(数据库问题):" + e.Message); return(Ok(new AjaxResult() { state = ResultType.error.ToString(), message = "房间进入失败,请联系管理员" })); } catch (ArgumentException e) { return(Ok(new AjaxResult() { state = ResultType.error.ToString(), message = e.Message })); } catch (Exception e) { return(Ok(new AjaxResult() { state = ResultType.error.ToString(), message = "非法操作:" + e.Message })); } }
public IHttpActionResult GameOver([FromBody] EndAction_Ac_Request RequestMod) { try { if (RequestMod.Roomid < 1) { throw new ArgumentException("非法访问"); } using (MysqlDbContext db = new MysqlDbContext()) { var room = db.Rooms.Where(t => t.RoomId == RequestMod.Roomid & t.IsQuit == false).FirstOrDefault(); var roomroles = db.RoomRoles.Where(t => t.Rid == RequestMod.Roomid); if (room == null || roomroles == null) { throw new ArgumentException("房间不存在"); } db.RoomRoles.RemoveRange(roomroles); int i = db.SaveChanges(); GoInRoom_Ac_Response ResponseMod = new GoInRoom_Ac_Response() { RoomID = room.RoomId, Pnum = room.PersonsNum }; return(Ok(new AjaxResult() { state = ResultType.success.ToString(), data = ResponseMod })); } } catch (MySqlException e) { LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + ":记录删除失败:" + e.Message); return(Ok(new AjaxResult() { state = ResultType.error.ToString(), message = "记录删除失败,请重试" })); } catch (ArgumentException e) { return(Ok(new AjaxResult() { state = ResultType.error.ToString(), message = e.Message })); } catch (Exception e) { return(Ok(new AjaxResult() { state = ResultType.error.ToString(), message = "非法操作:" + e.Message })); } }