public async Task <SavingsDeposit> AddSavingsDepositAsync(SavingsDeposit deposit)
        {
            var inserted = await connection.InsertAsync(deposit);

            //deposit.IsNew = false;
            return(deposit);
        }
        public async Task <IActionResult> PutSavingDeposit([FromRoute] int id, [FromBody] SavingsDepositDTO savingsDepositDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != savingsDepositDTO.Id)
            {
                return(BadRequest());
            }

            SavingsDeposit result = _mapper.Map <SavingsDeposit>(savingsDepositDTO);

            if (_userService.IsAdmin(HttpContext.User))
            {
                await _savingsService.UpdateSavingsDepositAsync(result);
            }
            else
            {
                string requestUserId = GetUserId(HttpContext.User);
                await _savingsService.UpdateSavingsDepositAsync(requestUserId, result);
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task UpdateSavingsDepositAsync(SavingsDeposit entity)
        {
            var owner = await _context.SavingsDeposits.Where(x => x.Id == entity.Id).Select(x => x.Owner).SingleOrDefaultAsync();

            entity.Owner = owner;
            _context.Entry(entity).State = EntityState.Modified;
            await _context.SaveChangesAsync();
        }
Ejemplo n.º 4
0
        public void ReportTest()
        {
            SavingsDeposit deposit = new SavingsDeposit
            {
                BankName                 = "MyDepositBank",
                AccountNumber            = 777777777,
                Owner                    = _user.Id,
                StartDate                = DateTime.Today,
                EndDate                  = DateTime.Today.AddDays(7),
                InitialAmount            = 100_000_000,
                TaxPercentage            = 20,
                YearlyInterestPercentage = 5
            };


            SavingsDeposit depositSmall = new SavingsDeposit
            {
                BankName                 = "MySmallDepositBank",
                AccountNumber            = 333333,
                Owner                    = _user.Id,
                StartDate                = DateTime.Today,
                EndDate                  = DateTime.Today.AddDays(7),
                InitialAmount            = 1000,
                TaxPercentage            = 10,
                YearlyInterestPercentage = 30
            };

            SavingsDeposit credit = new SavingsDeposit
            {
                BankName                 = "MyCreditBank",
                AccountNumber            = 111111,
                Owner                    = _user.Id,
                StartDate                = DateTime.Today,
                EndDate                  = DateTime.Today.AddDays(7),
                InitialAmount            = 10_000_000,
                TaxPercentage            = 0,
                YearlyInterestPercentage = -10
            };

            _context.SavingsDeposits.Add(deposit);
            _context.SavingsDeposits.Add(credit);
            _context.SavingsDeposits.Add(depositSmall);
            _context.SaveChanges();


            var today = DateTime.Today;

            for (int i = 0; i < 7; i++)
            {
                _calculationService.RunCalculationForAllUsersAsync(today.AddDays(i)).Wait();
            }

            ReportService reportService = new ReportService(_context);

            var report = reportService.GenerateReport(_user.Id, today, today.AddDays(7)).Result;
        }
    }
}
 public async Task <SavingsDeposit> AddSavingsDepositAsync(SavingsDeposit deposit)
 {
     if (!context.SavingsDeposit.Any(d => d.id == deposit.id))
     {
         await Task.Run(() => context.SavingsDeposit.Add(deposit));
     }
     else
     {
         throw new Exception("A deposit record already exists with the same Primary Key value");
     }
     return(deposit);
 }
        public async Task DeleteSavingsDepositAsync(SavingsDeposit deposit)
        {
            if (context.SavingsDeposit.Any(d => d.id == deposit.id))
            {
                await Task.Run(() => context.SavingsDeposit.Attach(deposit));

                await Task.Run(() => context.Entry(deposit).State = Microsoft.EntityFrameworkCore.EntityState.Deleted);

                if (deposit.savingsAccount != null)
                {
                    await Task.Run(() => context.Entry(deposit.savingsAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified);
                }
            }
        }
        public async Task UpdateSavingsDepositAsync(SavingsDeposit deposit)
        {
            if (context.SavingsDeposit.Any(c => c.id == deposit.id))
            {
                await Task.Run(() => context.SavingsDeposit.Attach(deposit));

                await Task.Run(() => context.Entry(deposit).State = Microsoft.EntityFrameworkCore.EntityState.Modified);

                if (deposit.savingsAccount != null)
                {
                    await Task.Run(() => context.Entry(deposit.savingsAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified);
                }
            }
            else
            {
                throw new Exception("Unable to locate existing Savings Deposit record with provided Primary Key value");
            }
        }
Ejemplo n.º 8
0
        private SavingsDeposit[] TestData()
        {
            SavingsDeposit deposit = new SavingsDeposit
            {
                BankName                 = "MyDepositBank",
                AccountNumber            = 777777777,
                Owner                    = "myId",
                StartDate                = DateTime.Today,
                EndDate                  = DateTime.Today.AddDays(7),
                InitialAmount            = 100_000_000,
                TaxPercentage            = 20,
                YearlyInterestPercentage = 5
            };


            SavingsDeposit depositSmall = new SavingsDeposit
            {
                BankName                 = "MySmallDepositBank",
                AccountNumber            = 333333,
                Owner                    = "myId",
                StartDate                = DateTime.Today,
                EndDate                  = DateTime.Today.AddDays(7),
                InitialAmount            = 1000,
                TaxPercentage            = 10,
                YearlyInterestPercentage = 30
            };

            SavingsDeposit credit = new SavingsDeposit
            {
                BankName                 = "MyCreditBank",
                AccountNumber            = 111111,
                Owner                    = "myId",
                StartDate                = DateTime.Today,
                EndDate                  = DateTime.Today.AddDays(7),
                InitialAmount            = 10_000_000,
                TaxPercentage            = 0,
                YearlyInterestPercentage = -10
            };

            return(new[] { deposit, credit, depositSmall });
        }
    }
}
        public async Task PopulateVMAsync(SavingsDeposit deposit)
        {
            this.model             = deposit;
            this.accountModel      = deposit.savingsAccount;
            this.ItemId            = this.model.id;
            this.ItemType          = AccountItemType.Deposits;
            this.ItemAmount        = model.transactionAmount;
            this.EndingBalance     = model.endingBalance;
            this.ItemDescription   = model.description;
            this.Description       = this.model.description;
            this.TransactionDate   = model.transactionDate;
            this.ItemDate          = model.transactionDate;
            this.TransactionAmount = model.transactionAmount;
            this.ObjectColorCode   = this.model.ColorCode;

            this.BudgetItemId = model.budgetIncomeId;

            //await LoadBudgetData();
        }
Ejemplo n.º 10
0
        public async Task UpdateSavingsDepositAsync(string userId, SavingsDeposit entity)
        {
            var result = await _context.SavingsDeposits.Where(x => x.Id == entity.Id).Select(x => x.Owner).FirstOrDefaultAsync();

            if (result == null)
            {
                throw new NotFoundException("Deposit not found for current user");
            }

            if (result == userId)
            {
                entity.Owner = userId;
                _context.Entry(entity).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            else
            {
                throw new NotAuthorizedException("User cannot edit this record");
            }
        }
Ejemplo n.º 11
0
        public DepositHistory PerformDepositCalculation(SavingsDeposit savingsDeposit)
        {
            DepositHistory depositHistory = new DepositHistory();

            decimal dailyCalculatedAmount = savingsDeposit.AccountBalance * savingsDeposit.YearlyInterestPercentage /
                                            DaysInYear / 100m;
            decimal profitTax = 0;

            if (dailyCalculatedAmount > 0)
            {
                profitTax = dailyCalculatedAmount * savingsDeposit.TaxPercentage / 100m;
            }

            depositHistory.SavingsDepositId = savingsDeposit.Id;

            depositHistory.ProfitBeforeTax = Math.Round(dailyCalculatedAmount, 2);
            depositHistory.ProfitTax       = Math.Round(profitTax, 2);
            depositHistory.ProfitAfterTax  = depositHistory.ProfitBeforeTax - depositHistory.ProfitTax;

            depositHistory.TotalProfitAfterTax = savingsDeposit.CurrentProfitAfterTax + depositHistory.ProfitAfterTax;

            return(depositHistory);
        }
        async Task <SavingsDepositViewModel> AddSavingsDepositAsync()
        {
            SavingsDepositViewModel vm = new SavingsDepositViewModel(this.dbFilePath);

            vm.IsNew     = true;
            vm.CanEdit   = true;
            vm.CanDelete = false;
            vm.ItemType  = AccountRegisterItemViewModel.AccountItemType.Deposits;

            SavingsDeposit deposit = new SavingsDeposit();

            deposit.savingsAccount   = model as SavingsAccount;
            deposit.savingsAccountId = model.id;
            deposit.transactionDate  = DateTime.Now;

            await vm.PopulateVMAsync(deposit);

            //this.AccountRegister.Add(vm);
            //await GroupAccountItemsAsync();
            //this.SelectedRegisterItem = vm;

            return(vm);
        }
 public async Task UpdateSavingsDepositAsync(SavingsDeposit deposit)
 {
     var updated = await connection.UpdateAsync(deposit);
 }
 public async Task DeleteSavingsDepositAsync(SavingsDeposit deposit)
 {
     var deleted = await connection.DeleteAsync(deposit);
 }
Ejemplo n.º 15
0
 public async Task CreateNewSavingsDepositAsync(SavingsDeposit entity)
 {
     _context.SavingsDeposits.Add(entity);
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 16
0
 public void Put(int id, [FromBody] SavingsDeposit item)
 {
     throw new NotImplementedException();
 }