Exemplo n.º 1
0
        public override Task <int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            var filtered =
                ChangeTracker
                .Entries <AuditableEntity>()
                .Where(e => e.Entity is AuditableEntity && (
                           e.State == EntityState.Added ||
                           e.State == EntityState.Modified) ||
                       e.State == EntityState.Deleted);

            foreach (var entry in filtered)
            {
                switch (entry.State)
                {
                case EntityState.Added:
                    entry.Entity.CreatedBy = user.Id;
                    entry.Entity.CreatedOn = dateTime.UtcNow();
                    break;

                case EntityState.Modified:
                    entry.Entity.LastModifiedBy = user.Id;
                    entry.Entity.ModifiedOn     = dateTime.UtcNow();
                    break;

                case EntityState.Deleted:
                    entry.Entity.DeleteBy  = user.Id;
                    entry.Entity.DeletedOn = dateTime.UtcNow();
                    entry.Entity.IsDeleted = true;
                    break;
                }
            }

            return(base.SaveChangesAsync(cancellationToken));
        }
        public void InvalidateToken()
        {
            if (string.IsNullOrEmpty(IdempotencyKey))
            {
                return;
            }

            _cache.Set(IdempotencyKey, _dateTime.UtcNow().ToString("o"), _dateTime.UtcNow().AddHours(IdempotencyKeyExpiryTimeInHours));
        }
Exemplo n.º 3
0
        public static void SeedAsync(IApplicationDbContext dbContext, IDateTime dateTimeService)
        {
            var defaultTransactionCategories = new List <TransactionCategory>
            {
                new TransactionCategory
                {
                    Created = dateTimeService.UtcNow(),
                    Name    = "Charges",
                    Display = true
                },
                new TransactionCategory
                {
                    Created = dateTimeService.UtcNow(),
                    Name    = "Insurance",
                    Display = true
                },
                new TransactionCategory
                {
                    Created = dateTimeService.UtcNow(),
                    Name    = "Investment",
                    Display = true
                },
                new TransactionCategory
                {
                    Created = dateTimeService.UtcNow(),
                    Name    = "Wage",
                    Display = true
                },
                new TransactionCategory
                {
                    Created = dateTimeService.UtcNow(),
                    Name    = "Withdraw",
                    Display = true
                }
            };
            var defaultTransactionCategoryNames = defaultTransactionCategories.Select(tc => tc.Name).ToList();
            var existingTransactionCategories   = dbContext.TransactionCategories.Where(tc => defaultTransactionCategoryNames.Contains(tc.Name));
            var shouldSave = false;

            defaultTransactionCategories.ForEach(d =>
            {
                if (existingTransactionCategories.Any(e => e.Name == d.Name))
                {
                    return;
                }

                dbContext.TransactionCategories.Add(d);
                shouldSave = true;
            });
            if (shouldSave)
            {
                dbContext.SaveChanges();
            }
        }
        public Task <ProcessRejectedPaymentResponse> Handle(ProcessRejectedPaymentRequest request, CancellationToken cancellationToken = default)
        {
            var merchantKey = _merchantEncryptionKeyGetter.Key(request.Merchant.Id);

            var paymentRecord = new PaymentRecord
            {
                Id     = _guid.NewGuid().ToString(),
                Source = new PaymentRecord.PaymentSource
                {
                    CardExpiryEncrypted = _encrypter.EncryptUtf8(request.Source.CardExpiry, merchantKey),
                    CardNumberEncrypted = _encrypter.EncryptUtf8(request.Source.CardNumber, merchantKey),
                    CvvEncrypted        = _encrypter.EncryptUtf8(request.Source.Cvv, merchantKey)
                },
                Recipient = new PaymentRecord.PaymentRecipient
                {
                    AccountNumberEncrypted = _encrypter.EncryptUtf8(request.Recipient.AccountNumber, merchantKey),
                    SortCodeEncrypted      = _encrypter.EncryptUtf8(request.Recipient.SortCode, merchantKey),
                },
                Currency      = request.Currency,
                Status        = PaymentStatus.Rejected,
                Amount        = request.Amount,
                CreatedAt     = _dateTime.UtcNow(),
                MerchantId    = request.Merchant.Id,
                FailureReason = request.BankResponse.FailureReason,
            };

            _paymentRecordCreator.Add(paymentRecord);

            return(Task.FromResult(new ProcessRejectedPaymentResponse
            {
                Id = paymentRecord.Id
            }));
        }
Exemplo n.º 5
0
        public override int SaveChanges()
        {
            foreach (var entry in ChangeTracker.Entries <AuditableEntity>())
            {
                switch (entry.State)
                {
                case EntityState.Added:
                    entry.Entity.Created   = _dateTimeService.UtcNow();
                    entry.Entity.CreatedBy = _currentUserService.UserId;
                    break;

                case EntityState.Modified:
                    entry.Entity.LastModified   = _dateTimeService.UtcNow();
                    entry.Entity.LastModifiedBy = _currentUserService.UserId;
                    break;
                }
            }
            return(base.SaveChanges());
        }
        public bool IsExpired(string input)
        {
            if (!IsValid(input))
            {
                throw new ArgumentException(nameof(input));
            }

            return(DateTime.TryParseExact(input,
                                          CardExpiryFormat,
                                          CultureInfo.InvariantCulture,
                                          DateTimeStyles.None,
                                          out var parsed) && _dateTime.UtcNow() > ActualCardExpiry(parsed));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Retrieves the next event from the activity queue and applies it to the appropriate profile
        /// </summary>
        public void ProcessActivityQueueItem()
        {
            var act     = new Act();
            var profile = new Profile();

            // get a list of achievements that have this act as a prerequisite
            var achievementsToCheck = _achievements.Where(a => a.Prerequisites.Any(p => p.ActivityId == act.ActivityId));

            foreach (var achievement in achievementsToCheck)
            {
                // check if achievement's limits have already been exceeded
                foreach (var limit in achievement.Limits)
                {
                    if (limit.LimitExceeded(null)) // TODO: fix limit so it gets activity stream here
                    {
                        continue;
                    }
                }

                // check if prerequisites have been fulfilled within time limit
                bool triggerAchievement = true;
                foreach (var prerequisite in achievement.Prerequisites)
                {
                    int countInWindow = profile.History.Count(a => (a.ActivityId == prerequisite.ActivityId) &&
                                                              (a.OccurredOnUtc >= _dateTime.UtcNow() - prerequisite.ActivityWindow));
                    if (countInWindow < prerequisite.NumberRequired)
                    {
                        triggerAchievement = false;
                    }
                }
                if (triggerAchievement)
                {
                    // raise Achievement Unlocked Event
                }
            }
        }
Exemplo n.º 8
0
 public bool IsOpen() => _openHours.IsOpen(_dateTime.UtcNow());