コード例 #1
0
        public static async Task <Columns> MapAsync()
        {
            var columns          = new Columns();
            var objectToDbMapper = await ObjectToDbMapperFactory <TEntity> .Create();

            ReflectionHelper.GetListOfProperties <TEntity>()
            .ToList()
            .ForEach(prop =>
            {
                var columnName = prop.Name;
                var ignore     = false;
                objectToDbMapper.GetColumnName(prop.Name)
                .Success(x =>
                {
                    if (!x.IsIgnore)
                    {
                        if (!string.IsNullOrWhiteSpace(x.ColumnName))
                        {
                            columnName = x.ColumnName;
                        }
                    }
                    else
                    {
                        ignore = true;
                    }
                });
                if (!ignore)
                {
                    columns.Add(columnName);
                }
            });
            return(columns);
        }
コード例 #2
0
 public async Task <Response <TEntity> > GetByIdAsync(int id) =>
 (await ObjectToDbMapperFactory <TEntity> .Create()).GetPk()
 .Success(async x =>
          Response <TEntity> .From((await CreateMapper()).Map(await SqlAccessService.SelectData(new Parameters()
                                                                                                .Add(x, id)
                                                                                                .Send(),
                                                                                                (await EntityToColumns <TEntity> .MapAsync()).Send()))))
 .Error(x => Response <TEntity> .Error());
コード例 #3
0
 public SqlAccessService()
 {
     _connectionString = ConfigurationManagerKeys.Configuration().ConnectionString;
     Task.Run(async() =>
     {
         _objectToDbMapper = await ObjectToDbMapperFactory <TEntity> .Create();
     }).Wait();
     _dataTableName = _objectToDbMapper.TableName;
 }
コード例 #4
0
ファイル: MapHelper.cs プロジェクト: germankuber/LicitProd
        private static async Task <TEntityType> ParseObjectAsync(DataRow row, TEntityType entity)
        {
            var mapper = await ObjectToDbMapperFactory <TEntityType> .Create();

            foreach (var prop in ReflectionHelper.GetListOfProperties <TEntityType>())
            {
                var columnName = prop.Name;
                mapper.GetColumnName(prop.Name)
                .Success(x =>
                {
                    if (!string.IsNullOrEmpty(x.ColumnName))
                    {
                        columnName = x.ColumnName;
                    }
                });

                try
                {
                    if (row.Table.Columns[columnName] != null)
                    {
                        var value = row[columnName].ToString();
                        if (prop.PropertyType.IsEnum && !string.IsNullOrWhiteSpace(value))
                        {
                            prop.SetValue(entity, Enum.Parse(prop.PropertyType, value));
                        }
                        else if (!prop.PropertyType.IsEnum)
                        {
                            prop.SetValue(entity, Convert.ChangeType(value, prop.PropertyType), null);
                        }
                    }
                }
                catch (ArgumentException ex)
                {
                    //TODO : Extrae el try catch
                    Console.WriteLine(ex);
                }
                catch (Exception) { }
            }
            return(entity);
        }
コード例 #5
0
 public async Task <List <TEntity> > GetByIdsAsync(List <int> ids) =>
 (await ObjectToDbMapperFactory <TEntity> .Create()).GetPk()
 .Success(async x =>
          (await CreateMapper()).MapList(await SqlAccessService.SelectDataIn(new Parameters()
                                                                             .Add("Id", string.Empty),
                                                                             GetParameters(ids), new List <string>())));