Exemple #1
0
        private Database GetSelfReferencingOneToManySchema()
        {
            var categoryTable = new TableDto {
                Name = "Categories"
            };
            var tables = new List <TableDto> {
                categoryTable
            };
            var columns = new List <ColumnDto> {
                new ColumnDto {
                    IsPrimaryKey    = true,
                    IsAutoGenerated = true,
                    Name            = "CategoryId",
                    DbTypeName      = "int",
                    TableName       = "Categories"
                },
                new ColumnDto {
                    Name = "ParentId", DbTypeName = "int", TableName = "Categories"
                }
            };

            var foreignKeys = new List <ForeignKeyDto> {
                new ForeignKeyDto {
                    ColumnName           = "ParentId",
                    Name                 = "Parent",
                    ReferencedColumnName = "CategoryId",
                    TableName            = "Categories",
                    ReferencedTableName  = "Categories"
                }
            };

            return(new Database(tables, columns, null, foreignKeys));
        }
Exemple #2
0
        public void GetTableProjection_DatabaseServiceReturnsTable_ReturnsTableDto()
        {
            // Arrange
            string dbName = "testDatabase";

            string[] attributesNames = { "firstAttribute" };
            Table    testTable       = new Table
            {
                Name       = "testTable",
                Attributes = { new Domain.Models.Attribute {
                                   Name = attributesNames.First(), Type = "someType"
                               } },
                Rows = { { 0, new Row {
                               Id = 0, Value ={ "firstValue" }
                           } } }
            };

            // Arrange - mock dbService
            this._dbServiceMock.Setup(s => s.GetTableProjection(dbName, testTable.Name, attributesNames))
            .Returns(testTable);

            // Arrange - create target
            DbWcfService target = new DbWcfService(this._dbServiceMock.Object);

            // Act
            TableDto table = target.GetTableProjection(dbName, testTable.Name, attributesNames);

            // Assert
            Assert.IsNotNull(testTable);
            Assert.AreEqual(testTable.Name, table.Name);
            Assert.AreEqual(testTable.Attributes, table.Attributes);
            Assert.AreEqual(testTable.Rows.Values, table.Rows);
        }
Exemple #3
0
        private async void OnDeleteTable(TableDto obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var ok = await DisplayDeleteAlertAsync();

                if (ok)
                {
                    TempZone.Tables.Remove(obj);
                }
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemple #4
0
        public IHttpActionResult GetTable(string dbName, string tableName)
        {
            try
            {
                Table table = this._databaseService.GetTable(dbName, tableName);
                if (table == null)
                {
                    return(this.NotFound());
                }

                return(this.Ok(TableDto.CreateFromTable(table)));
            }
            catch (ArgumentException)
            {
                return(this.BadRequest());
            }
            catch (DatabaseNotFoundException)
            {
                return(this.NotFound());
            }
            catch (DbServiceException)
            {
                return(this.InternalServerError());
            }
        }
Exemple #5
0
        public IHttpActionResult GetTableProjection(string dbName, string tableName,
                                                    [FromUri] IEnumerable <string> attributesNames)
        {
            try
            {
                Table table = this._databaseService.GetTableProjection(dbName, tableName, attributesNames);
                if (table == null)
                {
                    return(this.NotFound());
                }

                return(this.Ok(TableDto.CreateFromTable(table)));
            }
            catch (ArgumentException)
            {
                return(this.BadRequest());
            }
            catch (DatabaseNotFoundException)
            {
                return(this.NotFound());
            }
            catch (AttributeNotFoundException)
            {
                return(this.BadRequest("Nonexistent attribute's name."));
            }
            catch (DbServiceException)
            {
                return(this.InternalServerError());
            }
        }
Exemple #6
0
        private List <TableDto> TransformDtIntoObj(DataTable dt)
        {
            if (dt == null || dt.Rows.Count < 1)
            {
                MessageBox.Show("Sorry could not retrieve table details.");
                return(null);
            }

            var returnList = new List <TableDto>();
            var tempTab    = new TableDto();

            tempTab.Rows = new List <DBRowsDto>();
            var lastTableName = "";

            foreach (DataRow r in dt.Rows)
            {
                var tempTableName = r["TABLE_NAME"].ToString();

                var tempRow = new DBRowsDto
                {
                    Name                  = r["COLUMN_NAME"].ToString(),
                    SchemaName            = r["TABLE_SCHEMA"].ToString(),
                    DataType              = EnumHelper.TranslateDataType(r["DATA_TYPE"]),
                    ColumnDefault         = r["COLUMN_DEFAULT"] != DBNull.Value? r["COLUMN_DEFAULT"].ToString() : "",
                    MaxLength             = r["CHARACTER_MAXIMUM_LENGTH"] != DBNull.Value? Convert.ToInt32(r["CHARACTER_MAXIMUM_LENGTH"]) : default(int),
                    NumericPrecision      = r["NUMERIC_PRECISION"] != DBNull.Value ? Convert.ToInt32(r["NUMERIC_PRECISION"]) : default(int),
                    NumericPrecisionRadix = r["NUMERIC_PRECISION_RADIX"] != DBNull.Value ? Convert.ToInt32(r["NUMERIC_PRECISION_RADIX"]) : default(int),
                    NumericScale          = r["NUMERIC_SCALE"] != DBNull.Value ? Convert.ToInt32(r["NUMERIC_SCALE"]) : default(int),
                    DateTimePrecision     = r["DATETIME_PRECISION"] != DBNull.Value ? Convert.ToInt32(r["DATETIME_PRECISION"]) : default(int)
                };


                if (!string.IsNullOrEmpty(lastTableName) &&
                    !lastTableName.Equals(tempTableName, StringComparison.CurrentCultureIgnoreCase))
                {
                    tempTab.Name = lastTableName;
                    returnList.Add(tempTab);
                    lastTableName = tempTableName;

                    tempTab      = new TableDto();
                    tempTab.Name = tempTableName;
                    tempTab.Rows = new List <DBRowsDto>();
                }

                tempTab.Rows.Add(tempRow);
                lastTableName = tempTableName;
            }

            //add the last outstanding table
            if (tempTab != null && tempTab.Rows.Count > 0)
            {
                if (returnList.Count <= 1)
                {
                    tempTab.Name = lastTableName;
                }
                returnList.Add(tempTab);
            }

            return(returnList);
        }
        public async Task <TableDto> GetTable(int tableId)
        {
            var table = await _dbContext.Tables.Where(st => st.Id == tableId)
                        .SingleOrDefaultAsync();

            return(TableDto.Map(table));
        }
        public async Task <TableDto> GetTable(string tableName)
        {
            var table = await _dbContext.Tables.Where(st => st.Name == tableName)
                        .SingleOrDefaultAsync();

            return(TableDto.Map(table));
        }
Exemple #9
0
        private Database MakeSchema(CustomConfig config)
        {
            var tables  = new List <TableDto>();
            var columns = new List <ColumnDto>();
            var fks     = new List <ForeignKeyDto>();

            foreach (var map in config.Maps)
            {
                var table = new TableDto();
                table.Name = map.Table;
                foreach (var column in map.Columns.Where(c => c.Value.Relationship == RelationshipType.ManyToOne))
                {
                    columns.Add(new ColumnDto {
                        Name = column.Value.DbName, TableName = column.Value.Map.Table, DbType = column.Value.DbType
                    });
                    fks.Add(
                        new ForeignKeyDto {
                        ColumnName           = column.Value.DbName,
                        Name                 = "fk_" + column.Value.DbName,
                        ReferencedColumnName = column.Value.ParentMap.PrimaryKey.DbName,
                        ReferencedTableName  = column.Value.ParentMap.Table,
                        TableName            = column.Value.Map.Table
                    });
                }

                tables.Add(table);
            }

            return(new Database(tables, columns, null, fks));
        }
 public UpdateTableViewModel(TableDto tableDto)
 {
     TableDto     = tableDto;
     Number       = tableDto.Number;
     Seats        = tableDto.Seats;
     tableService = new TableService();
 }
        public async Task <List <TableDto> > List()
        {
            var tables = await _dbContext.Tables.ToListAsync();

            return(tables.Select(t => TableDto.Map(t))
                   .ToList());
        }
Exemple #12
0
        public async Task <TableDto> UpdateTableAsync(TableDto tableDto)
        {
            Table table   = tableDto.ToEntity();
            Table updated = await _repository.UpdateTableAsync(table);

            return(new TableDto(updated));
        }
        public TableDto<GroupBuyStore> Get(int limit = 1000, int offset = 0, string search = null, string order = "asc", string category=null)
        {
            List<GroupBuyStore> stores;
            TableDto<GroupBuyStore> list;
            using (var db = new HoGameEISContext())
            {
                stores = db.GroupBuyStores.ToList();

                if (search != null)
                    stores = stores.Where(o => o.StoreName.Contains(search)).ToList();

                if (!String.IsNullOrEmpty(category))
                    stores = stores.Where(o => o.Category.Contains(category)).ToList();

                int total = stores.Count();

                stores = stores.Skip(offset).Take(limit).ToList();

                list = new TableDto<GroupBuyStore>()
                {
                    total = total,
                    rows = stores
                };
            }

            return list;
        }
Exemple #14
0
        private static void FillColumnData(QueryResult queryResult, TableDto table)
        {
            if (queryResult.Columns == null ||
                !queryResult.Columns.Any())
            {
                return;
            }

            foreach (var dataColumn in queryResult.Columns)
            {
                var tableColumn = table.Columns.SingleOrDefault(c => c.Key == dataColumn.Code);

                if (tableColumn == null)
                {
                    tableColumn = new TableColumnDto
                    {
                        Key   = dataColumn.Code,
                        Order = table.Columns.Any()
                                                        ? table.Columns.Max(_ => _.Order) + 1
                                                        : 1
                    };

                    var columnsList = table.Columns.ToList();

                    columnsList.Add(tableColumn);

                    table.Columns = columnsList.ToArray();
                }

                tableColumn.Description = dataColumn.Description;

                tableColumn.Name = dataColumn.Name;
            }
        }
Exemple #15
0
        public HtmlTemplateCodeBuilder(string templateFilePath, TableDto tableDto, string filePath) : base(tableDto, filePath)
        {
            TemplateFilePath = templateFilePath;
            var file = new FileInfo(templateFilePath);

            this.FileName = file.Name.Replace(file.Extension, "");
            this.Suffix   = ".html";
        }
Exemple #16
0
 public static BusinessLayer.Table FromDto(TableDto tableDto)
 {
     return new BusinessLayer.Table
                {
                    Id = tableDto.Id,
                    Name = tableDto.Name,
                    Number = tableDto.Number
                };
 }
Exemple #17
0
 public static BusinessLayer.Table FromDto(TableDto tableDto)
 {
     return(new BusinessLayer.Table
     {
         Id = tableDto.Id,
         Name = tableDto.Name,
         Number = tableDto.Number
     });
 }
        public async Task Update(TableDto model)
        {
            var basketContent = new StringContent(JsonConvert.SerializeObject(model), System.Text.Encoding.UTF8, "application/json");

            var response = await _apiClient.PostAsync("", basketContent);

            _kitchenSender.SendTable(model);
            response.EnsureSuccessStatusCode();
        }
Exemple #19
0
        public static string JavaEntityCode(this TableDto table, ProviderType provider, NamingType type = NamingType.Naming)
        {
            var primary = table.PrimaryColumn;
            var sb      = new StringBuilder();

            sb.AppendLine("/**");
            sb.AppendLine($" * {table.Desc()}");
            sb.AppendLine(" *");
            sb.AppendLine(" * @author {user}");
            sb.AppendLine($" * @date {Clock.Now:yyyy/MM/dd}");
            sb.AppendLine(" * @serial generate by spear ");
            sb.AppendLine(" */");
            sb.AppendLine("@Getter");
            sb.AppendLine("@Setter");
            sb.AppendLine($"@TableName(\"{table.Name}\")");
            var clsName = table.GetConvertedName();

            if (type == NamingType.Naming)
            {
                clsName = table.GetConvertedName(start: 1);
            }
            sb.AppendLine(
                $"public class {clsName}PO implements Serializable {{");
            sb.AppendLine("\tprivate static final long serialVersionUID = 1L;");
            var index = 0;

            foreach (var column in table.Columns)
            {
                sb.AppendLine("\t/**");
                sb.AppendLine($"\t * {column.Desc()}");
                sb.AppendLine("\t */");
                if (column.IsPrimaryKey)
                {
                    sb.AppendLine($"\t@TableId(value = \"{column.Name}\", type = IdType.AUTO)");
                }
                else
                {
                    sb.AppendLine($"\t@TableField(\"{column.Name}\")");
                }
                var field = column.GetConvertedName(Spear.Core.Serialize.NamingType.CamelCase);
                if (type == NamingType.Naming)
                {
                    field = column.GetConvertedName(Spear.Core.Serialize.NamingType.CamelCase, 1);
                }
                sb.AppendLine($"\tprivate {column.LanguageType(provider, LanguageType.Java)} {field};");

                if (index < table.Columns.Count() - 1)
                {
                    sb.AppendLine(string.Empty);
                }
                index++;
            }

            sb.AppendLine("}");
            return(sb.ToString());
        }
Exemple #20
0
        public static TableDto TableDto(string name = null)
        {
            var dto = new TableDto();

            if (!string.IsNullOrEmpty(name))
            {
                dto = dto.WithName(name);
            }
            return(dto);
        }
Exemple #21
0
        public async Task <ActionResult <TableDto> > UpdateTable(TableDto table)
        {
            var updatedTable = await this._dal.UpdateTable(table);

            if (updatedTable != null)
            {
                return(Ok(updatedTable));
            }

            return(NotFound());
        }
Exemple #22
0
        public async Task <ActionResult <TableDto> > Post(TableDto dto)
        {
            var entity = new Table();

            mapper.Map(dto, entity);
            dataContext.Add(entity);
            await dataContext.SaveChangesAsync();

            dto.Id = entity.Id;
            return(dto);
        }
Exemple #23
0
        public async Task <TableDto> CreateTableAsync(TableDto tableDto)
        {
            Table table   = tableDto.ToEntity();
            Table created = await _repository.AddTableAsync(table);

            if (created == null)
            {
                throw new Exception("Table already exists.");
            }
            return(new TableDto(created));
        }
 public IActionResult Put(TableDto categoriesDto)
 {
     try
     {
         return(Ok(_tableService.Update(categoriesDto)));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(BadRequest("Ocorreu uma falha na alteração de Mesa"));
     }
 }
        /// <summary>
        /// Returns a table object with all it's elements from the remote database.
        /// </summary>
        /// <param name="name">The name of the table without dot separator.</param>
        /// <returns>Task&lt;Table&gt;.</returns>
        /// <exception cref="ArgumentNullException">name is null!</exception>
        public async Task <Table> GetTableAsync(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name is null!");
            }
            TableDto tableDto = await aceQLHttpApi.GetTableAsync(name);

            Table table = tableDto.Table;

            return(table);
        }
Exemple #26
0
        public async Task <ActionResult <TableDto> > Put(TableDto dto)
        {
            var entity = await dataContext.Set <Table>().FirstOrDefaultAsync(x => x.Id == dto.Id);

            if (entity == null)
            {
                return(NotFound());
            }
            mapper.Map(dto, entity);
            await dataContext.SaveChangesAsync();

            return(dto);
        }
        public async Task <IActionResult> UpdateTable(TableDto tableDto)
        {
            var ok = await _mediator.Send(new UpdateTableCommand(tableDto));

            if (ok)
            {
                return(NoContent());
            }
            else
            {
                return(BadRequest("Không thể cập nhật bàn!"));
            }
        }
        public async Task <IActionResult> CreateTable(TableDto tableDto)
        {
            var table = await _mediator.Send(new AddTableCommand(tableDto));

            if (table != null)
            {
                return(CreatedAtRoute(nameof(GetTable), new { id = table.Id }, table));
            }
            else
            {
                return(BadRequest("Không thể tạo mới!"));
            }
        }
Exemple #29
0
        public TableDto CreateTable(int number, int seats)
        {
            Table table = tableDb.CreateTable(number, seats);

            TableDto tableDto = new TableDto()
            {
                Id     = table.Id,
                Number = table.Number,
                Seats  = table.Seats
            };

            return(tableDto);
        }
Exemple #30
0
        public static TableModel ToModel(this TableDto table)
        {
            if (table == null)
            {
                return(null);
            }

            return(new TableModel
            {
                Columns = table.Columns?.Select(_ => _.ToModel()),
                Rows = table.Rows?.Select(_ => _.ToModel())
            });
        }
Exemple #31
0
        public static string EntityCode(this TableDto table, ProviderType provider,
                                        LanguageType language = LanguageType.CSharp, NamingType type = NamingType.Naming)
        {
            switch (language)
            {
            case LanguageType.CSharp:
                return(table.CSharpEntityCode(provider, type));

            case LanguageType.Java:
                return(table.JavaEntityCode(provider, type));
            }
            return(table.CSharpEntityCode(provider, type));
        }
        public async Task <ActionResult <string> > GenerateCreateTableStringAsync(TableDto tableDto)
        {
            var validationResult = tableDto.Validate();

            if (validationResult.IsValid != true)
            {
                return(BadRequest(validationResult.Error));
            }

            var table  = tableDto.Map();
            var script = await _dbScriptsService.GenerateCreateTableScriptAsync(table);

            return(Ok(script));
        }
        public TableDto<GroupBuyDto> GetGroupbuyList(int limit = 1000, int offset = 0, string search = null, string order = "asc", string category = null)
        {
            List<GroupBuyDto> groupbuys; ;
            TableDto<GroupBuyDto> list;
            using (var db = new HoGameEISContext())
            {
                var sql = @"[dbo].[usp_GetGroupbuyList] @isOngoing";
                groupbuys = db.Database.SqlQuery<GroupBuyDto>(sql, new SqlParameter("@isOngoing", category == "ongoing")).ToList();

                if (search != null)
                    groupbuys = groupbuys.Where(o => o.Description.Contains(search)).ToList();

                int total = groupbuys.Count();

                groupbuys = groupbuys.Skip(offset).Take(limit).ToList();

                list = new TableDto<GroupBuyDto>()
                {
                    total = total,
                    rows = groupbuys
                };
            }

            return list;
        }