public HttpResponseMessage FindObject(dynamic json) { if (json == null) { return(Request.CreateResponse <dynamic>(HttpStatusCode.BadRequest, new { Exception = "InvalidObjectFormatException", Message = "Json object you have provided has invalid format" })); } string connectionString = ConfigurationManager.ConnectionStrings["defaultConnection"].ConnectionString; CleverDbContext db = new CleverDbContext(connectionString); try { CleverQuery cq = new CleverQuery(json); var result = db.Find(cq); return(new HttpResponseMessage() { Content = new StringContent(CleverObjectService.GetJsonFromCleverObjectArray(result), Encoding.UTF8, "application/json") }); } catch (Exception exp) { return(Request.CreateResponse <dynamic>(HttpStatusCode.BadRequest, new { Exception = exp.GetType().Name.ToString(), Message = exp.Message })); } }
static void Main(string[] args) { string connectionString = "Data Source = (local);Initial Catalog = CleverDb;Integrated Security = True;MultipleActiveResultSets = True"; CleverDbContext db = new CleverDbContext(connectionString); var obj = new { name = "Насос", parentId = 95, attributes = new { марка = "Bosh", мощность = 95.3, ДатаУстановки = DateTime.Now } }; string stringified = Json.Encode(obj); var clever = CleverObjectService.GetCleverObjectFromJson(stringified); //insert operation CleverObject inserted = db.Insert(clever); Console.WriteLine(inserted.Id); //get operation CleverObject found = db.FindById(inserted.Id); //get subtree operation string json = db.GetSubTreeForTheNode(166); Console.WriteLine("done"); Console.ReadKey(); }
public CleverObject Insert(dynamic obj) { CleverObject result = CleverObjectService.GetCleverObjectFromDynamic(obj); return(Insert(result)); }