Ejemplo n.º 1
0
        // GET: Loans
        public ActionResult Index(string searchString)
        {
            LibraryDal     dal   = new LibraryDal();
            LoansViewModel model = new LoansViewModel();

            model.Loans             = dal.LoansList();
            model.Loans             = model.Loans.OrderByDescending(l => l.StartDate).ToList();
            model.BookTitles        = new List <string>();
            model.ClientsFirstNames = new List <string>();
            model.ClientsLastNames  = new List <string>();

            foreach (ClientBook loan in model.Loans)
            {
                Book   book   = dal.GetBookById(loan.BookId);
                Client client = dal.GetClientById(loan.ClientId);
                model.BookTitles.Add(book.Title);
                model.ClientsFirstNames.Add(client.FirstName);
                model.ClientsLastNames.Add(client.LastName);
            }

            if (!String.IsNullOrEmpty(searchString))
            {
                model.Loans = model.Loans.Where(l => dal.GetBookById(l.BookId).Title.Contains(searchString) ||
                                                dal.GetBookById(l.BookId).ISBN.Contains(searchString) ||
                                                dal.GetClientById(l.ClientId).FirstName.Contains(searchString) ||
                                                dal.GetClientById(l.ClientId).LastName.Contains(searchString) ||
                                                dal.GetClientById(l.ClientId).CIN.Contains(searchString)).ToList();
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public IActionResult Loans()
        {
            var data = new LoansViewModel()
            {
                Employees = _employeeBo.GetEmployees(),
                LoanTypes = _loanTypesBO.GetTypes(),
            };

            return(View(data));
        }
Ejemplo n.º 3
0
        public async Task <IViewComponentResult> InvokeAsync(Guid ProductId, Guid clientId, Guid policyId)
        {
            var loans = await _context.Loans
                        .Include(c => c.Component)
                        .AsNoTracking()
                        .Where(a => a.PolicyID == policyId)
                        .OrderBy(c => c.Component.Name).ToListAsync();

            LoansViewModel viewModel = new LoansViewModel
            {
                ProductID = ProductId,
                ClientID  = clientId,
                PolicyID  = policyId,
                Loans     = loans
            };

            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public LoansViewModel GetAll()
        {
            var query = _context.Loan.AsNoTracking();
            var loans = query.Select(loan => new LoanViewModel
            {
                Loan_ID    = loan.Id,
                User       = loan.User,
                Username   = loan.User.Username,
                Email      = loan.User.Email,
                Book       = loan.Book,
                BookTitle  = loan.Book.Title,
                LoanDate   = loan.LoanDate,
                ReturnDate = loan.ReturnDate
            }).ToList();

            var model = new LoansViewModel {
                Loans = loans
            };

            return(model);
        }
Ejemplo n.º 5
0
        // GET: Loans
        public ActionResult Index(LoansSelection selection)
        {
            //todo: want grab user ID based on who is logged in, not via get

            var info = new List <LoansViewModel>();

            ViewBag.Message = "Here is your loan history: the titles you have checked out, and when they are due back.";

            // if no user ID provided then return view immediately
            if (selection.UserId == null)
            {
                return(View(info));
            }

            // retrieve loan history from db
            LoansQuery query = new LoansQuery();
            List <LoanHistoryToTitleInfo> results = new List <LoanHistoryToTitleInfo>();

            try
            {
                results = query.GetLoanHistoryForUser(int.Parse(selection.UserId));
            }
            catch (Exception)
            {
                ViewBag.ErrorMessage = "Oops!!";
                //todo: test error handling & improve error message generation
            }

            // iterate over results in descending order of due date, and prepare data for view
            foreach (LoanHistoryToTitleInfo result in results.OrderByDescending(r => r.LoanHistory.Dueback_date).ToList())
            {
                LoansViewModel row = new LoansViewModel()
                {
                    TitleName      = result.Title.Title_name,
                    TitleVersion   = result.Title.Title_version,
                    CheckedOutDate = result.LoanHistory.Onloan_date,
                    DueBackDate    = result.LoanHistory.Dueback_date
                };

                // collate loan status dates
                List <LoanStatus> statuses = new List <LoanStatus>()
                {
                    new LoanStatus()
                    {
                        Type = LoanStatus.StatusType.OnLoan.ToString(), Date = result.LoanHistory.Onloan_date
                    },
                    new LoanStatus()
                    {
                        Type = LoanStatus.StatusType.Missing.ToString(), Date = result.LoanHistory.Missing_date
                    },
                    new LoanStatus()
                    {
                        Type = LoanStatus.StatusType.Reserved.ToString(), Date = result.LoanHistory.Reserved_date
                    },
                    new LoanStatus()
                    {
                        Type = LoanStatus.StatusType.Recalled.ToString(), Date = result.LoanHistory.Recalled_date
                    },
                    new LoanStatus()
                    {
                        Type = LoanStatus.StatusType.Returned.ToString(), Date = result.LoanHistory.Returned_date
                    }
                };

                // Set current status to that with highest date
                row.CurrentStatus = statuses.OrderByDescending(s => s.Date).First();

                info.Add(row);
            }

            return(View(info));
        }