private static bool IsValid(GameCloseRequest request, out string message) { if (string.IsNullOrEmpty(request.GameId)) { message = "Missing GameId."; return(false); } message = ""; return(true); }
public IActionResult Index([FromBody] GameCloseRequest request, string appId) { if (!IsValid(request, out string message)) { var errorResponse = new ErrorResponse { Message = message }; _logger.LogError($"{Request.GetUri()} - {JsonConvert.SerializeObject(errorResponse)}"); return(BadRequest(errorResponse)); } if (request.State == null) { if (request.ActorCount > 0) { var errorResponse = new ErrorResponse { Message = "Missing State." }; _logger.LogError($"{Request.GetUri()} - {JsonConvert.SerializeObject(errorResponse)}"); return(BadRequest(errorResponse)); } _dataAccess.StateDelete(appId, request.GameId); var okResponse = new OkResponse(); _logger.LogInformation($"{Request.GetUri()} - {JsonConvert.SerializeObject(okResponse)}"); return(Ok(okResponse)); } foreach (var actor in request.State.ActorList) { //var listProperties = new ListProperties() { ActorNr = (int)actor.ActorNr, Properties = request.State.CustomProperties }; //DataSources.DataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (string)JsonConvert.SerializeObject(listProperties)); _dataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (int)actor.ActorNr); } //deprecated if (request.State2 != null) { foreach (var actor in request.State2.ActorList) { _dataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (int)actor.ActorNr); } } var state = (string)JsonConvert.SerializeObject(request.State); _dataAccess.StateSet(appId, request.GameId, state); var response = new OkResponse(); _logger.LogInformation($"{Request.GetUri()} - {JsonConvert.SerializeObject(response)}"); return(Ok(response)); }
private static bool IsValid(GameCloseRequest request, out string message) { if (string.IsNullOrEmpty(request.GameId)) { message = "Missing GameId."; return false; } message = ""; return true; }
public dynamic Post(GameCloseRequest request, string appId) { if (log.IsDebugEnabled) log.DebugFormat("{0} - {1}", Request.RequestUri, JsonConvert.SerializeObject(request)); string message; if (!IsValid(request, out message)) { var errorResponse = new ErrorResponse { Message = message }; if (log.IsDebugEnabled) log.Debug(JsonConvert.SerializeObject(errorResponse)); return errorResponse; } if (request.State == null) { if (request.ActorCount > 0) { var errorResponse = new ErrorResponse { Message = "Missing State." }; if (log.IsDebugEnabled) log.Debug(JsonConvert.SerializeObject(errorResponse)); return errorResponse; } WebApiApplication.DataAccess.StateDelete(appId, request.GameId); var okResponse = new OkResponse(); if (log.IsDebugEnabled) log.Debug(JsonConvert.SerializeObject(okResponse)); return okResponse; } foreach (var actor in request.State.ActorList) { //var listProperties = new ListProperties() { ActorNr = (int)actor.ActorNr, Properties = request.State.CustomProperties }; //WebApiApplication.DataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (string)JsonConvert.SerializeObject(listProperties)); WebApiApplication.DataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (int)actor.ActorNr); } //deprecated if (request.State2 != null) { foreach (var actor in request.State2.ActorList) { WebApiApplication.DataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (int)actor.ActorNr); } } var state = (string)JsonConvert.SerializeObject(request.State); WebApiApplication.DataAccess.StateSet(appId, request.GameId, state); var response = new OkResponse(); if (log.IsDebugEnabled) log.Debug(JsonConvert.SerializeObject(response)); return response; }
private static bool IsValid(GameCloseRequest request, out string message) { if (request == null) { message = "Received request does not contain expected JSON data."; return(false); } if (string.IsNullOrWhiteSpace(request.GameId)) { message = "Missing \"GameId\" parameter."; return(false); } message = string.Empty; return(true); }
public dynamic Post(GameCloseRequest request, string appId) { if (log.IsDebugEnabled) { log.DebugFormat("{0} - {1}", Request.RequestUri, JsonConvert.SerializeObject(request)); } string message; if (!IsValid(request, out message)) { var errorResponse = new ErrorResponse { Message = message }; if (log.IsDebugEnabled) { log.Debug(JsonConvert.SerializeObject(errorResponse)); } return(errorResponse); } if (request.State == null) { if (request.ActorCount > 0) { var errorResponse = new ErrorResponse { Message = "Missing State." }; if (log.IsDebugEnabled) { log.Debug(JsonConvert.SerializeObject(errorResponse)); } return(errorResponse); } WebApiApplication.DataAccess.StateDelete(appId, request.GameId); var okResponse = new OkResponse(); if (log.IsDebugEnabled) { log.Debug(JsonConvert.SerializeObject(okResponse)); } return(okResponse); } foreach (var actor in request.State.ActorList) { //var listProperties = new ListProperties() { ActorNr = (int)actor.ActorNr, Properties = request.State.CustomProperties }; //WebApiApplication.DataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (string)JsonConvert.SerializeObject(listProperties)); WebApiApplication.DataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (int)actor.ActorNr); } //deprecated if (request.State2 != null) { foreach (var actor in request.State2.ActorList) { WebApiApplication.DataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (int)actor.ActorNr); } } var state = (string)JsonConvert.SerializeObject(request.State); WebApiApplication.DataAccess.StateSet(appId, request.GameId, state); var response = new OkResponse(); if (log.IsDebugEnabled) { log.Debug(JsonConvert.SerializeObject(response)); } return(response); }