예제 #1
0
        public void UpdateLoanRegistration(int userId, int bookId, LoanView loan)
        {
            var bookEntity = _db.Books.SingleOrDefault(b => (b.Id == bookId && b.Deleted == false));

            if (bookEntity == null)
            {
                throw new NotFoundException("Book with id " + bookId + " not found.");
            }

            var userEntity = _db.Users.SingleOrDefault(u => (u.Id == userId && u.Deleted == false));

            if (userEntity == null)
            {
                throw new NotFoundException("User with id " + userId + " not found.");
            }

            var loanEntity = _db.Loans.SingleOrDefault(l => (l.UserId == userId && l.BookId == bookId));

            if (loanEntity == null)
            {
                throw new NotFoundException("Loan for book id " + bookId + " and user id " + userId + " not found.");
            }

            loanEntity.BookId          = loan.BookId;
            loanEntity.HasBeenReturned = loan.HasBeenReturned;
            loanEntity.LoanDate        = loan.LoanDate;
            loanEntity.EndDate         = loan.EndDate;
            loanEntity.UserId          = loan.UserId;

            try {
                _db.SaveChanges();
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
예제 #2
0
        public void Books_UpdateLoanRegistration_SuccessfulUpdate()
        {
            // Arrange
            var repo   = new BooksRepository(context);
            int userId = (context.Users.OrderByDescending(u => u.Id).FirstOrDefault()).Id;
            int bookId = (context.Books.OrderByDescending(u => u.Id).FirstOrDefault()).Id;

            var updatedLoan = new LoanView {
                UserId          = userId,
                BookId          = bookId,
                LoanDate        = new DateTime(1999, 12, 24),
                HasBeenReturned = true,
                EndDate         = new DateTime(2019, 12, 24)
            };

            // Act
            repo.UpdateLoanRegistration(userId, bookId, updatedLoan);

            // Assert
            Assert.AreEqual(new DateTime(1999, 12, 24), (context.Loans
                                                         .Where(l => l.UserId == userId && l.BookId == bookId)
                                                         .SingleOrDefault()).LoanDate);
            Assert.AreEqual(new DateTime(2019, 12, 24), (context.Loans
                                                         .Where(l => l.UserId == userId && l.BookId == bookId)
                                                         .SingleOrDefault()).EndDate);
            Assert.AreEqual(true, (context.Loans
                                   .Where(l => l.UserId == userId && l.BookId == bookId)
                                   .SingleOrDefault()).HasBeenReturned);
        }
예제 #3
0
        private void LoanButton_Click(object sender, EventArgs e)
        {
            LoanView       loanView       = new LoanView();
            LoanService    loanService    = new LoanService();
            IList          loanList       = loanService.getAllLoans();
            LoanController loanController = new LoanController(loanView, loanList);

            loanController.LoadView();
            loanView.ShowDialog();
        }
예제 #4
0
 public string DisplayLoanStatus(LoanView loan)
 {
     if (loan.StillOutOnLoan)
     {
         return(String.Format(@"due back on {0} <a href=""Memberdetail.aspx?CopyIdToReturn={1}&Id={2}"">return?</a>", loan.DateForReturn, loan.CopyId, loan.MemberId));
     }
     else
     {
         return("returned on " + loan.ReturnDate);
     }
 }
예제 #5
0
 public IActionResult UpdateLoanRegistration(int userId, int bookId, [FromBody] LoanView loan)
 {
     if (loan == null)
     {
         return(BadRequest());
     }
     try {
         _booksService.UpdateLoanRegistration(userId, bookId, loan);
         return(NoContent());
     } catch (NotFoundException e) {
         return(NotFound(e.Message));
     }
 }
예제 #6
0
        public void Books_UpdateLoanRegistration_BookDoesntExist()
        {
            // Arrange
            var repo   = new BooksRepository(context);
            int userId = (context.Users.OrderByDescending(u => u.Id).FirstOrDefault()).Id;
            int bookId = (context.Books.OrderByDescending(u => u.Id).FirstOrDefault()).Id + 1;

            var loan = new LoanView {
                UserId          = userId,
                BookId          = bookId,
                LoanDate        = DateTime.Now,
                HasBeenReturned = false,
                EndDate         = null
            };

            // Act
            repo.UpdateLoanRegistration(userId, bookId, loan);

            // Assert
            Assert.Fail("Should have thrown a NotFoundException");
        }
예제 #7
0
        public void Books_UpdateLoanRegistration_LoanDoesntExist()
        {
            // Arrange
            var repo    = new BooksRepository(context);
            var newUser = new User {
                Name        = "New Guy",
                Address     = "Some street",
                Email       = "*****@*****.**",
                PhoneNumber = "1597534",
                Deleted     = false
            };
            var newBook = new Book {
                Title       = "New Book",
                Author      = "Some Guy",
                ReleaseDate = DateTime.Now,
                ISBN        = "5318343518342168435",
                Available   = true,
                Deleted     = false
            };

            context.Books.Add(newBook);
            context.Users.Add(newUser);
            context.SaveChanges();

            var loan = new LoanView {
                UserId          = newUser.Id,
                BookId          = newBook.Id,
                LoanDate        = DateTime.Now,
                HasBeenReturned = false,
                EndDate         = null
            };

            // Act
            repo.UpdateLoanRegistration(newUser.Id, newBook.Id, loan);

            // Assert
            Assert.Fail("Should have thrown a NotFoundException");
        }
예제 #8
0
        public IEnumerable <LoanView> CalculateLoan(int id, int loantypeid)
        {
            var op = context.Pf_loanType.FirstOrDefault(x => x.Id == loantypeid).Code;

            var     gh       = context.person.FirstOrDefault(x => x.PersonID == id);
            var     fg       = context.Pf_loanType.FirstOrDefault(x => x.Code == op);
            int     tenure   = int.Parse(fg.Tenure);
            double  interest = Convert.ToDouble(fg.Interest);
            decimal amount   = 0M;
            double  amount2;

            var rf = context.loanPerRank.FirstOrDefault(x => x.loantype == op);

            if (gh.rank == 1)
            {
                amount = rf.amount01;
            }
            if (gh.rank == 2)
            {
                amount = rf.amount02;
            }
            if (gh.rank == 3)
            {
                amount = rf.amount03;
            }
            if (gh.rank == 4)
            {
                amount = rf.amount04;
            }
            if (gh.rank == 5)
            {
                amount = rf.amount05;
            }
            if (gh.rank == 6)
            {
                amount = rf.amount06;
            }
            if (gh.rank == 7)
            {
                amount = rf.amount07;
            }
            if (gh.rank == 8)
            {
                amount = rf.amount08;
            }
            if (gh.rank == 9)
            {
                amount = rf.amount09;
            }
            if (gh.rank == 10)
            {
                amount = rf.amount10;
            }
            if (gh.rank == 11)
            {
                amount = rf.amount11;
            }
            if (gh.rank == 12)
            {
                amount = rf.amount12;
            }
            if (gh.rank == 13)
            {
                amount = rf.amount13;
            }
            if (gh.rank == 14)
            {
                amount = rf.amount14;
            }
            if (gh.rank == 15)
            {
                amount = rf.amount15;
            }
            if (gh.rank == 16)
            {
                amount = rf.amount16;
            }
            if (gh.rank == 17)
            {
                amount = rf.amount17;
            }
            if (gh.rank == 18)
            {
                amount = rf.amount18;
            }
            if (gh.rank == 19)
            {
                amount = rf.amount19;
            }
            if (gh.rank == 20)
            {
                amount = rf.amount20;
            }


            amount2 = Convert.ToDouble(amount);


            double a    = (amount2 * interest) / 100;
            double b    = amount2 + a;
            double sumE = 0.0;

            List <LoanView> AllRecord = new List <LoanView>();

            for (int j = 1; j <= tenure; j++)
            {
                for (int k = 1; k < 2; k++)
                {
                    sumE += ((amount2 + a) / tenure);
                    var result = new LoanView
                    {
                        openingBalance       = Math.Round(b, 2),
                        PrincipalRepayment   = Math.Round((amount2 / tenure), 2),
                        interestPayment      = Math.Round((a / tenure), 2),
                        MonthlyDeduction     = Math.Round(((amount2 + a) / tenure), 2),
                        TotalRepaymentToDate = Math.Round(sumE, 2),
                        OutstandingBalance   = Math.Round((b - ((amount2 + a) / tenure)), 2)
                    };

                    b = result.OutstandingBalance;

                    AllRecord.Add(result);
                }
            }


            return(AllRecord);
        }
예제 #9
0
 private void ShowLoanViewProc()
 {
     _loanView       = new LoanView();
     _loanView.Owner = Application.Current.MainWindow;
     _loanView.ShowDialog();
 }
예제 #10
0
 public void UpdateLoanRegistration(int userId, int bookId, LoanView book)
 {
     _repo.UpdateLoanRegistration(userId, bookId, book);
 }