示例#1
0
        /// <summary>
        /// Se agrega una nueva cuenta a un cliente
        /// </summary>
        /// <param name="pIdCliente"></param>
        /// <param name="pName"></param>
        /// <param name="pOverdraftLimit"></param>
        public bool NewAccount(int pClientId, String pName, int pOverdraftLimit)
        {
            bool agregado = false;

            using (var bDbContext = new AccountManagerDbContext())
            {
                using (IUnitOfWork bUoW = new UnitOfWork(bDbContext))
                {
                    var bClient = bUoW.ClientRepository.Get(pClientId);
                    if (bClient != null)
                    {
                        Account bAccount = new Account
                        {
                            Name           = pName,
                            OverdraftLimit = pOverdraftLimit
                        };
                        bClient.Accounts.Add(bAccount);
                        bDbContext.Accounts.Add(bAccount);
                        bDbContext.SaveChanges();
                        agregado = true;
                    }
                }
            }
            return(agregado);
        }
示例#2
0
        /// <summary>
        /// retorna una lista de los movimientos de una cuenta
        /// </summary>
        /// <param name="pAccountId"></param>
        /// <returns></returns>
        public IEnumerable <IO.AccountMovementDTO> GetAccountMovements(int pAccountId)
        {
            IList <IO.AccountMovementDTO> accountMovementsDTO;

            using (var bDbContext = new AccountManagerDbContext())
            {
                using (IUnitOfWork bUoW = new UnitOfWork(bDbContext))
                {
                    var bAccount = bUoW.AccountRepository.Get(pAccountId);

                    if (bAccount != null && bAccount.Movements.Count > 0)
                    {
                        accountMovementsDTO = new List <IO.AccountMovementDTO>(bAccount.Movements.Count);
                        foreach (var bMovements in bAccount.Movements)
                        {
                            accountMovementsDTO.Add(new IO.AccountMovementDTO
                            {
                                Id          = bMovements.Id,
                                Date        = bMovements.Date,
                                Description = bMovements.Description,
                                Amount      = bMovements.Amount
                            });
                        }
                    }
                    else
                    {
                        accountMovementsDTO = new List <IO.AccountMovementDTO>();
                    }
                }
            }
            return(accountMovementsDTO);
        }
示例#3
0
        //Metodos
        /// <summary>
        /// Retorna una lista de cuentas de un cliente
        /// </summary>
        /// <param name="pClientId"></param>
        /// <returns></returns>
        public IEnumerable <IO.AccountDTO> GetClientAccounts(int pClientId)
        {
            IList <IO.AccountDTO> accountsDTO;

            using (var bDbContext = new AccountManagerDbContext())
            {
                using (IUnitOfWork bUoW = new UnitOfWork(bDbContext))
                {
                    var bClient = bUoW.ClientRepository.Get(pClientId);

                    if (bClient != null && bClient.Accounts.Count > 0)
                    {
                        accountsDTO = new List <IO.AccountDTO>(bClient.Accounts.Count);
                        foreach (var bAccount in bClient.Accounts)
                        {
                            accountsDTO.Add(new IO.AccountDTO
                            {
                                Id             = bAccount.Id,
                                Name           = bAccount.Name,
                                OverDraftLimit = bAccount.OverdraftLimit,
                                Balance        = bAccount.GetBalance()
                            });
                        }
                    }
                    else
                    {
                        accountsDTO = new List <IO.AccountDTO>();
                    }
                }
            }
            return(accountsDTO);
        }
示例#4
0
        public async Task GetAllByUserIdAsync_Returns_Accounts()
        {
            // Arrange
            var userId   = 1;
            var account1 = new AccountDbo
            {
                AccountId   = 1,
                UserId      = userId,
                AccountType = AccountType.Credit,
                DateCreated = DateTime.UtcNow
            };
            var account2 = new AccountDbo
            {
                AccountId   = 2,
                UserId      = userId,
                AccountType = AccountType.Debit,
                DateCreated = DateTime.UtcNow.AddDays(-1)
            };
            var accountDbos = new List <AccountDbo>
            {
                account1,
                account2
            };

            using var dbContext = new AccountManagerDbContext(_options);
            dbContext.Accounts.AddRange(accountDbos);

            var expectedAccounts = new List <Account>
            {
                new Account
                {
                    AccountId   = account1.AccountId,
                    UserId      = userId,
                    AccountType = account1.AccountType,
                    DateCreated = account1.DateCreated
                },
                new Account
                {
                    AccountId   = account2.AccountId,
                    UserId      = userId,
                    AccountType = account2.AccountType,
                    DateCreated = account2.DateCreated
                },
            };

            _mockMapper.Setup(
                m => m.Map <IEnumerable <Account> >(
                    It.Is <List <AccountDbo> >(accounts => accounts.All(a => accountDbos.Contains(a)))))
            .Returns(expectedAccounts);

            var service = new AccountService(_mockMapper.Object, dbContext);

            // Act
            var actualAccounts = await service.GetAllByUserIdAsync(correlationId : Guid.NewGuid(), userId);

            // Assert
            Assert.NotNull(actualAccounts);
            Assert.NotEmpty(actualAccounts);
            Assert.True(actualAccounts.All(a => expectedAccounts.Contains(a)));
        }
示例#5
0
        public AccountTypeData()
        {
            var factory = new AccountManagerDesignTimeFactory();

            context = factory.CreateDbContext(new string[] { });
            context.Database.Migrate();
        }
示例#6
0
        public void CrearCuenta(Client pClient, String pName, double pOverdraftLimit)
        {
            using (var dbContext = new AccountManagerDbContext())
            {
                using (var uof = new UnitOfWork(dbContext))
                {
                    var cuenta = new Account
                    {
                        Client         = pClient,
                        Name           = pName,
                        OverdraftLimit = pOverdraftLimit
                    };

                    try
                    {
                        uof.AccountRepository.Add(cuenta);
                        uof.Complete();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }
示例#7
0
        public void CrearCliente(String pNumDocument, DocumentType pType, String pFirstName, String pLastName)
        {
            using (var dbContext = new AccountManagerDbContext())
            {
                using (var uof = new UnitOfWork(dbContext))
                {
                    var documento = new Document
                    {
                        Number = pNumDocument,
                        Type   = pType
                    };

                    var cliente = new Client
                    {
                        FirstName = pFirstName,
                        LastName  = pLastName,
                        Document  = documento
                    };

                    try
                    {
                        uof.ClientRepository.Add(cliente);
                        uof.Complete();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }
示例#8
0
        /// <summary>
        /// Se agrega un nuevo movimiento de una cuenta
        /// </summary>
        /// <param name="pAccountId"></param>
        /// <param name="pDescription"></param>
        /// <param name="pAmount"></param>
        public bool NewAccountMovement(int pAccountId, String pDescription, double pAmount, DateTime pDate)
        {
            bool agregado = false;

            using (var bDbContext = new AccountManagerDbContext())
            {
                using (IUnitOfWork bUoW = new UnitOfWork(bDbContext))
                {
                    var bAccount = bUoW.AccountRepository.Get(pAccountId);
                    if (bAccount != null)
                    {
                        AccountMovement pAccountM = new AccountMovement
                        {
                            Date        = pDate,
                            Description = pDescription,
                            Amount      = pAmount
                        };

                        bAccount.Movements.Add(pAccountM);
                        bDbContext.AccountMovements.Add(pAccountM);
                        bDbContext.SaveChanges();
                        agregado = true;
                    }
                }
            }
            return(agregado);
        }
示例#9
0
        /// <summary>
        /// Retorna una lista de cuentas con saldo negativo
        /// </summary>
        /// <returns></returns>
        public IEnumerable <IO.AccountDTO> GetAccountsNegativeAMount()
        {
            IList <IO.AccountDTO> bAccountsDTO = new List <IO.AccountDTO>();

            using (var bDbContext = new AccountManagerDbContext())
            {
                using (IUnitOfWork bUoW = new UnitOfWork(bDbContext))
                {
                    var bAccounts = bUoW.AccountRepository.GetAll();
                    foreach (Account bAccount in bAccounts)
                    {
                        if (bAccount != null)
                        {
                            if (bAccount.GetBalance() > Convert.ToDouble(bAccount.OverdraftLimit))
                            {
                                bAccountsDTO.Add(new IO.AccountDTO
                                {
                                    Id             = bAccount.Id,
                                    Name           = bAccount.Name,
                                    OverDraftLimit = bAccount.OverdraftLimit,
                                    Balance        = bAccount.GetBalance()
                                });
                            }
                        }
                    }
                }
            }
            return(bAccountsDTO);
        }
示例#10
0
        //Muestra en una dataGridView las cuentas con deuda
        private void bAccountsDebt_Click(object sender, EventArgs e)
        {
            AccountManagerDbContext context = new AccountManagerDbContext();

            try
            {
                IEnumerable <AccountDTO> AccDebt = iBank.GetAccountsWithDebt(context);

                dgvAccountsDebt.DataSource = AccDebt;
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error al buscar cuentas con deuda.", exc.Message);
            }
        }
示例#11
0
        //Agrega un movimiento a la cuenta
        private void bAddMov_Click(object sender, EventArgs e)
        {
            Bank iBank = new Bank();

            AccountManagerDbContext context = new AccountManagerDbContext();

            try
            {
                iBank.AddMovement(Int32.Parse(l_IdAccount.Text), tbDescription.Text, Int32.Parse(tbAmount.Text));
            }
            catch (Exception exc)
            {
                MessageBox.Show("Verifique que ingreso correctamente los datos.", exc.Message);
            }
        }
示例#12
0
        //Agrega una cuenta.
        private void bAddAccount_Click(object sender, EventArgs e)
        {
            Bank iBank = new Bank();
            AccountManagerDbContext context = new AccountManagerDbContext();

            try
            {
                iBank.AddAccount(Int32.Parse(l_Id.Text), tbName.Text, Int32.Parse(tbOverdraftLimit.Text));

                ActualizarComboBox();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Verifique que ingreso correctamente los datos.", exc.Message);
            }
        }
示例#13
0
 public Account ObtenerCuenta(int pId)
 {
     using (var dbContext = new AccountManagerDbContext())
     {
         using (var uof = new UnitOfWork(dbContext))
         {
             try
             {
                 return(uof.AccountRepository.Get(pId));
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
 }
示例#14
0
 public List <Client> ObtenerClientes()
 {
     using (var dbContext = new AccountManagerDbContext())
     {
         using (var uof = new UnitOfWork(dbContext))
         {
             try
             {
                 return(uof.ClientRepository.GetAll().ToList());
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
 }
示例#15
0
 public List <Account> ObtenerCuentasSobregiradas()
 {
     using (var dbContext = new AccountManagerDbContext())
     {
         using (var uof = new UnitOfWork(dbContext))
         {
             try
             {
                 return(uof.AccountRepository.GetOverdrawnAccounts().ToList());
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
 }
示例#16
0
 public double ObtenerBalance(Account pAccount)
 {
     using (var dbContext = new AccountManagerDbContext())
     {
         using (var uof = new UnitOfWork(dbContext))
         {
             try
             {
                 return(uof.AccountRepository.GetAccountBalance(pAccount));
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
 }
示例#17
0
 public void EliminarCuenta(Account pAccount)
 {
     using (var dbContext = new AccountManagerDbContext())
     {
         using (var uof = new UnitOfWork(dbContext))
         {
             try
             {
                 uof.AccountRepository.Remove(pAccount);
                 uof.Complete();
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
 }
示例#18
0
        //Agrega un cliente nuevo
        private void bAddClient_Click(object sender, EventArgs e)
        {
            AccountManagerDbContext context = new AccountManagerDbContext();

            try
            {
                iBank.AddClient(context, tbDocNum.Text, cbDocType.Text,
                                tbFName.Text, tbLName.Text);

                int aux = iBank.SearchIdClientByNumDoc(context, tbDocNum.Text);

                tbIdForSearch.Text = aux.ToString();        //Muestra en el campo de id cual es la id asignada al nuevo cliente
            }
            catch (Exception exc)
            {
                MessageBox.Show("Verifique que ingreso correctamente los datos.", exc.Message);
            }
        }
示例#19
0
        public async Task AddAsync_Successful()
        {
            // Arrange
            var accountToAdd = new Account
            {
                AccountType = AccountType.Credit,
                DateCreated = DateTime.UtcNow,
                UserId      = 1,
            };
            var expectedAccountDbo = new AccountDbo
            {
                AccountType = accountToAdd.AccountType,
                DateCreated = accountToAdd.DateCreated,
                UserId      = accountToAdd.UserId,
            };

            _mockMapper.Setup(m => m.Map <AccountDbo>(It.IsAny <Account>()))
            .Returns(expectedAccountDbo);

            var expectedAccount = new Account
            {
                AccountId   = 1,
                AccountType = expectedAccountDbo.AccountType,
                DateCreated = expectedAccountDbo.DateCreated,
                UserId      = expectedAccountDbo.UserId,
            };

            _mockMapper.Setup(m => m.Map <Account>(It.IsAny <AccountDbo>()))
            .Returns(expectedAccount);

            using var dbContext = new AccountManagerDbContext(_options);
            var service = new AccountService(_mockMapper.Object, dbContext);

            // Act
            var correlationId = Guid.NewGuid();
            var actualAccount = await service.AddAsync(correlationId, accountToAdd);

            // Assert
            Assert.NotNull(actualAccount);
            Assert.Equal(expectedAccount.AccountId, actualAccount.AccountId);
            Assert.Equal(expectedAccount.AccountType, actualAccount.AccountType);
            Assert.Equal(expectedAccount.DateCreated, actualAccount.DateCreated);
            Assert.Equal(expectedAccount.UserId, actualAccount.UserId);
        }
示例#20
0
        public async Task GetAllByUserIdAsync_Returns_Empty_Collection()
        {
            // Arrange
            var accountDbos = new List <AccountDbo>
            {
                new AccountDbo
                {
                    AccountId   = 1,
                    UserId      = 1,
                    AccountType = AccountType.Credit,
                    DateCreated = DateTime.UtcNow
                },
                new AccountDbo
                {
                    AccountId   = 2,
                    UserId      = 2,
                    AccountType = AccountType.Debit,
                    DateCreated = DateTime.UtcNow
                },
            };

            using var dbContext = new AccountManagerDbContext(_options);
            dbContext.Accounts.AddRange(accountDbos);

            var expectedAccounts = new List <Account>();

            _mockMapper.Setup(
                m => m.Map <IEnumerable <Account> >(
                    It.Is <List <AccountDbo> >(accountDbos => !accountDbos.Any())))
            .Returns(expectedAccounts);

            var service = new AccountService(_mockMapper.Object, dbContext);

            // Act
            var nonExistentUserId = 3;
            var actualAccounts    = await service.GetAllByUserIdAsync(correlationId : Guid.NewGuid(), nonExistentUserId);

            // Assert
            Assert.NotNull(actualAccounts);
            Assert.Empty(actualAccounts);
        }
示例#21
0
        //Busca un cliente por num de documento
        private void bSearchClientNumDoc_Click(object sender, EventArgs e)
        {
            AccountManagerDbContext context = new AccountManagerDbContext();

            try
            {
                int idClient = iBank.SearchIdClientByNumDoc(context, textBox1.Text);
                //Si el metodo devuelve 0, es porque no se encontro.
                if (idClient == 0)
                {
                    MessageBox.Show("No se encontro el cliente");
                }
                else
                {
                    AdmClient ventana = new AdmClient(idClient);
                    ventana.Show();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Verifique que ingreso correctamente el Numero de Doc.", exc.Message);
            }
        }
示例#22
0
        public IEnumerable <AccountMovementDTO> GetAccountMovements(int pAccountId)
        {
            IList <AccountMovementDTO> mAccountMovements;

            using (var bDbContext = new AccountManagerDbContext())
            {
                using (IUnitOfWork bUoW = new UnitOfWork(bDbContext))
                {
                    var bAccount = bUoW.AccountRepository.Get(pAccountId);

                    if (bAccount != null && bAccount.Movements.Count > 0)
                    {
                        mAccountMovements = cMapper.Map <IList <AccountMovementDTO> >(bAccount.Movements);
                    }
                    else
                    {
                        mAccountMovements = new List <AccountMovementDTO>();
                    }
                }
            }

            return(mAccountMovements);
        }
示例#23
0
        public void ModificarCuenta(Account pAccount)
        {
            using (var dbContext = new AccountManagerDbContext())
            {
                using (var uof = new UnitOfWork(dbContext))
                {
                    try
                    {
                        var cuenta = uof.AccountRepository.Get(pAccount.Id);

                        cuenta.Client         = pAccount.Client;
                        cuenta.Name           = pAccount.Name;
                        cuenta.OverdraftLimit = pAccount.OverdraftLimit;
                        cuenta.Movements      = pAccount.Movements;

                        uof.Complete();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }
示例#24
0
        public void ModificarCliente(Client pClient)
        {
            using (var dbContext = new AccountManagerDbContext())
            {
                using (var uof = new UnitOfWork(dbContext))
                {
                    try
                    {
                        var cliente = uof.ClientRepository.Get(pClient.Id);

                        cliente.Accounts  = pClient.Accounts;
                        cliente.Document  = pClient.Document;
                        cliente.FirstName = pClient.FirstName;
                        cliente.LastName  = pClient.LastName;

                        uof.Complete();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }
示例#25
0
        public AccountTypeData()
        {
            var factory = new AccountManagerDesignTimeFactory();

            context = factory.CreateDbContext(null);
        }
 public AccountService(IMapper mapper, AccountManagerDbContext dbContext)
 {
     _mapper    = mapper;
     _dbContext = dbContext;
 }