Пример #1
0
        public JsonResult Create([FromBody] Tree Model)
        {
            try
            {
                //PW: validate
                if (TryValidateModel(Model))
                {
                    Guid GeneratedTreeId = db.Create(Model);

                    /*
                     * var inputs = new List<formInput>();
                     * var configs = new List<ConfigField>();
                     * configs.Add(new ConfigField() { name = "root", value = "true"});
                     * inputs.Add(new formInput() { name = "Name", form_control = "text-box-input", config_fields = configs });
                     * Guid GeneratedLeafId = db.Create<Leaf>(new Leaf() { name = "root.leaf", form_inputs = inputs});
                     */

                    //Create root leaf
                    // db.Create<Branch>(new Branch() { is_root = true, name = "Root", level = 0, tree = db.GetByID<Tree>(GeneratedTreeId), order = 0, _id = Guid.NewGuid(), leaf = db.GetByID<Leaf>(GeneratedLeafId), });
                    return(Json(new { status = "OK" }));
                }
                else
                {
                    return(Json(new { status = "INVALID_DATA" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { status = "ERROR", message = ex.Message }));
            }
        }
Пример #2
0
        public async Task <Item> SaveAsync(HomeUser user, Item item)
        {
            if (item.HomeId != user.HomeId)
            {
                item.HomeId = user.HomeId;
            }
            var query = queryRepo.Get((item.Id > 0) ?
                                      "ItemUpdateQuery" : "ItemInsertQuery");

            using (var conn = factory.Create(current))
            {
                await conn.OpenAsync();

                var result = await conn.QueryFirstOrDefaultAsync <Item>(query, item);

                if (result == null)
                {
                    throw new Exception("Item could not be saved");
                }
                return(result);
            }
        } // END SaveAsync
Пример #3
0
        public JsonResult Create([FromBody] Leaf Model)
        {
            try
            {
                //PW: validate
                if (TryValidateModel(Model))
                {
                    Guid GeneratedTreeId = db.Create(Model);

                    return(Json(new { status = "OK" }));
                }
                else
                {
                    return(Json(new { status = "INVALID_DATA" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { status = "ERROR", message = ex.Message }));
            }
        }