/// <summary> /// Delete table by id /// </summary> /// <param name="tableId"></param> /// <returns></returns> public async Task <ResultModel> DeleteTableAsync(Guid?tableId) { var result = new ResultModel(); if (!tableId.HasValue) { return(new InvalidParametersResultModel <object>().ToBase()); } var table = await _context.Table.FirstOrDefaultAsync(x => x.Id == tableId); if (table == null) { return(new NotFoundResultModel()); } var(_, connection) = DbUtil.GetConnectionString(_configuration); var checkColumn = _tablesService.CheckTableValues(connection, table.Name, table.EntityType); if (checkColumn.Result) { result.Errors.Add(new ErrorModel { Message = "The table contains data and cannot be deleted" }); return(result); } var dropResult = _tablesService.DropTable(connection, table.Name, table.EntityType); if (!dropResult.IsSuccess) { return(dropResult.ToBase()); } _context.Table.Remove(table); var dbResult = await _context.PushAsync(); if (!dbResult.IsSuccess) { return(dbResult); } _logger.LogInformation($"Table {table.Name} was deleted"); EntityEvents.Entities.EntityDeleted(new EntityDeleteEventArgs { EntityId = tableId.Value, EntityName = table.Name }); return(dbResult); }