Exemple #1
0
        public async Task <bool> CreateAccountAsync(Services.Models.Customer customerModel)
        {
            try
            {
                Entities.Customer newCustomer = _mapper.Map <Entities.Customer>(customerModel);
                newCustomer.Id     = Guid.NewGuid();
                newCustomer.Active = false;
                _accountContext.Customers.Add(newCustomer);
                var account = new Entities.Account()
                {
                    Id         = Guid.NewGuid(),
                    CustomerId = newCustomer.Id,
                    Opendate   = DateTime.Today,
                    Balance    = 100000,
                };
                _accountContext.Accounts.Add(account);
                await _accountContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                throw new CreateAccountFailed($"Account creation for { customerModel.Email } failed");
            }
        }
        public async Task CreateOperation(Services.Models.Operation operation)
        {
            Entities.Operation newOperation = _mapper.Map <Entities.Operation>(operation);
            Entities.Account   account      = await _accountContext.Accounts.FirstOrDefaultAsync(a => a.Id == operation.AccountId);

            newOperation.Id            = Guid.NewGuid();
            newOperation.Balance       = account.Balance;
            newOperation.OperationTime = DateTime.Now;
            _accountContext.Operations.Add(newOperation);
            await _accountContext.SaveChangesAsync();
        }
        public async Task <bool> CreateAccountAsync(Services.Models.Customer customerModel)
        {
            Entities.Customer newCustomer = _mapper.Map <Entities.Customer>(customerModel);
            newCustomer.Id     = Guid.NewGuid();
            newCustomer.Active = false;
            _accountContext.Customers.Add(newCustomer);
            var account = new Entities.Account()
            {
                Id         = Guid.NewGuid(),
                CustomerId = newCustomer.Id,
                Opendate   = DateTime.Today,
                Balance    = 100000,
            };

            _accountContext.Accounts.Add(account);
            await _accountContext.SaveChangesAsync();

            return(true);
        }