public AllLibrariesViewModel PreparedPage()
        {
            var model       = new AllLibrariesViewModel();
            var returnModel = this.GetLibrarys(model);

            return(returnModel);
        }
        public IActionResult SearchLibraries(AllLibrariesViewModel model)
        {
            this.StartUp();
            var returnModel = this.allLibraryService.GetLibrarys(model);

            return(this.View("Index", returnModel));
        }
        public IActionResult AllLibrariesChangePage(AllLibrariesViewModel model, int id)
        {
            this.StartUp();
            var returnModel = this.allLibraryService.ChangeActivePage(model, id);

            return(this.View("Index", returnModel));
        }
        public AllLibrariesViewModel GetLibrarys(AllLibrariesViewModel model)
        {
            var libraryEmail = model.SearchLibrary.Email;
            var libraryName  = model.SearchLibrary.Name;

            var sortMethodId       = model.SortMethodId;
            var countLibraryOfPage = model.CountLibraiesOfPage;
            var currentPage        = model.CurrentPage;
            var libraryRoleId      = this.context.Roles.FirstOrDefault(r => r.Name == GlobalConstants.LibraryRoleName).Id;

            var libraries = this.context.Users
                            .Include(u => u.Roles)
                            .Where(u =>
                                   u.DeletedOn == null &&
                                   u.Roles.FirstOrDefault().RoleId == libraryRoleId)
                            .Select(u => new LibraryViewModel()
            {
                Email    = u.Email,
                Location = u.LastName,
                Name     = u.FirstName,
                Role     = this.roleService.GetUserRole(u),
                Avatar   = u.Avatar,
                UserId   = u.Id,
            });

            libraries = this.SelectLibraries(libraryEmail, libraryName, libraries);
            libraries = this.SortLibraries(sortMethodId, libraries);
            int maxCountPage = libraries.Count() / countLibraryOfPage;

            if (libraries.Count() % countLibraryOfPage != 0)
            {
                maxCountPage++;
            }

            var viewLibraries = libraries.Skip((currentPage - 1) * countLibraryOfPage)
                                .Take(countLibraryOfPage);
            var searchLibrary = new LibraryViewModel()
            {
                Email = libraryEmail,
                Name  = libraryName,
            };

            var returnModel = new AllLibrariesViewModel()
            {
                CountLibraiesOfPage = countLibraryOfPage,
                Libraries           = viewLibraries,
                SearchLibrary       = searchLibrary,
                SortMethodId        = sortMethodId,
                MaxCountPage        = maxCountPage,
                CurrentPage         = currentPage,
            };

            return(returnModel);
        }
 public AllLibrariesViewModel ChangeActivePage(AllLibrariesViewModel model, int newPage)
 {
     model.CurrentPage = newPage;
     return(this.GetLibrarys(model));
 }