Esempio n. 1
0
        public async Task SendMessage(MessageDto message)
        {
            var entity = _mapper.MapTo <Domain.Message>(message);

            entity.CreateDate = DateTime.UtcNow;

            await _messageRepository.InsertAsync(entity);
        }
Esempio n. 2
0
        public async Task <IEnumerable <ListingValuation> > GetValuations(DateTime day)
        {
            var entities = await context.Valuations
                           .AsNoTracking()
                           .Where(v => v.Day == day)
                           .ToListAsync();

            return(mapper.MapTo <ListingValuation>(entities));
        }
Esempio n. 3
0
        public virtual async Task <TEntityDto> AddAsync(Func <Task <TAggregateRoot> > when, TPrimaryKey identifier = default)
        {
            var aggregate = await when();

            var insertedAggregate = await AggregateRootRepository.InsertAsync(aggregate, identifier);

            await this.UnitOfWorkAsync.SaveChangesAsync();

            return(ObjectMapper.MapTo <TEntityDto>(
                       insertedAggregate
                       ));
        }
Esempio n. 4
0
        public async Task BlockUser(UserBlockDto model)
        {
            var entity = _mapper.MapTo <UserBlock>(model);

            entity.CreateDate = DateTime.UtcNow;

            await _userBlockRepository.InsertAsync(entity);
        }
Esempio n. 5
0
        public async Task <IEnumerable <Tuple <Listing, DateTime?> > > GetActiveListingWithLastPriceFetchDay()
        {
            var eodPrices = await context.EndOfDayPrices
                            .AsNoTracking()
                            .Where(eodPrice => eodPrice.Day == context.EndOfDayPrices.Where(al => al.Listing.Id == eodPrice.Listing.Id).Max(al => al.Day))
                            .Include(eod => eod.Listing.Currency)
                            .ToListAsync();

            var activeListingVolumeEntities = await GetActiveListingVolumes();

            var p = activeListingVolumeEntities.GroupJoin(eodPrices, lv => lv.Listing.Id, eod => eod.Listing.Id, (lv, eod) => new { ListingVolume = lv, EndOfDayPrice = eod })
                    .SelectMany(x => x.EndOfDayPrice.DefaultIfEmpty(), (x, y) => new { ListingVolume = x.ListingVolume, eodPrice = x.EndOfDayPrice })
                    .ToList();

            var listingsWithDate = p
                                   .Where(x => x.ListingVolume.Quantity > 0)
                                   .Select(x => Tuple.Create(mapper.MapTo <Listing>(x.ListingVolume.Listing), x.eodPrice?.FirstOrDefault()?.Day))
                                   .ToList();

            return(listingsWithDate);
        }
Esempio n. 6
0
        public async Task <IEnumerable <(Currency, DateTime?)> > GetCurrenciesWithLastDownloadedDate()
        {
            var currenciesEntities = await context.Currencies.Where(c => c.Symbol != "GBP").ToListAsync();

            var currencies    = mapper.MapTo <Currency>(currenciesEntities);
            var currencyRates = await context.CurrencyRates.GroupBy(cr => cr.From)
                                .Select(x => new { From = x.Key, Day = (DateTime?)x.Max(p => p.Day) })
                                .ToListAsync();

            var currencyWithDate = currencies.GroupJoin(currencyRates, c => c.Symbol, cr => cr.From, (c, cr) => (c, cr?.First()?.Day))
                                   .ToList();

            return(currencyWithDate);
        }
        public async Task Save(IEnumerable <EndOfDayPrice> endOfDayPrices)
        {
            foreach (var eodPrice in endOfDayPrices)
            {
                var e = context.EndOfDayPrices.Where(eod => eod.Listing.Id == eodPrice.ListingId && eod.Day == eodPrice.Day).ToList();
                context.EndOfDayPrices.RemoveRange(e);
            }

            var entities = endOfDayPrices
                           .Select(endOfDayPrice => mapper.MapTo <EndOfDayPriceEntity>(endOfDayPrice))
                           .ToList();

            context.EndOfDayPrices.AddRange(entities);
            await context.SaveChangesAsync();
        }
Esempio n. 8
0
        public static X To <O, X>(O from, X defaultVal = default, CastingContext context = null, IObjectMapper mapper = null)
        {
            var oType             = typeof(O);
            var xType             = typeof(X);
            var oTypeNullableFlag = TypeJudgment.IsNullableType(oType);
            var xTypeNullableFlag = TypeJudgment.IsNullableType(xType);

            context ??= CastingContext.DefaultContext;

            if (xType.IsValueType && defaultVal is null)
            {
                defaultVal = Activator.CreateInstance <X>();
            }

            if (from is null)
            {
                return(defaultVal);
            }

            if (oType == xType)
            {
                return(from.AsOrDefault(defaultVal));
            }

            if (from is string strFrom)
            {
                return(FromStringTo(strFrom, xType, xTypeNullableFlag, defaultVal));
            }

            if (from is DateTime dtFrom)
            {
                return(FromDateTimeTo(dtFrom, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (from is bool boolFrom)
            {
                return(FromBooleanTo(boolFrom, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (TypeHelper.IsEnumType(oType))
            {
                return(FromEnumTo(oType, from, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (TypeHelper.IsNullableNumericType(oType) || TypeHelper.IsNumericType(oType))
            {
                return(FromNumericTo(oType, oTypeNullableFlag, from, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (from is Guid guid)
            {
                return(FromGuidTo(guid, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (TypeHelper.IsNullableGuidType(oType))
            {
                return(FromNullableGuidTo(from.As <Guid?>(), context, xType, xTypeNullableFlag, defaultVal));
            }

            if (from is IConvertible)
            {
                return(Convert.ChangeType(from, xType).As <X>());
            }

            if (oType == TypeClass.ObjectClass)
            {
                return(FromObjTo(from, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (xType == TypeClass.ObjectClass)
            {
                return(from.As <X>());
            }

            if (xType.IsAssignableFrom(oType))
            {
                return(from.As <X>());
            }

            if (mapper != null)
            {
                return(mapper.MapTo <O, X>(from));
            }

            try
            {
                return(from.As <X>());
            }
            catch
            {
                try
                {
                    return(Mapper.DefaultMapper.Instance.MapTo <O, X>(from));
                }
                catch
                {
                    return(xTypeNullableFlag ? default : defaultVal);
                }
            }
        }
Esempio n. 9
0
        public static object To(object from, Type sourceType, Type targetType,
                                object defaultVal = default, CastingContext context = null, IObjectMapper mapper = null)
        {
            var oType             = sourceType;
            var xType             = targetType;
            var oTypeNullableFlag = Types.IsNullableType(oType);
            var xTypeNullableFlag = Types.IsNullableType(xType);

            context ??= CastingContext.DefaultContext;

            if (xType.IsValueType && defaultVal is null)
            {
                defaultVal = Activator.CreateInstance(xType);
            }

            if (from is null)
            {
                return(defaultVal);
            }

            if (oType == xType)
            {
                return(from.AsOrDefault(defaultVal));
            }

            if (from is string strFrom)
            {
                return(FromStringTo(strFrom, xType, xTypeNullableFlag, defaultVal));
            }

            if (from is DateTime dtFrom)
            {
                return(FromDateTimeTo(dtFrom, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (from is bool boolFrom)
            {
                return(FromBooleanTo(boolFrom, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (TypeDeterminer.IsEnumType(oType))
            {
                return(FromEnumTo(oType, from, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (TypeDeterminer.IsNullableNumericType(oType) || Types.IsNumericType(oType))
            {
                return(FromNumericTo(oType, oTypeNullableFlag, from, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (from is Guid guid)
            {
                return(FromGuidTo(guid, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (TypeDeterminer.IsNullableGuidType(oType))
            {
                return(FromNullableGuidTo(from.As <Guid?>(), context, xType, xTypeNullableFlag, defaultVal));
            }

            if (from is IConvertible)
            {
                return(Convert.ChangeType(from, xType));
            }

            if (oType == TypeClass.ObjectClazz)
            {
                return(FromObjTo(from, oType, context, xType, xTypeNullableFlag, defaultVal));
            }

            if (xType == TypeClass.ObjectClazz)
            {
                return(Convert.ChangeType(from, xType));
            }

            if (xType.IsAssignableFrom(oType))
            {
                return(from);
            }

            if (mapper != null)
            {
                return(mapper.MapTo(oType, xType, from));
            }

            try
            {
                return(Convert.ChangeType(from, xType, context.FormatProvider).AsOrDefault(defaultVal));
            }
            catch
            {
                try
                {
                    return(DefaultMapper.Instance.MapTo(oType, xType, from));
                }
                catch
                {
                    return(xTypeNullableFlag ? default : defaultVal);
                }
            }
        }
Esempio n. 10
0
        public async Task <Provider> GetEmailProvider(string name)
        {
            var entity = await context.Providers.FirstOrDefaultAsync(p => p.ServiceName == name);

            return(mapper.MapTo <Provider>(entity));
        }
Esempio n. 11
0
 public static TDestination MapTo <TDestination>(this object source) => ObjectMapper.MapTo <TDestination>(source);
Esempio n. 12
0
        public async Task <List <ProductDto> > GetAll()
        {
            List <Product> products = await _repository.GetAll();

            return(_mapper.MapTo <List <ProductDto> >(products));
        }