//Här använder jag asyncron metoden för att böcker och författare ska kunna hämtas oberoende av main tråden //samt att await pausar all vidare exekvering fram tills alla böcker och författare är framtagna. public async static void GetAll() { var bookRepo = new BooksRepository(); var authorRepo = new AuthorsRepository(); Console.WriteLine("Starting"); Task <ICollection <Book> > books = bookRepo.GetAllAsync(); foreach (var book in books.Result) { Console.WriteLine(book.Title); } Console.WriteLine("In process"); Task <ICollection <Author> > authors = authorRepo.GetAllAsync(); foreach (var author in authors.Result) { Console.WriteLine(author.FirstName); } await Task.WhenAll(books, authors); Console.WriteLine("Both tasks done"); }
static void Main(string[] args) { connectionString = ConfigurationManager.ConnectionStrings["BooksDb"].ConnectionString; var loader = new AuthorsRepository(connectionString); while (true) { Console.WriteLine("1) Get all authors"); Console.WriteLine("2) Get authors by name"); Console.WriteLine("3) Get author by ID"); Console.WriteLine("4) Add new author"); var choice = Console.ReadLine(); if (choice == "2") { Console.Write("Enter name fragment: "); var fragment = Console.ReadLine(); var results = loader.GetAuthorsByName(fragment); PrintAuthors(results); } else if (choice == "1") { var results = loader.GetAllAuthors(); PrintAuthors(results); } else if (choice == "3") { Console.Write("Enter Id: "); var fragment = Int32.Parse(Console.ReadLine()); var result = loader.GetAuthorById(fragment); PrintAuthor(result); } } }
public ActionResult EditAuthor(AuthorsEditAuthorVM model) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); AuthorsRepository authorsRepository = new AuthorsRepository(context); Author author = null; if (!ModelState.IsValid) { return(View(model)); } else { if (model.ID > 0) { author = authorsRepository.GetByID(model.ID); } else { author = new Author(); } author.ID = model.ID; author.FirstName = model.FirstName; author.LastName = model.LastName; authorsRepository.Save(author); } return(RedirectToAction("Index", "Authors")); }
public UnitOfWork(IDbContextFactory <APPDbContext> dbContextFactory, Microsoft.AspNetCore.Http.IHttpContextAccessor httpContextAccessor) { _dbContext = dbContextFactory.GetContext(); UserRepository = new UserRepository(_dbContext); MenuRepository = new MenuRepository(_dbContext); RolesRepository = new RolesRepository(_dbContext); Role_PermissionsRepository = new Role_PermissionsRepository(_dbContext); AccountsRepository = new AccountsRepository(_dbContext); AccountRolesRepository = new AccountRolesRepository(_dbContext); CategoryRepository = new CategoryRepository(_dbContext); Content_CategoriesRepository = new Content_CategoriesRepository(_dbContext); AuthorsRepository = new AuthorsRepository(_dbContext); GroupsRepository = new GroupsRepository(_dbContext); NewsSourcesRepository = new NewsSourcesRepository(_dbContext); TypesRepository = new TypesRepository(_dbContext); ContentTypesRepository = new ContentTypesRepository(_dbContext); Content_GroupsRepository = new Content_GroupsRepository(_dbContext); TitleImagesRepository = new TitleImagesRepository(_dbContext); MediasRepository = new MediasRepository(_dbContext); ContentsRepository = new ContentsRepository(_dbContext); QuanLyDonGiaNhuanButRepository = new QuanLyDonGiaNhuanButRepository(_dbContext); TheLoai_HeSoRepository = new TheLoai_HeSoRepository(_dbContext); NhuanButRepository = new NhuanButRepository(_dbContext); ContactRepository = new ContactRepository(_dbContext); }
protected void Page_Load(object sender, EventArgs e) { if (Session["username"] != null) { db = new ContentManagementEntities(); if (Request.Form["action"] == "save") { SaveToDb(); } id = Convert.ToInt32(Request.QueryString["id"]); if (id != 0) { myid = id; } author = author = db.Authors.Where(c => c.Id == myid).FirstOrDefault(); rep = new ArticlesRepository(); repCat = new CategoriesRepository(); repAuthor = new AuthorsRepository(); articleList = rep.List(); catList = repCat.List(); authorsList = repAuthor.List(); } else { Response.Redirect("/AuthorLogin"); } }
public DataAccess() { _context = new LibraryContext(); _usersRepository = new UsersRepository(_context); _booksRepository = new BooksRepository(_context); _authorsRepository = new AuthorsRepository(_context); }
public LibraryQuery(BooksRepository booksRepository, AuthorsRepository authorsRepository) { FieldAsync <ListGraphType <BookType> >( "books", resolve: async context => { return(await booksRepository.GetAllAsync()); }); Field <BookType>( "book", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" }), resolve: context => { var id = context.GetArgument <long>("id"); return(booksRepository.GetById(id)); }); Field <ListGraphType <AuthorType> >( "authors", resolve: context => authorsRepository.GetAuthorsAsync()); Field <AuthorType>( "author", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" }), resolve: context => { var id = context.GetArgument <long>("id"); return(authorsRepository.GetAuthorById(id)); }); }
protected void Page_Load(object sender, EventArgs e) { db = new ContentManagementEntities(); if (Request.Form["action"] == "login") { rep = new AuthorsRepository(); authorList = rep.List(); for (int i = 0; i < authorList.Count; i++) { if (authorList[i].UserName == Username.Value && authorList[i].Password == Password.Value) { isloginFailed = false; break; } } if (isloginFailed) { Session["username"] = null; Response.Redirect("/AuthorLogin"); } else { author = db.Authors.Where(c => c.UserName == Username.Value).FirstOrDefault(); Session["username"] = author.UserName; Response.Redirect("/AddArticle?id=" + author.Id); } } }
// PUT: api/Authors/5 public Author Put(int id, [FromBody] Author author) { AuthorsRepository authorsRepo = new AuthorsRepository(); author.Id = id; return(authorsRepo.Update(author)); }
protected void Page_Load(object sender, EventArgs e) { db = new ContentManagementEntities(); authorid = AddArticle.myid; author = db.Authors.Where(c => c.Id == authorid).FirstOrDefault(); rep = new ArticlesRepository(); repAutors = new AuthorsRepository(); repCat = new CategoriesRepository(); articleList = rep.List(); isonclick = false; if (IsPostBack) { isonclick = true; } if (isonclick) { articleListFilter = rep.FilterList(Title.Value, Request.Form["CatType"], Request.Form["Autors"], ArticleBody.Value); } else { articleListFilter = rep.List(); } catList = repCat.List(); authorList = repAutors.List(); }
public AuthorsList() { InitializeComponent(); var context = new LibraryContext(); _authorsRepository = new AuthorsRepository(context); FillAuthorsListBox(); }
public AuthorAddForm() { InitializeComponent(); var context = new LibraryContext(); _authorsRepository = new AuthorsRepository(context); FillBooks(); }
public CreateEditAuthor() { InitializeComponent(); var context = new LibraryContext(); _authorsRepository = new AuthorsRepository(context); createEditButton.Text = @"Create"; }
public BooksController( BooksRepository booksRepository, AuthorsRepository authorsRepository, AuthorsHelper authorsHelper) { this.booksRepository = booksRepository; this.authorsHelper = authorsHelper; this.authorsRepository = authorsRepository; }
// List refresh methods private void RefreshRepositories() { var context = new LibraryContext(); _authorsRepository = new AuthorsRepository(context); _studentsRepository = new StudentsRepository(context); _publishersRepository = new PublishersRepository(context); _booksRepository = new BooksRepository(context); _loansRepository = new LoansRepository(context); }
public static void AddAuthor() { var authorRepo = new AuthorsRepository(); authorRepo.Add(new Author { FirstName = "Anders", LastName = "Gren", BirthDay = new DateTime(1922, 1, 2) }); authorRepo.Save(); Console.WriteLine("Added new author"); }
protected void Page_Load(object sender, EventArgs e) { db = new ContentManagementEntities(); rep = new AuthorsRepository(); Authorid = AddArticle.myid; myAdminId = AdminLogin.adminId; adminmi = AdminLogin.isAdmin; author = db.Authors.Where(c => c.Id == Authorid).FirstOrDefault(); admin = db.Admin.Where(c => c.Id == myAdminId).FirstOrDefault(); }
public void deleteDatabase() { int id = Convert.ToInt32(Request.QueryString["id"]); db = new ContentManagementEntities(); Authors entity = new Authors(); entity = db.Authors.Where(c => c.Id == id).FirstOrDefault(); rep = new AuthorsRepository(); rep.Delete(entity.Id); }
public AuthorDetailsForm(string authorId) { InitializeComponent(); var context = new LibraryContext(); _authorsRepository = new AuthorsRepository(context); _author = _authorsRepository.GetAuthorById(int.Parse(authorId)); FillDetails(); }
public CreateEditAuthor(Author authorToEdit) { InitializeComponent(); var context = new LibraryContext(); _authorsRepository = new AuthorsRepository(context); _authorToEdit = authorToEdit; createEditButton.Text = @"Edit"; FillInputFields(); }
private void FillAuthorsListBox() { authorsListBox.Items.Clear(); var context = new LibraryContext(); _authorsRepository = new AuthorsRepository(context); foreach (var author in _authorsRepository.GetAllAuthors()) { authorsListBox.Items.Add($"{author.AuthorId}. {author.FirstName} {author.LastName}"); } }
private List <Author> PopulateAuthorList(List <Author> authors, Quote quote) { AuthorsRepository aRepo = new AuthorsRepository(); int authorUnwantedId = quote.Author.Id; Expression <Func <Author, bool> > authorFilter = a => a.Id != authorUnwantedId; Func <IQueryable <Author>, IOrderedQueryable <Author> > order = u => u.OrderBy(r => Guid.NewGuid()); authors = aRepo.GetAll(authorFilter, 1, 2, order); authors.Add(quote.Author); Shuffle(authors); return(authors); }
public BookType(Func <ApplicationDbContext> dbContext) { Field(t => t.Id); Field(t => t.Title); Field(t => t.Description); Field(t => t.ReleaseDate); FieldAsync <AuthorType>( "author", resolve: async context => { using var db = dbContext(); var authorsRepository = new AuthorsRepository(db); return(await authorsRepository.GetAuthorByIdAsync(context.Source.AuthorId)); } ); }
public CreateEditBook() { InitializeComponent(); var context = new LibraryContext(); _booksRepository = new BooksRepository(context); _authorsRepository = new AuthorsRepository(context); _publishersRepository = new PublishersRepository(context); createEditButton.Text = @"Create"; RefreshPublishersAndAuthorsList(); RefreshGenres(); SearchAutoComplete(); }
public ActionResult AddBookAuthor(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); BooksRepository booksRepository = new BooksRepository(context); AuthorsRepository authorsRepository = new AuthorsRepository(context); BooksAddBookAuthorVM model = new BooksAddBookAuthorVM(); Book book = booksRepository.GetByID(id); model.ID = book.ID; model.Title = book.Title; model.Authors = model.Authors ?? new List<SelectListItem>(); model.Authors = SelectListHandler.Create<Author>( authorsRepository.GetAll(), a => (a.FirstName + " " + a.LastName), a => a.ID.ToString(), model.AuthorID.ToString()); return View(model); }
public ActionResult AddBookAuthor(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); BooksRepository booksRepository = new BooksRepository(context); AuthorsRepository authorsRepository = new AuthorsRepository(context); BooksAddBookAuthorVM model = new BooksAddBookAuthorVM(); Book book = booksRepository.GetByID(id); model.ID = book.ID; model.Title = book.Title; model.Authors = model.Authors ?? new List <SelectListItem>(); model.Authors = SelectListHandler.Create <Author>( authorsRepository.GetAll(), a => (a.FirstName + " " + a.LastName), a => a.ID.ToString(), model.AuthorID.ToString()); return(View(model)); }
private List <SelectListItem> PopulateSelectList() { AuthorsRepository repo = new AuthorsRepository(); List <Author> dbAuthors = repo.GetAll(a => true); List <SelectListItem> listItems = new List <SelectListItem>(); foreach (Author author in dbAuthors) { listItems.Add(new SelectListItem() { Text = author.Name, Value = author.Id.ToString() }); } return(listItems); }
public virtual void AddBookToAuthor(string authorLastName, string bookTitle) { var authorRepo = new AuthorsRepository(); var author = authorRepo.FindBy(a => a.LastName.StartsWith(authorLastName)).FirstOrDefault(); Console.WriteLine(author.FirstName); var bookRepo = new BooksRepository(); var book = bookRepo.FindBy(b => b.Title.StartsWith(bookTitle)).FirstOrDefault(); Console.WriteLine(book.Title); var context = new BookContext(); context.Add(new BookAuthor { BookId = book.Id, AuthorId = author.Id }); Console.WriteLine("Waiting for books and authors"); context.SaveChanges(); }
public int GetPagesCount(Expression <Func <Author, bool> > filter = null) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); AuthorsRepository authorsRepository = new AuthorsRepository(context); int pagesCount = 0; int pageSize = ApplicationConfiguration.ItemsPerPage; int authorsCount = 0; authorsCount = authorsRepository.Count(filter); pagesCount = authorsCount / pageSize; if ((authorsCount % pageSize) > 0) { pagesCount++; } return(pagesCount); }
public ActionResult Details(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); BooksRepository booksRepository = new BooksRepository(context); AuthorsRepository authorsRepository = new AuthorsRepository(context); BooksDetailsVM model = new BooksDetailsVM(); this.TryUpdateModel(model); Book book = booksRepository.GetByID(id); Author author = new Author(); if (book != null) { model.ID = book.ID; model.Title = book.Title; model.Publisher = book.Publisher; model.StockCount = book.StockCount; model.DeliveryPrice = book.DeliveryPrice; model.DateReceived = book.DateReceived; model.DatePublished = book.DatePublished; model.AuthorsPager = model.AuthorsPager ?? new GenericPagerVM(); model.AuthorsPager.PagesCount = GetPagesCount(); model.AuthorsPager.CurrentPage = model.AuthorsPager.CurrentPage == 0 ? 1 : model.AuthorsPager.CurrentPage; model.Authors = authorsRepository .GetAll(model.AuthorsPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, a => a.Books.Any(b => b.ID == id), order: x => x.OrderBy(a => a.FirstName)) .ToList(); model.AuthorsPager.Action = "Details"; model.AuthorsPager.Controller = "Books"; model.AuthorsPager.Prefix = "AuthorsPager"; model.AuthorsPager.CurrentParameters = new Dictionary <string, object>() { { "AuthorsPager.CurrentPage", model.AuthorsPager.CurrentPage } }; return(View(model)); } else { return(RedirectToAction("Index", "Authors")); } }
public ActionResult Index(string sortOrder) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); AuthorsRepository authorsRepository = new AuthorsRepository(context); AuthorsIndexVM model = new AuthorsIndexVM(); this.TryUpdateModel(model); model.AuthorsPager = model.AuthorsPager ?? new GenericPagerVM(); model.AuthorsPager.CurrentPage = model.AuthorsPager.CurrentPage == 0 ? 1 : model.AuthorsPager.CurrentPage; model.AuthorsPager.Action = "Index"; model.AuthorsPager.Controller = "Authors"; model.AuthorsPager.Prefix = "AuthorsPager"; model.AuthorsPager.CurrentParameters = new Dictionary <string, object>() { { "AuthorName", model.AuthorName }, { "AuthorsPager.CurrentPage", model.AuthorsPager.CurrentPage } }; #region Sorting and Filtering Expression <Func <Author, bool> > filter = a => string.IsNullOrEmpty(model.AuthorName) || (a.FirstName.Contains(model.AuthorName) || a.LastName.Contains(model.AuthorName)); model.AuthorsPager.PagesCount = GetPagesCount(filter); ViewBag.NameSortParam = string.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; switch (sortOrder) { case "name_desc": model.AuthorsList = authorsRepository .GetAll(model.AuthorsPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderByDescending(a => a.FirstName)); break; default: model.AuthorsList = authorsRepository .GetAll(model.AuthorsPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderBy(a => a.FirstName)); break; } #endregion return(View(model)); }
public ActionResult AddBookAuthor(BooksAddBookAuthorVM model) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); BooksRepository booksRepository = new BooksRepository(context); AuthorsRepository authorsRepository = new AuthorsRepository(context); Book book = null; Author author = null; if (!ModelState.IsValid) { return View(model); } else { book = booksRepository.GetByID(model.ID); author = authorsRepository.GetByID(model.AuthorID); book.Authors.Add(author); booksRepository.Save(book); } return RedirectToAction("Details/" + model.ID, "Books"); }
public ActionResult EditAuthor(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); AuthorsRepository authorsRepository = new AuthorsRepository(context); AuthorsEditAuthorVM model = new AuthorsEditAuthorVM(); Author author = authorsRepository.GetByID(id); if (id > 0) { if (author == null) { return RedirectToAction("Index", "Authors"); } model.ID = author.ID; model.FirstName = author.FirstName; model.LastName = author.LastName; } return View(model); }
public ActionResult EditAuthor(AuthorsEditAuthorVM model) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); AuthorsRepository authorsRepository = new AuthorsRepository(context); Author author = null; if (!ModelState.IsValid) { return View(model); } else { if (model.ID > 0) { author = authorsRepository.GetByID(model.ID); } else { author = new Author(); } author.ID = model.ID; author.FirstName = model.FirstName; author.LastName = model.LastName; authorsRepository.Save(author); } return RedirectToAction("Index", "Authors"); }
public int GetPagesCount(Expression<Func<Author, bool>> filter = null) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); AuthorsRepository authorsRepository = new AuthorsRepository(context); int pagesCount = 0; int pageSize = ApplicationConfiguration.ItemsPerPage; int authorsCount = 0; authorsCount = authorsRepository.Count(filter); pagesCount = authorsCount / pageSize; if ((authorsCount % pageSize) > 0) { pagesCount++; } return pagesCount; }
public ActionResult Index(string sortOrder) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); AuthorsRepository authorsRepository = new AuthorsRepository(context); AuthorsIndexVM model = new AuthorsIndexVM(); this.TryUpdateModel(model); model.AuthorsPager = model.AuthorsPager ?? new GenericPagerVM(); model.AuthorsPager.CurrentPage = model.AuthorsPager.CurrentPage == 0 ? 1 : model.AuthorsPager.CurrentPage; model.AuthorsPager.Action = "Index"; model.AuthorsPager.Controller = "Authors"; model.AuthorsPager.Prefix = "AuthorsPager"; model.AuthorsPager.CurrentParameters = new Dictionary<string, object>() { { "AuthorName", model.AuthorName }, { "AuthorsPager.CurrentPage", model.AuthorsPager.CurrentPage } }; #region Sorting and Filtering Expression<Func<Author, bool>> filter = a => string.IsNullOrEmpty(model.AuthorName) || (a.FirstName.Contains(model.AuthorName) || a.LastName.Contains(model.AuthorName)); model.AuthorsPager.PagesCount = GetPagesCount(filter); ViewBag.NameSortParam = string.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; switch (sortOrder) { case "name_desc": model.AuthorsList = authorsRepository .GetAll(model.AuthorsPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderByDescending(a => a.FirstName)); break; default: model.AuthorsList = authorsRepository .GetAll(model.AuthorsPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderBy(a => a.FirstName)); break; } #endregion return View(model); }
public ActionResult Details(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); BooksRepository booksRepository = new BooksRepository(context); AuthorsRepository authorsRepository = new AuthorsRepository(context); BooksDetailsVM model = new BooksDetailsVM(); this.TryUpdateModel(model); Book book = booksRepository.GetByID(id); Author author = new Author(); if (book != null) { model.ID = book.ID; model.Title = book.Title; model.Publisher = book.Publisher; model.StockCount = book.StockCount; model.DeliveryPrice = book.DeliveryPrice; model.DateReceived = book.DateReceived; model.DatePublished = book.DatePublished; model.AuthorsPager = model.AuthorsPager ?? new GenericPagerVM(); model.AuthorsPager.PagesCount = GetPagesCount(); model.AuthorsPager.CurrentPage = model.AuthorsPager.CurrentPage == 0 ? 1 : model.AuthorsPager.CurrentPage; model.Authors = authorsRepository .GetAll(model.AuthorsPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, a => a.Books.Any(b => b.ID == id), order: x => x.OrderBy(a => a.FirstName)) .ToList(); model.AuthorsPager.Action = "Details"; model.AuthorsPager.Controller = "Books"; model.AuthorsPager.Prefix = "AuthorsPager"; model.AuthorsPager.CurrentParameters = new Dictionary<string, object>() { { "AuthorsPager.CurrentPage", model.AuthorsPager.CurrentPage } }; return View(model); } else { return RedirectToAction("Index", "Authors"); } }
public ActionResult Details(int id, string sortOrder) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); AuthorsRepository authorsRepository = new AuthorsRepository(context); BooksRepository booksRepository = new BooksRepository(context); AuthorsDetailsVM model = new AuthorsDetailsVM(); this.TryUpdateModel(model); Author author = authorsRepository.GetByID(id); if (author != null) { model.ID = author.ID; model.AuhtorName = author.ToString(); model.BooksPager = model.BooksPager ?? new GenericPagerVM(); model.BooksPager.CurrentPage = model.BooksPager.CurrentPage == 0 ? 1 : model.BooksPager.CurrentPage; model.BooksPager.Action = "Details"; model.BooksPager.Controller = "Authors"; model.BooksPager.Prefix = "BooksPager"; model.BooksPager.CurrentParameters = new Dictionary<string, object>() { { "BookTitle", model.BookTitle }, { "PublisherName", model.PublisherName }, { "BooksPager.CurrentPage", model.BooksPager.CurrentPage } }; #region Sorting and Filtering Expression<Func<Book, bool>> filter = b => (string.IsNullOrEmpty(model.BookTitle) || b.Title.Contains(model.BookTitle)) && (string.IsNullOrEmpty(model.PublisherName) || b.Publisher.Name.Contains(model.PublisherName)); model.BooksPager.PagesCount = GetPagesCount(filter); ViewBag.TitleSortParam = string.IsNullOrEmpty(sortOrder) ? "title_desc" : ""; ViewBag.PublisherSortParam = sortOrder == "Publisher" ? "publisher_desc" : "Publisher"; ViewBag.StockCountSortParam = sortOrder == "StockCount" ? "stockCount_desc" : "StockCount"; switch (sortOrder) { case "title_desc": model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderByDescending(b => b.Title)) .Where(b => b.Authors.Any(a => a.ID == id)) .ToList(); break; case "Publisher": model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderBy(b => b.Publisher.Name)) .Where(b => b.Authors.Any(a => a.ID == id)) .ToList(); break; case "publisher_desc": model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderByDescending(b => b.Publisher.Name)) .Where(b => b.Authors.Any(a => a.ID == id)) .ToList(); break; case "StockCount": model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderBy(b => b.StockCount)) .Where(b => b.Authors.Any(a => a.ID == id)) .ToList(); break; case "stockCount_desc": model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderByDescending(b => b.StockCount)) .Where(b => b.Authors.Any(a => a.ID == id)) .ToList(); break; default: model.Books = booksRepository .GetAll(model.BooksPager.CurrentPage, ApplicationConfiguration.ItemsPerPage, filter, order: x => x.OrderBy(b => b.Title)) .Where(b => b.Authors.Any(a => a.ID == id)) .ToList(); break; } #endregion return View(model); } else { return RedirectToAction("Index", "Authors"); } }