Пример #1
0
        public IActionResult Index()
        {
            if (!Middleware.CheckUserPermission(PermissionType.None, HttpContext))
            {
                return(RedirectToAction("Login", "User"));
            }

            BookIndexViewModel bivm = new BookIndexViewModel();

            bivm.Books = new List <BookModel>();

            foreach (Book book in BookContainer.GetNewestBooks(8))
            {
                BookModel temp = new BookModel();

                temp.Id            = book.Id;
                temp.Name          = book.Name;
                temp.Price         = book.Price;
                temp.QualityRating = book.QualityRating;

                bivm.Books.Add(temp);
            }

            return(View(bivm));
        }
Пример #2
0
        public async static Task<BookContainer> GetFromStorageFolder(Windows.Storage.StorageFolder folder, string Token = null, string[] Path = null)
        {
            var result = new BookContainer();
            result.Title = folder.DisplayName;

            List<string> path = (Path ?? new string[0]).ToList();
            if (Token == null)
            {
                Token = Books.BookManager.StorageItemRegister(folder);
            }
            else
            {
                path.Add(folder.Name);
            }

            foreach (var item in await folder.GetFoldersAsync())
            {
                var f = await GetFromStorageFolder(item, Token, path.ToArray());
                if (!f.IsEmpty())
                {
                    result.Folders.Add(f);
                }
            }

            foreach (var item in await folder.GetFilesAsync())
            {
                var f = await GetFromStorageFile(item, Token, path.ToArray());
                if (f != null)
                {
                    result.Files.Add(f);
                }
            }

            return result;
        }
Пример #3
0
        public IActionResult Edit(int id)
        {
            if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext))
            {
                return(RedirectToAction("Login", "User"));
            }

            Book book = BookContainer.GetBookById(id);

            // FIXME: Hoe kan dit beter?
            BookModel bookModel = new BookModel();

            bookModel.Id = book.Id;

            bookModel.User           = new UserModel();
            bookModel.User.Id        = book.User.Id;
            bookModel.User.FirstName = book.User.FirstName;
            bookModel.User.Insertion = book.User.Insertion;
            bookModel.User.LastName  = book.User.LastName;
            bookModel.User.Email     = book.User.Email;

            bookModel.Course      = new CourseModel();
            bookModel.Course.Id   = book.Course.Id;
            bookModel.Course.Name = book.Course.Name;

            bookModel.Sector      = new SectorModel();
            bookModel.Sector.Id   = book.Sector.Id;
            bookModel.Sector.Name = book.Sector.Name;

            bookModel.Name          = book.Name;
            bookModel.Price         = book.Price;
            bookModel.QualityRating = book.QualityRating;

            return(View(bookModel));
        }
        public override BookContainer <Detective> GetAll(string type = null, BookContainer <Detective> section = null, int?sectionId = null)
        {
            DetectiveSection books = new DetectiveSection();

            base.GetAll("Detective", books, 1);

            return(GetDetectives(books, type, section, sectionId));
        }
Пример #5
0
        public override BookContainer <SpecialLiterature> GetAll(string type = null, BookContainer <SpecialLiterature> section = null, int?sectionId = null)
        {
            SpecialLiteratureSection books = new SpecialLiteratureSection();

            base.GetAll("SpecialLiterature", books, 2);

            return(GetSpecialLiterature(books, type, section, sectionId));
        }
        public override BookContainer <Schoolbook> GetAll(string type = null, BookContainer <Schoolbook> section = null, int?sectionId = null)
        {
            SchoolbookSection books = new SchoolbookSection();

            base.GetAll("Schoolbook", books, 3);

            return(GetSchoolbooks(books, type, section, sectionId));
        }
Пример #7
0
        static void Main(string[] args)
        {
            BookContainerStub bookContainerStub = new BookContainerStub();
            BookContainer     bookContainer     = new BookContainer(bookContainerStub);

            bookContainerStub.Testvalue = true;
            Book book = new Book();

            book.author = new Author();
            bookContainer.AddBook(book);
        }
Пример #8
0
        public IActionResult Create(BookModel book)
        {
            if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext))
            {
                return(RedirectToAction("Login", "User"));
            }

            BookContainer.Save(book);

            return(RedirectToAction("Index"));
        }
    void LoadBookList()
    {
        _container = new BookContainer();
        var idList = BookLoader.LoadBookIdList();

        foreach (var id in idList)
        {
            if (!id.Equals(String.Empty))
            {
                AddBook(id);
            }
        }
    }
Пример #10
0
        public static BookShelf GetFlatBookShelf(BookContainer shelf)
        {
            var result = new BookShelf();

            if (shelf.Files.Count > 0)
            {
                result.Folders.Add(shelf);
            }
            result.Title = shelf.Title;

            foreach (var item in shelf.Folders)
            {
                result.Folders.AddRange(GetFlatBookShelf(item).Folders);
            }
            shelf.Folders = new List <BookContainer>();
            return(result);
        }
Пример #11
0
        public IActionResult Remove(int id)
        {
            if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext))
            {
                return(RedirectToAction("Login", "User"));
            }

            if (BookContainer.Remove(id, SessionHandler.GetUserID(HttpContext)))
            {
                // TODO: Add message
            }
            else
            {
                // TODO: Add message
            }

            return(RedirectToAction("Index"));
        }
Пример #12
0
        public IActionResult Index()
        {
            if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext))
            {
                return(RedirectToAction("Login", "User"));
            }

            BookIndexViewModel bivm = new BookIndexViewModel();

            bivm.Books = new List <BookModel>();

            foreach (Book book in BookContainer.GetAllBooks())
            {
                // FIXME: Dit moet beter kunnen.
                BookModel temp = new BookModel();

                temp.Id = book.Id;

                temp.User           = new UserModel();
                temp.User.Id        = book.User.Id;
                temp.User.FirstName = book.User.FirstName;
                temp.User.Insertion = book.User.Insertion;
                temp.User.LastName  = book.User.LastName;
                temp.User.Email     = book.User.Email;

                temp.Course      = new CourseModel();
                temp.Course.Id   = book.Course.Id;
                temp.Course.Name = book.Course.Name;

                temp.Sector      = new SectorModel();
                temp.Sector.Id   = book.Sector.Id;
                temp.Sector.Name = book.Sector.Name;

                temp.Name          = book.Name;
                temp.Price         = book.Price;
                temp.QualityRating = book.QualityRating;

                bivm.Books.Add(temp);
            }

            return(View(bivm));
        }
Пример #13
0
        private BookContainer <T> GetBooks(string type, BookContainer <T> section, int?sectionId, string query = GetAllBooksQuery)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("@id", sectionId);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        BookContainer <T> books = section;

                        while (reader.Read())
                        {
                            T book = (T)Activator.CreateInstance(Type.GetType("HomeLibrary.Entities." + type));

                            book.Id                      = (int)reader["id"];
                            book.Author                  = (string)reader["author"];
                            book.Title                   = (string)reader["title"];
                            book.Edition                 = (string)reader["edition"];
                            book.Year                    = (int)reader["year"];
                            book.Pages                   = (int)reader["pages"];
                            book.Section.Name            = (string)reader["name"];
                            book.Estimate.Origin         = (string)reader["origin"];
                            book.Estimate.Availability   = (bool)reader["availability"];
                            book.Estimate.Worth          = (string)reader["worth"];
                            book.Estimate.Recommendation = (string)reader["recommendation"];

                            books.Books.Add(book);
                        }

                        books.BooksCount = books.Books.Count;

                        return(books);
                    }
                }
            }
        }
Пример #14
0
        public static async Task <BookContainer> GetFromStorageFolder(Windows.Storage.StorageFolder folder, string Token = null, string[] Path = null)
        {
            var result = new BookContainer();

            result.Title = folder.DisplayName;

            List <string> path = (Path ?? new string[0]).ToList();

            if (Token == null)
            {
                Token = Books.BookManager.StorageItemRegister(folder);
            }
            else
            {
                path.Add(folder.Name);
            }

            foreach (var item in await folder.GetFoldersAsync())
            {
                var f = await GetFromStorageFolder(item, Token, path.ToArray());

                if (!f.IsEmpty())
                {
                    result.Folders.Add(f);
                }
            }

            foreach (var item in await folder.GetFilesAsync())
            {
                var f = await GetFromStorageFile(item, Token, path.ToArray());

                if (f != null)
                {
                    result.Files.Add(f);
                }
            }

            return(result);
        }
Пример #15
0
 public BookController(IBookContainersDAL ibookContainerDAL)
 {
     bookValidator = new BookValidator();
     bookContainer = new BookContainer(ibookContainerDAL);
 }
Пример #16
0
        public static BookShelf GetFlatBookShelf(BookContainer shelf)
        {
            var result = new BookShelf();
            if (shelf.Files.Count > 0)
            {
                result.Folders.Add(shelf);
            }
            result.Title = shelf.Title;

            foreach (var item in shelf.Folders)
            {
                result.Folders.AddRange(GetFlatBookShelf(item).Folders);
            }
            shelf.Folders = new List<BookContainer>();
            return result;
        }
Пример #17
0
        public virtual BookContainer <T> Search(string text, BookFilter filter, string type, BookContainer <T> section, int?sectionId)
        {
            string SearchQuery = "";

            switch (filter)
            {
            case BookFilter.Author:
                SearchQuery = string.Concat(SearchBookQuery, "author LIKE '%", text, "%'");
                break;

            case BookFilter.Title:
                SearchQuery = string.Concat(SearchBookQuery, "title LIKE '%", text, "%'");
                break;

            case BookFilter.Edition:
                SearchQuery = string.Concat(SearchBookQuery, "edition LIKE '%", text, "%'");
                break;

            default:
                break;
            }

            return(GetBooks(type, section, sectionId, SearchQuery));
        }
Пример #18
0
        private BookContainer <SpecialLiterature> GetSpecialLiterature(SpecialLiteratureSection books, string type, BookContainer <SpecialLiterature> section, int?sectionId, string query = GetAllSpecialLiteratureQuery)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var bookId = (int)reader["id"];

                            if (books.Books.FirstOrDefault(b => b.Id == bookId) != null)
                            {
                                books.Books.First(b => b.Id == bookId).Field = (string)reader["field"];
                            }
                        }
                        return(books);
                    }
                }
            }
        }
        private BookContainer <Detective> GetDetectives(DetectiveSection books, string type, BookContainer <Detective> section, int?sectionId, string query = GetAllDetectivesQuery)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var bookId = (int)reader["id"];

                            if (books.Books.FirstOrDefault(b => b.Id == bookId) != null)
                            {
                                books.Books.First(b => b.Id == bookId).HeroesNumber = (int)reader["heroes_number"];
                            }
                        }
                        return(books);
                    }
                }
            }
        }
        public override BookContainer <Detective> Search(string text, BookFilter filter, string type = null, BookContainer <Detective> section = null, int?sectionId = null)
        {
            DetectiveSection books = new DetectiveSection();

            base.Search(text, filter, "Detective", books, 1);

            return(GetDetectives(books, type, section, sectionId));
        }
Пример #21
0
 public void Testinitialize()
 {
     bookContainerStub = new BookContainerStub();
     bookContainer     = new BookContainer(bookContainerStub);
 }
Пример #22
0
        public override BookContainer <SpecialLiterature> Search(string text, BookFilter filter, string type = null, BookContainer <SpecialLiterature> section = null, int?sectionId = null)
        {
            SpecialLiteratureSection books = new SpecialLiteratureSection();

            base.Search(text, filter, "SpecialLiterature", books, 2);

            return(GetSpecialLiterature(books, type, section, sectionId));
        }
        public override BookContainer <Schoolbook> Search(string text, BookFilter filter, string type = null, BookContainer <Schoolbook> section = null, int?sectionId = null)
        {
            SchoolbookSection books = new SchoolbookSection();

            base.Search(text, filter, "Schoolbook", books, 3);

            return(GetSchoolbooks(books, type, section, sectionId));
        }
        private BookContainer <Schoolbook> GetSchoolbooks(SchoolbookSection books, string type, BookContainer <Schoolbook> section, int?sectionId, string query = GetAllSchoolbooksQuery)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var bookId = (int)reader["id"];

                            if (books.Books.FirstOrDefault(b => b.Id == bookId) != null)
                            {
                                books.Books.First(b => b.Id == bookId).Form    = (int)reader["form"];
                                books.Books.First(b => b.Id == bookId).Subject = (string)reader["subject"];
                            }
                        }
                        return(books);
                    }
                }
            }
        }
Пример #25
0
 public virtual BookContainer <T> GetAll(string type, BookContainer <T> section, int?sectionId)
 {
     return(GetBooks(type, section, sectionId));
 }