Example #1
0
        public async Task CollectFeeAsync(Account account, decimal fee)
        {
            using (var dbContextTransaction = _dataDbContext.Database.BeginTransaction())
            {
                var entity = _dataDbContext.Accounts.Single(x => string.Equals(x.IBAN, account.AccountName));

                entity.Balance   = account.Balance;
                entity.UpdatedAt = SystemDateTime.UtcNow();

                var transaction = new TransactionEntity
                {
                    FromId    = entity.Id,
                    Amount    = fee,
                    CreateAt  = entity.UpdatedAt,
                    Type      = TransactionType.Withdraw,
                    Status    = OperationStatus.Ok,
                    AccountTo = "SYSTEM"
                };

                _dataDbContext.Transactions.Add(transaction);
                await _dataDbContext.SaveChangesAsync();

                dbContextTransaction.Commit();
            }
        }
Example #2
0
        public async Task UpdateTransactionAsync(Account account, AccountTransaction accountTransaction)
        {
            using (var dbContextTransaction = _dataDbContext.Database.BeginTransaction())
            {
                var entity   = _dataDbContext.Accounts.Single(x => string.Equals(x.IBAN, account.AccountName));
                var entityTo =
                    _dataDbContext.Accounts.SingleOrDefault(x => string.Equals(x.IBAN, accountTransaction.AccountName));

                entity.Balance   = account.Balance;
                entity.UpdatedAt = SystemDateTime.UtcNow();

                var transaction = new TransactionEntity
                {
                    FromId    = entity.Id,
                    Amount    = accountTransaction.Amount,
                    CreateAt  = entity.UpdatedAt,
                    Type      = accountTransaction.Type,
                    Status    = OperationStatus.Ok,
                    AccountTo = accountTransaction.AccountName
                };

                if (entityTo == null)
                {
                    transaction.Status = OperationStatus.AccountNotFound;
                }

                _dataDbContext.Transactions.Add(transaction);
                await _dataDbContext.SaveChangesAsync();

                dbContextTransaction.Commit();
            }
        }
Example #3
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <AccountEntity>()
            .HasMany(b => b.Transactions)
            .WithOne(e => e.From);

            modelBuilder.Entity <AccountEntity>()
            .HasData(
                new AccountEntity
            {
                Id        = new Guid("E74EA75C-EF51-40E1-BD83-086805F32060"),
                Balance   = 0,
                IBAN      = "MOCKACCOUNT1",
                OwenerId  = "SYSTEM",
                CreatedAt = SystemDateTime.UtcNow()
            },
                new AccountEntity
            {
                Id        = new Guid("5ccc827f-63e3-4bcc-9826-487088444106"),
                Balance   = 0,
                IBAN      = "MOCKACCOUNT2",
                OwenerId  = "SYSTEM",
                CreatedAt = SystemDateTime.UtcNow()
            }
                );

            modelBuilder.Entity <TransactionEntity>()
            .HasOne(b => b.From)
            .WithMany(x => x.Transactions)
            .HasForeignKey(x => x.FromId);

            //modelBuilder.ApplyConfiguration(new ManufacturerConfiguration());
            //modelBuilder.ApplyConfiguration(new VehicleModelConfiguration());
        }
        public void Enroll(Student student)
        {
            var enrollment = new Enrollment
            {
                Student = student,
                Course  = _course,
                Created = SystemDateTime.UtcNow(),
            };

            _enrollments.Add(enrollment);
        }
        public HttpResponseMessage Get([FromUri] StreamFilter filter)
        {
            var response = this.Request.CreateResponse(HttpStatusCode.NotFound);

            if (!string.IsNullOrEmpty(filter.Id))
            {
                var item = this.streamStorage.Get(filter.Id);
                if (item != null)
                {
                    response = this.Request.CreateResponse(HttpStatusCode.OK, item);
                }
            }
            else if (!string.IsNullOrEmpty(filter.Max_Id))
            {
                var item = this.streamStorage.Get(filter.Max_Id);
                if (item != null)
                {
                    var stream = this.streamStorage.GetOlder(item, filter.Limit);
                    response = this.Request.CreateResponse(HttpStatusCode.OK, stream);
                }
            }
            else if (!string.IsNullOrEmpty(filter.Min_Id))
            {
                var item = this.streamStorage.Get(filter.Min_Id);
                if (item != null)
                {
                    var stream = this.streamStorage.GetNewer(item, filter.Limit);
                    response = this.Request.CreateResponse(HttpStatusCode.OK, stream);
                }
            }
            else if (filter.Type.HasValue || filter.From != SystemDateTime.UtcNow().AddDays(-StreamFilter.PastDays).Date || filter.To.HasValue)
            {
                // this is temp branch for backwards compatibility, will be removed
                var stream = this.streamStorage.GetLatest(filter.Type, filter.From, filter.To, filter.Limit);
                response = this.Request.CreateResponse(HttpStatusCode.OK, stream);
            }
            else
            {
                var stream = this.streamStorage.GetLatest(filter.Limit);
                response = this.Request.CreateResponse(HttpStatusCode.OK, stream);
            }

            return(response);
        }
        public void Enroll(Student student)
        {
            var enrollment = new Enrollment(student, _course, SystemDateTime.UtcNow());

            _enrollments.Add(enrollment);
        }