public IActionResult Patch([FromRoute] String table, [FromRoute] String id, [FromBody] JObject jObject) { var patch = new DbPatchModel { Table = table, Id = id, Values = jObject.ToDictionary() }; dc.Patch <IDbRecord>(patch); return(Ok()); }
public async Task Run(Database dc, Workflow wf, ActivityInWorkflow activity, ActivityInWorkflow preActivity) { string json = "{" + activity.GetOptionValue("values") + "}"; var values = JObject.Parse(json); var dic = JObject.FromObject(activity.Input.Data).ToDictionary(); dic.ToList().ForEach(p => values[p.Key] = JToken.FromObject(p.Value)); var paramters = new List <Object>(); var createIfNotExists = bool.Parse(activity.GetOptionValue("createIfNotExists") ?? "false"); var patch = new DbPatchModel { Table = activity.GetOptionValue("table"), Where = activity.GetOptionValue("where"), Values = dic }; var tableType = TypeHelper.GetType(patch.Table, (string[])AppDomain.CurrentDomain.GetData("Assemblies")); JObject.FromObject(activity.Input.Data).Properties() .ToList() .ForEach(d => { if (patch.Where.Contains("{" + d.Name + "}")) { patch.Where = patch.Where.Replace("{" + d.Name + "}", "@" + paramters.Count()); var propertType = tableType.GetProperty(d.Name).PropertyType; paramters.Add(d.Value.ToObject(propertType)); } }); patch.Params = paramters.ToArray(); // check if exists if (dc.Table(patch.Table).Any(patch.Where, patch.Params)) { dc.Patch <IDbRecord>(patch); } else { dc.Add(values.ToObject(tableType)); } activity.Output = activity.Input; }
private void PatchRecord(Database db) { DateTime dt = DateTime.UtcNow.AddMinutes(-5); var patch = new DbPatchModel { Table = "PizzaOrder", Id = PIZZA_ORDER_ID }; patch.Values.Add("CreatedTime", dt); int row = db.DbTran(() => db.Patch <IDbRecord>(patch)); var po = db.Table <PizzaOrder>().Find(PIZZA_ORDER_ID); Assert.IsTrue(po.CreatedTime.ToString() == dt.ToString()); }