Ejemplo n.º 1
0
        private IActionResult DeleteGame()
        {
            JObject Paramaters = new JObject();

            Request.Query.ToList().ForEach(query =>
            {
                Paramaters[query.Key] = query.Value.ToString();
            });

            // If there's a post body, use it overriding the query string
            try
            {
                using (var reader = new StreamReader(Request.Body))
                {
                    // read posted data
                    JObject postedObject = JObject.Parse(reader.ReadToEnd());
                    postedObject.Properties().ToList().ForEach(property =>
                    {
                        try
                        {
                            Paramaters[property.Name] = property.Value.Value <string>();
                        }
                        catch { }
                    });
                }
            }
            catch { }

            IGameListModule Plugin = null;

            Plugin = _gameListModuleManager.GetLikelyPlugins(Paramaters, Request.Path.Value, Request.Method).FirstOrDefault();

            // transform DELETE paramaters to match default logic
            Plugin?.TransformDeleteParamaters(ref Paramaters);

            // check input rowId
            string rawRowId = Paramaters["__rowId"].Value <string>();

            if (string.IsNullOrWhiteSpace(rawRowId))
            {
                return(StatusCode(400)); // Bad Request
            }
            // process input rowId
            long lookupRowId = -1;

            if (!long.TryParse(rawRowId, out lookupRowId))
            {
                return(StatusCode(400)); // Bad Request
            }
            GameData tmpDat = _gameListContext.CheckGame(lookupRowId);

            if (tmpDat == null)
            {
                return(StatusCode(400));
            }


            // process input rowPw
            string inputRowPw = Paramaters["__rowPW"]?.Value <string>();

            if (string.IsNullOrWhiteSpace(inputRowPw))
            {
                inputRowPw = string.Empty;
            }

            // prepare variables for holding check data
            string lookupRowPw = string.Empty;

            // get RowPw for game
            lookupRowPw = tmpDat.rowPW;

            if (tmpDat.rowId < 0)
            {
                return(StatusCode(400)); // Bad Request
            }
            if (lookupRowPw == null)
            {
                lookupRowPw = string.Empty;
            }

            if (inputRowPw == lookupRowPw)
            {
                // delete the game
                _gameListContext.DeleteGame(tmpDat.rowId);
                return(StatusCode(200)); // OK
            }
            else
            {
                return(StatusCode(401)); // Unauthorized
            }
        }