Beispiel #1
0
        public string UpdateScore([FromBody] System.Text.Json.JsonElement rawQuery)
        {
            string rawJson   = rawQuery.ToString();
            User   scoreData = JsonConvert.DeserializeObject <User>(rawJson);

            error err = new error
            {
                Code    = 0,
                Message = "Successfull"
            };

            using (var context = new UsersDBContext())
            {
                User user = context.Users.Where(x => x.Name == scoreData.Name).FirstOrDefault();
                if (user == null)
                {
                    err.Code    = 1;
                    err.Message = "Error update values, player doesnt exist";
                }
                else
                {
                    user.Score += scoreData.Score;
                    user.Win   += scoreData.Win;
                    user.Lose  += scoreData.Lose;

                    context.SaveChanges();
                }
            }

            string response = JsonConvert.SerializeObject(err);

            return(response);
        }
        public async Task <IActionResult> Send(
            MessageType msgType,
            [FromBody] System.Text.Json.JsonElement message
            )
        {
            var json = message.ToString();
            var obj  = await _provider.GetHandler(msgType)
                       .HandleMessageAsync(json);

            return(Ok(obj));
        }
        public IActionResult Put(System.Text.Json.JsonElement value)
        {
            StudentModel model = JsonConvert.DeserializeObject <StudentModel>(value.ToString());

            if (managerModel.EditStudent(model) > 0)
            {
                return(Ok(new { state = "Successful" }));
            }
            else
            {
                return(NotFound(new { Result = "Edit operation failed" }));
            }
        }
        public IActionResult Post(System.Text.Json.JsonElement value)
        {
            StudentModel model = JsonConvert.DeserializeObject <StudentModel>(value.ToString());

            if (managerModel.AddStudent(model) > 0)
            {
                return(Ok(new { Result = "Saved", state = "Successful" }));
            }
            else
            {
                return(NotFound(new { Result = "something went wrong", state = "UnSuccessful" }));
            }
        }
        public async Task <object> Post([FromBody] System.Text.Json.JsonElement _query)
        {
            string rawJson = _query.ToString();
            var    query   = JsonConvert.DeserializeObject <GraphQLQueryDTO>(rawJson);
            var    result  = await _executer.ExecuteAsync(_ =>
            {
                _.Schema = _schema;
                _.Query  = query.Query;
                _.Inputs = query.Variables?.ToInputs();
            });

            if (result.Errors?.Count > 0)
            {
                for (int i = 0; i < result.Errors.Count; i++)
                {
                    _errors.Errors.Add(result.Errors[i].Message);
                }
                return(_errors);
            }

            return(Ok(result));
        }
Beispiel #6
0
        public string Post([FromBody] System.Text.Json.JsonElement rawQuery)
        {
            string rawJson = rawQuery.ToString();

            error err = new error
            {
                Code    = 0,
                Message = "Successfull"
            };

            string response;

            User userData = JsonConvert.DeserializeObject <User>(rawJson);

            using (var context = new UsersDBContext())
            {
                User user = context.Users.Where(x => x.Name == userData.Name).FirstOrDefault();
                if (user != null)
                {
                    //err.Code = 1;
                    //err.Message = "Name already naken";
                    //Already have user
                }
                else
                {
                    context.Users.Add(userData);
                    context.SaveChanges();
                }
            }

            response = JsonConvert.SerializeObject(err);

            //string jsonData = JsonConvert.SerializeObject(query);
            //Newtonsoft.Json.Linq.JObject
            //var aa = JsonConvert.DeserializeObject(value.ToString());
            return(response);
        }
Beispiel #7
0
        public string GetConditionSql()
        {
            if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Op))
            {
                return(string.Empty);
            }

            string op = Op.ToLower();

            if (op == "isnull" || op == "isnotnull")
            {
                return(string.Format(" {0} {1} ", Field, op == "isnull" ? "IS NULL" : "IS NOT NULL"));
            }

            if (Value == null)
            {
                throw new Exception("condition error");
            }

            System.Text.Json.JsonElement jsonVal = (System.Text.Json.JsonElement)Value;
            string valStr = jsonVal.ToString();

            if (jsonVal.ValueKind == System.Text.Json.JsonValueKind.String)
            {
                valStr = "'" + valStr.Replace("'", "''") + "'";
            }
            else if (jsonVal.ValueKind == System.Text.Json.JsonValueKind.Array)
            {
                valStr = valStr.Substring(1, valStr.Length - 2);
            }

            switch (Op.ToLower())
            {
            case "eq":
                return(string.Format(" {0} = {1} ", Field, valStr));

            case "ne":
                return(string.Format(" {0} <> {1} ", Field, valStr));

            case "lt":
                return(string.Format(" {0} < {1} ", Field, valStr));

            case "le":
                return(string.Format(" {0} <= {1} ", Field, valStr));

            case "gt":
                return(string.Format(" {0} > {1} ", Field, valStr));

            case "ge":
                return(string.Format(" {0} >= {1} ", Field, valStr));

            case "like":
                return(string.Format(" {0} like {1} ", Field, valStr));

            case "in":
                return(string.Format(" {0} in ({1}) ", Field, valStr));

            case "notin":
                return(string.Format(" {0} not in ({1})", Field, valStr));
            }

            throw new Exception("condition error");
        }