Exemple #1
0
        public override string ToString()
        {
            var authors    = string.Join("|", Authors.Select(e => e.Name));
            var categories = string.Join('|', BookCategories.Select(e => e.Category.Name));

            return($"Book {{ Id = {Id}, ISBN = {Identifier}, Title = {Title}, Language = {Language}, Authors = {authors}, Categories = {categories} }}");
        }
Exemple #2
0
        public bool AddCategoryDAL(BookCategories category)
        {
            bool status = false;

            try
            {
                cmd             = conn.CreateCommand();
                cmd.CommandText = "sp_AddBookCategory";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@CategoryId", category.CategoryId);
                cmd.Parameters.AddWithValue("@CategoryName", category.CategoryName);

                conn.Open();

                int count = cmd.ExecuteNonQuery();

                if (count > 0)
                {
                    status = true;
                }
            }
            catch (BookCategoriesException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return(status);
        }
        static void AddCategory()
        {
            try
            {
                BookCategories bookCategories = new BookCategories();

                Console.WriteLine("Enter Book CategoryId: ");
                bookCategories.CategoryId = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("Enter Book Category Name: ");
                bookCategories.CategoryName = Console.ReadLine();

                if (caller.AddBookCategoryBLL(bookCategories))
                {
                    Console.WriteLine("Book Category Added Successfully");
                }
                else
                {
                    Console.WriteLine("Cannot Add Category!");
                }
            }
            catch (BookCategoriesException ex)
            {
                throw ex;
            }
        }
        public void AddNewBookCategory(ActionExecutionContext context, string bookCategoryName)
        {
            if ((context.EventArgs as KeyEventArgs).Key == Key.Return && !String.IsNullOrWhiteSpace(bookCategoryName))
            {
                (context.EventArgs as KeyEventArgs).Handled = true;

                BookCategory bookCat = BookCategories.FirstOrDefault(p => p.Name.ToLower() == bookCategoryName.ToLower());
                if (bookCat != null)
                {
                    SelectedBookCategory = bookCat;
                    return;
                }

                if (MessageBox.Show(String.Format(App.GetString("AreYouSureAddCategory"), bookCategoryName), App.GetString("NewCategory"),
                                    MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                {
                    using (var dbService = _dbServiceManager.GetService())
                    {
                        BookCategory newBookCat = new BookCategory()
                        {
                            Name = bookCategoryName
                        };
                        newBookCat.Id = dbService.BookCategories.Add(newBookCat);

                        BookCategories.Add(newBookCat);
                        SelectedBookCategory = newBookCat;
                    }
                }
                else
                {
                    SelectedBookCategory = null;
                }
            }
        }
 public static void Add(BookCategories bc)
 {
     using (var db = new LibraryDBEntities())
     {
         db.BookCategories.Add(bc);
         db.SaveChanges();
     }
 }
Exemple #6
0
        public Book RemoveCategory(Category category)
        {
            var bc = BookCategories.First(e => e.Category == category);

            if (bc is not null)
            {
                BookCategories.Remove(bc);
            }
            return(this);
        }
Exemple #7
0
 /// <summary>
 /// コンストラクタ(2)
 /// </summary>
 /// <param name="id">int : ID</param>
 /// <param name="title">string : タイトル</param>
 /// <param name="author">string : 著者</param>
 /// <param name="publisher">string : 出版社</param>
 /// <param name="category">BookCategories : カテゴリー</param>
 /// <param name="price">decimal : 価格</param>
 /// <param name="purchaseDate">DateTime? : 購入日</param>
 /// <param name="reviewPoint">int : 評価点</param>
 public Book(int id, string title, string author, string publisher, BookCategories category, decimal price, DateTime?purchaseDate, int reviewPoint)
     : this()
 {
     IdProperty.Init(id);
     TitleProperty.Init(title);
     AuthorProperty.Init(author);
     PublisherProperty.Init(publisher);
     CategoryProperty.Init(category);
     PriceProperty.Init(price);
     PurchaseDateProperty.Init(purchaseDate);
     ReviewPointProperty.Init(reviewPoint);
 }
Exemple #8
0
        public bool AddBookCategoryBLL(BookCategories bookCat)
        {
            bool status = false;

            try
            {
                status = obj.AddCategoryDAL(bookCat);
            }
            catch (BooksException ex)
            {
                throw ex;
            }

            return(status);
        }
Exemple #9
0
        public void AddCategory(Category category, bool isPrimary = false)
        {
            if (IsCategoryInList(category))
            {
                throw new BookException("Category already added to this book");
            }

            if (isPrimary && BookCategories.Any(e => e.IsPrimary))
            {
                throw new BookException("Book already contains a primary category, a book can only have a single primary category");
            }

            var bc = new BookCategory(this, category, isPrimary);

            BookCategories.Add(bc);
        }
Exemple #10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            ep.Clear();
            if (txtBookType.Text.Trim().Length == 0)
            {
                ep.SetError(txtBookType, "Kitap türü boş bırakılamaz!");
                txtBookType.Focus();
                return;
            }

            BookCategories bc = new BookCategories();

            bc.Name = txtBookType.Text;

            BookCategoriesHelper.Add(bc);

            MessageBox.Show("Kitap Türü Ekleme Başarılı", "Library Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);

            txtBookType.Text = string.Empty;

            FillGrid();
        }
Exemple #11
0
 public IList <Book> GetBooks(BookCategories type) => _dal.GetBooks().Where(p => p.BookCategories == type).ToList();
Exemple #12
0
        public static string ToDisplayName(this BookCategories e)
        {
            var names = new string[] { "小説", "ノンフィクション", "漫画" };

            return(names[(int)e]);
        }
Exemple #13
0
 private bool IsCategoryInList(Category category)
 {
     return(BookCategories.Select(e => e.Category).Contains(category));
 }
 public void RemoveCategories()
 {
     BookCategories.Clear();
     Status = Status.Updated;
 }
Exemple #15
0
        public async Task <IActionResult> Index(string keywords, string bookPublisher, BookCategories category, AgeGroups ageGroup, string yearFrom, string yearTo, string sortField, int page = 1)
        {
            var user = await _userManager.GetUserAsync(User);

            var books = _context.Books
                        .Include(b => b.Answers)
                        .Include(b => b.BookRatings)
                        .AsQueryable();

            CurrentPage = page == 0 ? 1 : page;

            var publishers = books.Select(b => b.Publisher);

            if (!string.IsNullOrEmpty(keywords))
            {
                books = books.Where(b => b.Title.ToUpper().Contains(keywords.ToUpper()) ||
                                    b.BookAuthor.ToUpper().Contains(keywords.ToUpper()) ||
                                    b.Isbn1.ToUpper().Contains(keywords.ToUpper()) ||
                                    b.Publisher.ToUpper().Contains(keywords.ToUpper()) ||
                                    b.Isbn2.ToUpper().Contains(keywords.ToUpper()));
            }

            if (!string.IsNullOrEmpty(bookPublisher))
            {
                books = books.Where(b => b.Publisher == bookPublisher);
            }

            if (category != 0)
            {
                books = books.Where(b => b.BookCategory == category);
            }

            if (ageGroup != 0)
            {
                books = books.Where(b => b.AgeGroup == ageGroup);
            }

            if (!string.IsNullOrEmpty(yearFrom) && int.TryParse(yearFrom, out int n))
            {
                books = books.Where(b => int.Parse(b.YearPublished) >= n);
            }

            if (!string.IsNullOrEmpty(yearTo) && int.TryParse(yearTo, out int m))
            {
                books = books.Where(b => int.Parse(b.YearPublished) <= m);
            }

            switch (sortField)
            {
            case "latest":
                books = books.OrderByDescending(b => b.DateAdded);
                break;

            case "rating":
                books = books.OrderByDescending(b => b.AverageRating);
                break;

            case "views":
                books = books.OrderByDescending(b => b.Answers.Count);
                break;

            case "class":
                books = books.OrderBy(b => b.Grade);
                break;

            case "year":
                books = books.OrderBy(b => b.YearPublished);
                break;

            case "title":
                books = books.OrderBy(b => b.Title);
                break;

            case "author":
                books = books.OrderBy(b => b.BookAuthor);
                break;

            default:
                books = books.OrderByDescending(b => b.DateAdded);
                break;
            }

            Count = books.Count();

            if (CurrentPage > TotalPages)
            {
                CurrentPage = TotalPages;
            }

            var indexVm = new IndexBookViewModel()
            {
                Books = await books.Skip((CurrentPage - 1) *PageSize)
                        .Take(PageSize)
                        .ToListAsync(),

                Publishers = new SelectList(await publishers.Distinct().ToListAsync()),

                CurrentPage    = CurrentPage,
                Count          = Count,
                PageSize       = PageSize,
                TotalPages     = TotalPages,
                EnablePrevious = EnablePrevious,
                EnableNext     = EnableNext
            };

            if (User.Identity.IsAuthenticated)
            {
                var booksIds = _context.MarkedBooks
                               .Where(mb => mb.UserId == user.Id)
                               .Select(mb => mb.BookId).ToList();

                indexVm.BooksIds = booksIds;
            }
            return(View(indexVm));
        }