Пример #1
0
        public async Task <IActionResult> Index([FromQuery] int page = 1, [FromQuery] int perPage = 10)
        {
            var paginatedBranches = await _branchService.GetPaginated(page, perPage);

            if (paginatedBranches.Results.Any())
            {
                foreach (var branch in paginatedBranches.Results)
                {
                    var branchId = branch.Id;
                    branch.IsOpen = await _branchService.IsBranchOpen(branchId);

                    branch.NumberOfAssets = await _branchService.GetAssetCount(branchId);

                    branch.NumberOfPatrons = await _branchService.GetPatronCount(branchId);
                }

                var model = new BranchIndexModel {
                    PageOfBranches = paginatedBranches
                };

                return(View(model));
            }

            var emptyModel = new BranchIndexModel {
                PageOfBranches = new PaginationResult <LibraryBranchDto> {
                    Results    = new List <LibraryBranchDto>(),
                    PageNumber = page,
                    PerPage    = perPage
                }
            };

            return(View(emptyModel));
        }
Пример #2
0
        public IActionResult Index()
        {
            if (HttpContext.Session.GetString("username") == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else if (HttpContext.Session.GetInt32("role_id") == 3)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else
            {
                var branchModels = _branchService.GetAll()
                                   .Select(br => new BranchDetailModel
                {
                    Id              = br.Id,
                    BranchName      = br.Name,
                    NumberOfAssets  = _branchService.GetAssetCount(br.Id),
                    NumberOfPatrons = _branchService.GetPatronCount(br.Id),
                    IsOpen          = _branchService.IsBranchOpen(br.Id)
                }).ToList();

                var model = new BranchIndexModel
                {
                    Branches = branchModels
                };

                return(View(model));
            }
        }
        public IActionResult Index()
        {
            var branchModels = _branchService.GetAll()
                               .Select(br => new BranchDetailModel
            {
                Id              = br.Id,
                BranchName      = br.Name,
                NumberOfAssets  = _branchService.GetAssetCount(br.Id),
                NumberOfPatrons = _branchService.GetPatronCount(br.Id),
                IsOpen          = _branchService.IsBranchOpen(br.Id)
            }).ToList();

            var model = new BranchIndexModel
            {
                Branches = branchModels
            };

            return(View(model));
        }
Пример #4
0
        public IActionResult ListBranch()
        {
            var branch = _branch.GetAll();
            var List   = branch
                         .Select(result => new BranchDetailModel
            {
                Id              = result.Id,
                ImageURL        = result.ImageUrl,
                Name            = result.Name,
                Address         = result.Address,
                Telephone       = result.Telephone,
                Description     = result.Description,
                OpenDate        = result.OpenDate,
                NumberOfAssets  = _branch.GetAssetCount(result.Id),
                NumberOfPatrons = _branch.GetPatronCount(result.Id),
                IsOpen          = _branch.IsBranchOpen(result.Id)
            });
            var model_branch = new BranchIndexModel()
            {
                Branches = List
            };

            return(View(model_branch));
        }