using Dto; using Model; using Shared; namespace APIMappers; public static class DataSourceMapper { private static GenericMapper _mapper = new (); public static DataSource ToModel(this DataSourceDto dto) { Func create = dataSourceDto => new DataSource( dataSourceDto.Id, dataSourceDto.Type, dataSourceDto.Model, dataSourceDto.Precision, dataSourceDto.Athletes.ToModels().ToList(), dataSourceDto.Activities.ToModels().ToList()); /* Action link = (dataSourceDto, model) => { model.Activities.AddRange(dataSourceDto.Activities.ToModels()); model.Athletes.AddRange(dataSourceDto.Athletes.ToModels()); };*/ return dto.ToT(_mapper, create); } public static DataSourceDto ToDto(this DataSource model) { Func create = dataSource => new DataSourceDto { Id = dataSource.Id, Type = dataSource.Type, Model = dataSource.Model, Precision = dataSource.Precision, }; Action link = (dataSource, dto) => { dto.Activities = dataSource.Activities.ToDtos().ToArray(); dto.Athletes = dataSource.Athletes.ToDtos().ToArray(); }; return model.ToU(_mapper, create, link); } public static IEnumerable ToModels(this IEnumerable dtos) => dtos.Select(d => d.ToModel()); public static IEnumerable ToDtos(this IEnumerable models) => models.Select(m => m.ToDto()); }