public IActionResult Index(BookLibraryDbContext db) { using (db) { var books = db.Books.Select(b => new { b.Id, b.Title, b.AuthorId, AuthorName = b.Author.Name, b.Loans }).ToList(); var bookViews = new List <BookViewModel>(books.Count); foreach (var book in books) { var loans = book.Loans; string status = "At home"; if (loans.Any(l => l.IsReturned == false)) { status = "Borrowed"; } var model = new BookViewModel() { Id = book.Id, Title = book.Title, AuthorId = book.AuthorId, Author = book.AuthorName, Status = status }; bookViews.Add(model); } return(View(bookViews)); } }
public WriteBookRepository(BookLibraryDbContext ctx, IMapper mapper) { this._ctx = ctx; this.mapper = mapper; _books = _ctx.Set <Book>(); _booksAsNoTracking = _ctx.Set <Book>().AsNoTracking(); }
public IActionResult Index() { using (var db = new BookLibraryDbContext()) { var books = db.Books.ToList(); return(View(books)); } }
public static void Main(string[] args) { using (var dbContext = new BookLibraryDbContext()) { dbContext.Database.Migrate(); } CreateWebHostBuilder(args).Build().Run(); }
public IActionResult Delete(int id) { using (var db = new BookLibraryDbContext()) { Book currentBook = db.Books.Find(id); return(View(currentBook)); } }
public IActionResult Delete(Book book) { using (var db = new BookLibraryDbContext()) { db.Books.Remove(book); db.SaveChanges(); } return(RedirectToAction("Index")); }
protected override void Seed(BookLibraryDbContext context) { this.userManager = new UserManager <User>(new UserStore <User>(context)); context.Roles.AddOrUpdate(x => x.Name, new IdentityRole("Admin")); context.Roles.AddOrUpdate(x => x.Name, new IdentityRole("User")); context.SaveChanges(); var defaultUser = new User { Email = "*****@*****.**", UserName = "******" }; this.userManager.Create(defaultUser, "diMANA123"); this.userManager.AddToRole(defaultUser.Id, "User"); var adminUser = new User { Email = "*****@*****.**", UserName = "******" }; this.userManager.Create(adminUser, "diMANA123"); this.userManager.AddToRole(adminUser.Id, "Admin"); Genre genreAction = new Genre { GenreName = "Action" }; Genre genreDrama = new Genre { GenreName = "Drama" }; Genre genreAdventure = new Genre { GenreName = "Adventure" }; context.Genres.AddOrUpdate(genreAction, genreDrama, genreAdventure); Author teryPratched = new Author { FirstName = "Author", LastName = "Demo" }; Author ivanPetrov = new Author { FirstName = "Ivan", LastName = "Petrov" }; context.Books.AddOrUpdate( new Book { Title = "Demo Book One", ReleaseDate = DateTime.Now, Autors = { teryPratched, ivanPetrov }, Description = "some description for test", Genre = genreAction }, new Book { Title = "Test Boom Two", ReleaseDate = DateTime.Now, Autors = { teryPratched }, Description = "some description for test for", Genre = genreAdventure } ); context.SaveChanges(); }
public IActionResult Edit(Book book) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } using (var db = new BookLibraryDbContext()) { db.Books.Update(book); db.SaveChanges(); } return(RedirectToAction("Index")); }
public DetailsModel(BookLibraryDbContext context) : base(context) { }
public IndexModel(BookLibraryDbContext db) { this.db = db; }
public SearchModel(BookLibraryDbContext context) : base(context) { this.SearchResults = new List <BookAndAuthorSearchViewModel>(); }
public JwtService(IOptions <JwtConfigs> configs, BookLibraryDbContext ctx, UserManager <User> userManager) { this.configs = configs; this.ctx = ctx; this.userManager = userManager; }
public BooksController(BookLibraryDbContext dbContext) { this.DbContext = dbContext; }
public MovieLoansController(BookLibraryDbContext db) : base(db) { }
public BorrowModel(BookLibraryDbContext context) : base(context) { this.Borrowers = this.Context.Borrowers.Select(b => new SelectListItem(b.Name, b.Id.ToString())).ToList(); this.BorrowDate = this.DateNow; }
public IndexModel(BookLibraryDbContext context) : base(context) { }
public BaseController(BookLibraryDbContext context) { this.Context = context; }
public DetailsModel(BookLibraryDbContext db) : base(db) { }
public BaseContextModel(BookLibraryDbContext context) { this.Context = context; }
public AddModel(BookLibraryDbContext db) { this.db = db; }
public StatusModel(BookLibraryDbContext context) : base(context) { }
public UsersController(BookLibraryDbContext db) { this.db = db; }
public ListModel(BookLibraryDbContext db) : base(db) { }
public DirectorsController(BookLibraryDbContext db) : base(db) { }
public SearchModel(BookLibraryDbContext db) { this.db = db; this.Results = new List <SearchResult>(); }
public ReturnModel(BookLibraryDbContext context) : base(context) { }
public SearchModel(BookLibraryDbContext db) { this.db = db; }
public BookController(BookLibraryDbContext context) { _context = context; }
public PageModelWithDb(BookLibraryDbContext db) { this.db = db; }
public AddModel(BookLibraryDbContext db) : base(db) { this.Loan = new AddLoanBindingModel(); }