public IActionResult Index()
        {
            var branches = _branch.GetAll().Select(a => new BranchDetailModel
            {
                Id              = a.Id,
                BranchName      = a.Name,
                isOpen          = _branch.isBranchOpen(a.Id),
                NumberOfAssets  = _branch.GetLibraryAssets(a.Id).Count(),
                NumberOfPatrons = _branch.GetPatrons(a.Id).Count()
            }).ToList();

            var model = new BranchIndexModel
            {
                Branches = branches
            };

            return(View(model));
        }
        public IActionResult Index()
        {
            var branches = _branch.GetAll()
                           .Select(b => new BranchDetailModel
            {
                Id              = b.Id,
                Name            = b.Name,
                IsOpen          = _branch.IsBranchOpen(b.Id),
                NumberOfAssets  = _branch.GetAssets(b.Id).Count(),
                NumberOfPatrons = _branch.GetPatrons(b.Id).Count()
            });

            var model = new BranchIndexModel
            {
                Branches = branches
            };

            return(View(model));
        }
Пример #3
0
        public IActionResult Index()
        {
            var branches = _branch.GetAll().Select(branch => new BranchDetailModel
            {
                Id              = branch.Id,
                BranchName      = branch.Name,
                IsOpen          = _branch.IsBranchOpen(branch.Id),
                NumberOfAssets  = _branch.GetAssets(branch.Id).Count(),
                NumberOfPatrons = _branch.GetPatrons(branch.Id).Count()
            });

            //Create a view Model to return to the Index View
            var model = new BranchIndexModel()
            {
                Branches = branches
            };

            return(View(model));
        }
Пример #4
0
        public IActionResult Index(string sortOrder, string searchString)
        {
            var branchModels = from c in _branch.GetAll().ToList() select c;

            ViewData["CurrentFilter"]     = searchString;
            ViewData["NameSortParm"]      = sortOrder == "name" ? "name_desc" : "name";
            ViewData["AddressSortParm"]   = sortOrder == "address" ? "address_desc" : "address";
            ViewData["TelephoneSortParm"] = sortOrder == "telephone" ? "telephone_desc" : "telephone";;

            if (!String.IsNullOrEmpty(searchString))
            {
                branchModels = branchModels.Where(c => c.Name.ToUpper().Contains(searchString.ToUpper()) ||
                                                  c.Address.ToUpper().Contains(searchString.ToUpper()) ||
                                                  c.Telephone.Contains(searchString));
            }

            switch (sortOrder)
            {
            case "name":
                branchModels = branchModels.OrderBy(s => s.Name.ToUpper());
                break;

            case "name_desc":
                branchModels = branchModels.OrderByDescending(s => s.Name.ToUpper());
                break;

            case "address":
                branchModels = branchModels.OrderBy(s => s.Address.ToUpper());
                break;

            case "address_desc":
                branchModels = branchModels.OrderByDescending(s => s.Address.ToUpper());
                break;

            case "telephone":
                branchModels = branchModels.OrderBy(s => s.Telephone);
                break;

            case "telephone_desc":
                branchModels = branchModels.OrderByDescending(s => s.Telephone);
                break;

            default:
                branchModels = branchModels.OrderBy(s => s.Id);
                break;
            }

            var branches = branchModels
                           .Select(branch => new BranchDetailModel

            {
                Id        = branch.Id,
                Name      = branch.Name,
                Address   = branch.Address,
                Telephone = branch.Telephone
            });

            var model = new BranchIndexModel()
            {
                Branches = branches
            };

            return(View(model));
        }