public HttpResponseMessage Insert(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 { var inserted = db.Insert(json); return(new HttpResponseMessage() { Content = new StringContent(inserted.ToString(), Encoding.UTF8, "application/json") }); } catch (Exception exp) { return(Request.CreateResponse <dynamic>(HttpStatusCode.BadRequest, new { Exception = exp.GetType().Name.ToString(), Message = exp.Message })); //throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, 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(); }