Ejemplo n.º 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");
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> IsEmailExistsAsync(string email)
        {
            Entities.Customer customer = await _accountContext.Customers.FirstOrDefaultAsync(
                c => c.Email == email);

            if (customer == null)
            {
                return(false);
            }
            return(true);
        }
        public async Task <Services.Models.Customer> GetCustomerAsync(string email)
        {
            Entities.Customer customer = await _accountContext.Customers
                                         .FirstOrDefaultAsync(c => c.Email == email);

            if (customer == null)
            {
                throw new AccountNotFoundException("Your email is not exist");
            }
            return(_mapper.Map <Services.Models.Customer>(customer));
        }
        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);
        }