Exemple #1
0
        public override void DELETE()
        {
            //Get required fields
            if (!Params.ContainsKey("table"))
            {
                Response.Send("Missing params", HttpStatusCode.BadRequest);
                return;
            }
            if (!JSON.TryGetValue <JArray>("RowIDs", out JToken RowIDs))
            {
                Response.Send("Missing fields", HttpStatusCode.BadRequest);
                return;
            }

            //Check if all specified table exist
            GenericDataTable Table = GenericDataTable.GetTableByName(Connection, Params["table"][0]);

            if (Table == null)
            {
                Response.Send("No such table", HttpStatusCode.NotFound);
                return;
            }

            List <int> IDs = (((JArray)RowIDs).Where(ID => ID.Type == JTokenType.Integer).Select(ID => (int)ID)).ToList();

            Table.Delete(IDs);
            Response.Send(HttpStatusCode.OK);
        }
Exemple #2
0
        public void Delete_ValidArguments()
        {
            Table.Insert(new Dictionary <string, dynamic> {
                { "StringColumn", "Value" }
            });
            Table.Delete(1);

            Assert.IsTrue(JToken.DeepEquals(new JObject {
                { "Columns", new JObject {
                      { "rowid", "Integer" },
                      { "StringColumn", "String" },
                      { "IntegerColumn", "Integer" },
                      { "Validated", "Integer" }
                  } },
                { "Rows", new JArray()
                  {
                  } }
            }, Table.GetRows()));
        }