public static Transaction ToEntity(this TransactionModel model) { var transaction = new Transaction( CurrencyType.FromValue(model.Currency).ToCurrency(model.Amount), new TransactionDescription(model.Description), TransactionType.FromValue(model.Type), new DateTimeProvider(model.Timestamp), new TransactionMetadata(model.Metadata.ToDictionary(metadata => metadata.Key, metadata => metadata.Value))); transaction.SetEntityId(model.Id); var status = TransactionStatus.FromValue(model.Status); if (status == TransactionStatus.Succeeded) { transaction.MarkAsSucceeded(); } if (status == TransactionStatus.Failed) { transaction.MarkAsFailed(); } transaction.ClearDomainEvents(); return(transaction); }
public static IChallenge ToEntity(this ChallengeModel model) { var entryFee = new EntryFee(model.EntryFeeAmount, CurrencyType.FromValue(model.EntryFeeCurrency)); var payout = new ChallengePayout(entryFee, new ChallengePayoutBuckets(model.PayoutBuckets.Select(bucket => bucket.ToEntity()))); var challenge = new Challenge(ChallengeId.FromGuid(model.Id), payout); challenge.ClearDomainEvents(); return(challenge); }
public static Promotion ToEntity(this PromotionModel model) { var promotion = new Promotion( model.PromotionalCode, CurrencyType.FromValue(model.Currency).ToCurrency(model.Amount), TimeSpan.FromTicks(model.Duration), new DateTimeProvider(model.ExpiredAt)); promotion.SetEntityId(model.Id); foreach (var recipient in model.Recipients) { promotion.Redeem(recipient.ToEntity()); } if (model.CanceledAt.HasValue) { promotion.Cancel(new DateTimeProvider(model.CanceledAt.Value)); } promotion.ClearDomainEvents(); return(promotion); }
protected override async Task SeedProductionAsync() { await this.SeedAdministratorAccountAsync(); var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !; var file = File.OpenRead(Path.Combine(assemblyPath, "Setup/Challenges.Production.csv")); using var csvReader = file.OpenCsvReader(); Challenges.AddRange( csvReader.GetRecords( new { Id = default(Guid), EntryFeeCurrency = default(int), EntryFeeAmount = default(decimal), Entries = default(int) }) .Select( record => { var payoutStrategy = new ChallengePayoutFactory().CreateInstance(); var payoutEntries = new ChallengePayoutEntries(record.Entries / 2); var currency = CurrencyType.FromValue(record.EntryFeeCurrency) !; var entryFee = new EntryFee(record.EntryFeeAmount, currency); var payout = payoutStrategy.GetChallengePayout(payoutEntries, entryFee); return(new Challenge(record.Id.ConvertTo <ChallengeId>(), payout)); }) .Where(challenge => Challenges.All(x => x.Id != challenge.Id)) .Select(challenge => challenge.ToModel())); await this.CommitAsync(); var startedAt = DateTimeOffset.FromUnixTimeMilliseconds(1582261200000).UtcDateTime; var duration = TimeSpan.FromDays(4); var promotion1 = new Promotion( "DHANA20REDCUP", new Money(5), duration, new DateTimeProvider(startedAt + duration)); promotion1.SetEntityId(PromotionId.Parse("885cdd1e-0ed9-4fdc-9c29-d48a9d071cfd")); var promotion2 = new Promotion( "DHANA20TOK", new Token(250), duration, new DateTimeProvider(startedAt + duration)); promotion2.SetEntityId(PromotionId.Parse("263aa2ed-3f88-4070-96e6-a098814e44f3")); var promotions = new List <Promotion> { promotion1, promotion2 }; Promotions.AddRange(promotions.Where(promotion => Promotions.All(x => x.Id != promotion.Id)).Select(promotion => promotion.ToModel())); await this.CommitAsync(); }
public static ChallengePayoutBucket ToEntity(this ChallengePayoutBucketModel model) { return(new ChallengePayoutBucket(new ChallengePayoutBucketPrize(model.PrizeAmount, CurrencyType.FromValue(model.PrizeCurrency)), new ChallengePayoutBucketSize(model.Size))); }