Exemplo n.º 1
0
        public async Task <Guid> CreateNewExpense(ExpenseRequestDTO requestDTO)
        {
            var bankAccount = await _repository.GetByIdAsync <Domain.Model.Account.BankAccount>(requestDTO.BankAccountId);

            var institution = await _repository.GetByIdAsync <Domain.Model.Institution.Institution>(requestDTO.InstitutionId);

            var sector = await _repository.GetByIdAsync <Domain.Model.Sector.Sector>(requestDTO.SectorId);

            if (bankAccount == null || institution == null || sector == null)
            {
                return(Guid.Empty);
            }

            var newInstance = new Domain.Model.Income.Expenses
            {
                Amount         = requestDTO.Amount,
                CurrencyType   = requestDTO.CurrencyType,
                Description    = requestDTO.Description,
                DocumentNumber = requestDTO.DocumentNumber,
                Expiry         = requestDTO.Expiry,
                ExpiryDate     = requestDTO.ExpiryDate,
                Type           = requestDTO.ExpenseType,
                BankAccount    = bankAccount,
                Institution    = institution,
                Sector         = sector
            };

            _repository.Add(newInstance);
            await _repository.CommitAsync();

            return(newInstance.Id);
        }
Exemplo n.º 2
0
        public async Task <Guid> UpdateExpense(Guid Id, ExpenseRequestDTO requestDTO)
        {
            var expense = await _repository.Query <Domain.Model.Income.Expenses>().Where(q => q.Id == Id && q.Status == StatusType.Active)
                          .Include(q => q.BankAccount)
                          .Include(q => q.Institution)
                          .FirstOrDefaultAsync();

            var bankAccount = await _repository.GetByIdAsync <Domain.Model.Account.BankAccount>(requestDTO.BankAccountId);

            var sector = await _repository.GetByIdAsync <Domain.Model.Sector.Sector>(requestDTO.SectorId);

            var institution = await _repository.GetByIdAsync <Domain.Model.Institution.Institution>(requestDTO.InstitutionId);

            if (expense == null || bankAccount == null || institution == null || sector == null)
            {
                return(Guid.Empty);
            }

            expense.Amount         = requestDTO.Amount;
            expense.Sector         = sector;
            expense.CurrencyType   = requestDTO.CurrencyType;
            expense.Description    = requestDTO.Description;
            expense.DocumentNumber = requestDTO.DocumentNumber;
            expense.Expiry         = requestDTO.Expiry;
            expense.ExpiryDate     = requestDTO.ExpiryDate;
            expense.Type           = requestDTO.ExpenseType;
            expense.BankAccount    = bankAccount;

            _repository.Update(expense);
            await _repository.CommitAsync();

            return(expense.Id);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateNewExpense([FromBody] ExpenseRequestDTO requestDTO)
        {
            var result = await _expensesService.CreateNewExpense(requestDTO);

            return(new OkObjectResult(new { Id = result }));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> UpdateExpense(Guid Id, [FromBody] ExpenseRequestDTO requestDTO)
        {
            var result = await _expensesService.UpdateExpense(Id, requestDTO);

            return(new OkObjectResult(new { Id = result }));
        }