private static bool IsValid(GamePropertiesRequest request, out string message) { if (string.IsNullOrEmpty(request.GameId)) { message = "Missing GameId."; return(false); } message = ""; return(true); }
public dynamic Post(GamePropertiesRequest 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) { var state = (string)JsonConvert.SerializeObject(request.State); WebApiApplication.DataAccess.StateSet(appId, request.GameId, state); var properties = request.Properties; object actorNrNext = null; if (properties != null) { properties.TryGetValue("turn", out actorNrNext); } var userNextInTurn = string.Empty; foreach (var actor in request.State.ActorList) { if (actorNrNext != null) { if (actor.ActorNr == actorNrNext) { userNextInTurn = (string)actor.UserId; } } WebApiApplication.DataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (int)actor.ActorNr); } if (!string.IsNullOrEmpty(userNextInTurn)) { var notificationContent = new Dictionary<string, string> { { "en", "{USERNAME} finished. It's your turn." }, { "de", "{USERNAME} hat seinen Zug gemacht. Du bist dran." }, }; pushWoosh.RequestPushNotification(notificationContent, request.Username, "UID2", userNextInTurn, appId); } } var response = new OkResponse(); if (log.IsDebugEnabled) log.Debug(JsonConvert.SerializeObject(response)); return response; }
public IActionResult Index([FromBody] GamePropertiesRequest request, string appId) { if (!IsValid(request, out string message)) { var errorResponse = new ErrorResponse { Message = message }; _logger.LogError($"{Request.GetUri()} - {JsonConvert.SerializeObject(errorResponse)}"); return(Ok(errorResponse)); } appId = appId.ToLowerInvariant(); if (request.State != null) { var state = JsonConvert.SerializeObject(request.State); _dataAccess.StateSet(appId, request.GameId, state); var properties = request.Properties; object actorNrNext = null; properties?.TryGetValue("turn", out actorNrNext); var userNextInTurn = string.Empty; foreach (var actor in request.State.ActorList) { if (actorNrNext != null) { if (actor.ActorNr == actorNrNext) { userNextInTurn = (string)actor.UserId; } } _dataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (int)actor.ActorNr); } if (!string.IsNullOrEmpty(userNextInTurn)) { var notificationContent = new Dictionary <string, string> { { "en", "{USERNAME} finished. It's your turn." }, { "de", "{USERNAME} hat seinen Zug gemacht. Du bist dran." }, }; _notification.SendMessage(notificationContent, request.Nickname, "UID2", userNextInTurn, appId); } } var response = new OkResponse(); _logger.LogInformation($"{Request.GetUri()} - {JsonConvert.SerializeObject(response)}"); return(Ok(response)); }
private static bool IsValid(GamePropertiesRequest request, out string message) { if (string.IsNullOrEmpty(request.GameId)) { message = "Missing GameId."; return false; } message = ""; return true; }
public dynamic Post(GamePropertiesRequest 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) { var state = (string)JsonConvert.SerializeObject(request.State); WebApiApplication.DataAccess.StateSet(appId, request.GameId, state); var properties = request.Properties; object actorNrNext = null; if (properties != null) { properties.TryGetValue("turn", out actorNrNext); } var userNextInTurn = string.Empty; foreach (var actor in request.State.ActorList) { if (actorNrNext != null) { if (actor.ActorNr == actorNrNext) { userNextInTurn = (string)actor.UserId; } } WebApiApplication.DataAccess.GameInsert(appId, (string)actor.UserId, request.GameId, (int)actor.ActorNr); } if (!string.IsNullOrEmpty(userNextInTurn)) { var notificationContent = new Dictionary <string, string> { { "en", "{USERNAME} finished. It's your turn." }, { "de", "{USERNAME} hat seinen Zug gemacht. Du bist dran." }, }; pushWoosh.RequestPushNotification(notificationContent, request.Username, "UID2", userNextInTurn, appId); } } var response = new OkResponse(); if (log.IsDebugEnabled) { log.Debug(JsonConvert.SerializeObject(response)); } return(response); }