示例#1
0
        public void CreateTable(User user, string tableName, dynamic columns, string masterTableId)
        {
            // Add meta data
            var table = new Table
            {
                name        = tableName,
                createdTime = DateTime.Now,
                createdBy   = user.id
            };

            if (_db.Tables.Any(t => t.name == tableName))
            {
                throw new TedExeption(ExceptionCodes.Generic, $"Table {table} already exist");
            }

            _db.Tables.Add(table);
            _db.SaveChanges();

            using (var tbl = new FlexTable(_config.GetConnectionString("DefaultConnection"), tableName))
            {
                tbl.CreateTable();

                tbl.CreateColumns(columns);

                if (!string.IsNullOrEmpty(masterTableId))
                {
                    tbl.CreateColumn(masterTableId + "_id", "int", false);
                }
            }
        }
示例#2
0
        public void UpdatePage(int pageId, PageUpdate update)
        {
            var page = _db.Pages.SingleOrDefault(r => r.id == pageId && !r.deleted);

            if (page == null)
            {
                throw new Exception($"The page with id {pageId} does not exist");
            }

            // Always set the child components JSON
            page.json = update.json.Replace("\\r", "");

            // This is a column update so create the column
            if (update.column != null)
            {
                if (update.dataSourceId == null)
                {
                    throw new Exception("DatasourceId is missing from the update");
                }
                using (var tbl = new FlexTable(_config.GetConnectionString("DefaultConnection"), update.dataSourceId))
                {
                    tbl.CreateColumn(update.column.name, update.column.type, true);
                }
            }

            _db.SaveChanges();
        }