Ejemplo n.º 1
0
        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
                }));
            }
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        public object GetSubtree(int id)
        {
            string          connectionString = ConfigurationManager.ConnectionStrings["defaultConnection"].ConnectionString;
            CleverDbContext db = new CleverDbContext(connectionString);

            try
            {
                return(Json(db.GetSubTreeForTheNode(id)));
            }
            catch (Exception exp)
            {
                return(Request.CreateResponse <dynamic>(HttpStatusCode.InternalServerError,
                                                        new
                {
                    Exception = exp.GetType().Name.ToString(),
                    Message = exp.Message
                }));
            }
        }
Ejemplo n.º 5
0
        public HttpResponseMessage Get(int id)
        {
            string          connectionString = ConfigurationManager.ConnectionStrings["defaultConnection"].ConnectionString;
            CleverDbContext db = new CleverDbContext(connectionString);

            try
            {
                var result = db.FindById(id);
                return(new HttpResponseMessage()
                {
                    Content = new StringContent(result == null ? "{}" : result.ToString(), Encoding.UTF8, "application/json")
                });
            }
            catch (Exception exp)
            {
                return(Request.CreateResponse <dynamic>(HttpStatusCode.InternalServerError,
                                                        new
                {
                    Exception = exp.GetType().Name.ToString(),
                    Message = exp.Message
                }));
            }
        }