Beispiel #1
0
        public List <BooksViewModel> booksViews(LibraryContext _context)
        {
            List <BooksViewModel> books = new List <BooksViewModel>();

            var libraryContext = _context.Book.Include(b => b.Author);

            foreach (var book in libraryContext)
            {
                BooksViewModel model  = new BooksViewModel();
                AuthorDropDown author = new AuthorDropDown();
                author.Author = book.Author.Name + book.Author.Surname;
                model.Author  = author;

                model.BookId      = book.BookId;
                model.BookType    = book.BookType;
                model.Description = book.Description;
                model.Title       = book.Title;

                var lease = _context.Lease.Where(l => l.BookId == book.BookId).FirstOrDefault();
                if (lease == null)
                {
                    model.Availability = "Dostępna";
                }
                else
                {
                    model.Availability = "Wypożyczona";
                }
                books.Add(model);
            }
            return(books);
        }
Beispiel #2
0
        public List <AuthorDropDown> GetAuthors(LibraryContext _context)
        {
            var authorList = (from Author in _context.Author select Author).ToList();
            List <AuthorDropDown> authors = new List <AuthorDropDown>();

            foreach (var author in authorList)
            {
                AuthorDropDown authorDropDown = new AuthorDropDown();
                authorDropDown.Author = author.Name + author.Surname;
                authorDropDown.ID     = author.AuthorId;

                authors.Add(authorDropDown);
            }
            return(authors);
        }
Beispiel #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!User.IsInRole("Librarian"))
     {
         Response.Redirect(SitePages.GetUrl(LibraryPage.NotAuthorized));
     }
     if (!IsPostBack)
     {
         AuthorDropDown.ListDataSource = () =>
         {
             DataTable dt = DatabaseHelper.Retrieve(GetAuthorsQuery);
             AuthorDropDown.SetTextAndValueFields("AuthorName", "Id");
             return(dt);
         };
     }
 }
Beispiel #4
0
        public BooksViewModel getBookDetails(LibraryContext _context, int?id)
        {
            var            book   = _context.Book.FindAsync(id);
            var            author = _context.Author.Find(book.Result.AuthorId);
            BooksViewModel model  = new BooksViewModel();

            AuthorDropDown authorModel = new AuthorDropDown();

            authorModel.Author = author.Name + author.Surname;
            authorModel.ID     = author.AuthorId;
            model.Author       = authorModel;

            model.Title       = book.Result.Title;
            model.BookId      = book.Result.BookId;
            model.BookType    = book.Result.BookType;
            model.Description = book.Result.Description;

            return(model);
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.IsInRole("Librarian"))
            {
                Response.Redirect(SitePages.GetUrl(LibraryPage.NotAuthorized));
            }
            if (!int.TryParse(Request.QueryString["ID"], out bookId))
            {
                Response.Redirect(BooksUrl);
            }

            if (!IsPostBack)
            {
                AuthorDropDown.ListDataSource = () =>
                {
                    DataTable authorsTable = DatabaseHelper.Retrieve(GetAuthorsQuery);
                    AuthorDropDown.SetTextAndValueFields("AuthorName", "Id");
                    return(authorsTable);
                };
                DataTable bookTable = DatabaseHelper.Retrieve(
                    GetBookQuery,
                    new SqlParameter("@BookId", bookId));

                if (bookTable.Rows.Count == 1)
                {
                    string oldTitle    = bookTable.Rows[0].Field <string>("Title");
                    string oldAuthor   = bookTable.Rows[0].Field <string>("AuthorName");
                    string oldIsbn     = bookTable.Rows[0].Field <string>("Isbn");
                    int    oldAuthorId = bookTable.Rows[0].Field <int>("AuthorId");
                    OldTitle.Text                = oldTitle;
                    OldAuthor.Text               = oldAuthor;
                    OldIsbn.Text                 = oldIsbn;
                    TitleTextBox.Text            = oldTitle;
                    AuthorDropDown.SelectedValue = oldAuthorId.ToString();
                    IsbnTextBox.Text             = oldIsbn;
                }
                else
                {
                    Response.Redirect(BooksUrl);
                }
            }
        }