Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
 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));
     }
 }
Esempio n. 4
0
        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"));
        }
Esempio n. 7
0
        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"));
        }
Esempio n. 9
0
 public DetailsModel(BookLibraryDbContext context) : base(context)
 {
 }
Esempio n. 10
0
 public IndexModel(BookLibraryDbContext db)
 {
     this.db = db;
 }
Esempio n. 11
0
 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;
 }
Esempio n. 13
0
 public BooksController(BookLibraryDbContext dbContext)
 {
     this.DbContext = dbContext;
 }
Esempio n. 14
0
 public MovieLoansController(BookLibraryDbContext db) : base(db)
 {
 }
Esempio n. 15
0
 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;
 }
Esempio n. 16
0
 public IndexModel(BookLibraryDbContext context) : base(context)
 {
 }
Esempio n. 17
0
 public BaseController(BookLibraryDbContext context)
 {
     this.Context = context;
 }
Esempio n. 18
0
 public DetailsModel(BookLibraryDbContext db) : base(db)
 {
 }
Esempio n. 19
0
 public BaseContextModel(BookLibraryDbContext context)
 {
     this.Context = context;
 }
 public AddModel(BookLibraryDbContext db)
 {
     this.db = db;
 }
Esempio n. 21
0
 public StatusModel(BookLibraryDbContext context)
     : base(context)
 {
 }
 public UsersController(BookLibraryDbContext db)
 {
     this.db = db;
 }
Esempio n. 23
0
 public ListModel(BookLibraryDbContext db) : base(db)
 {
 }
Esempio n. 24
0
 public DirectorsController(BookLibraryDbContext db) : base(db)
 {
 }
Esempio n. 25
0
 public SearchModel(BookLibraryDbContext db)
 {
     this.db      = db;
     this.Results = new List <SearchResult>();
 }
Esempio n. 26
0
 public ReturnModel(BookLibraryDbContext context)
     : base(context)
 {
 }
 public SearchModel(BookLibraryDbContext db)
 {
     this.db = db;
 }
Esempio n. 28
0
 public BookController(BookLibraryDbContext context)
 {
     _context = context;
 }
Esempio n. 29
0
 public PageModelWithDb(BookLibraryDbContext db)
 {
     this.db = db;
 }
Esempio n. 30
0
 public AddModel(BookLibraryDbContext db) : base(db)
 {
     this.Loan = new AddLoanBindingModel();
 }