Example #1
0
        void Load_cmbAcctType()
        {
            List <BookDto> bookList = new List <BookDto>();

            bookList = BookDao.GetAll();

            List <ComboItems> _ItemList = new List <ComboItems>();

            ComboItems Item;

            Item = new ComboItems();
            Item.DisplayMember = "Select";
            Item.ValueMember   = "-1";
            _ItemList.Add(Item);

            foreach (BookDto book in bookList)
            {
                Item = new ComboItems();
                Item.DisplayMember = book.BookName;
                Item.ValueMember   = book.BookID.ToString();
                _ItemList.Add(Item);
            }


            cmbBooks.DataSource    = _ItemList;
            cmbBooks.DisplayMember = "DisplayMember";
            cmbBooks.ValueMember   = "ValueMember";
            cmbBooks.SelectedValue = "-1";
        }
Example #2
0
        private void LoadGride()
        {
            dgvBookList.Rows.Clear();
            dgvBookList.Columns.Clear();

            dgvBookList.Columns.Add("BookID", "");
            dgvBookList.Columns.Add("BookName", "Book Name");
            dgvBookList.Columns.Add("AuthorName", "Author Name");
            dgvBookList.Columns.Add("ReleaseYear", "Release Year");
            dgvBookList.Columns.Add("Remarks", "Remarks");

            dgvBookList.Columns["BookName"].Width    = 150;
            dgvBookList.Columns["AuthorName"].Width  = 100;
            dgvBookList.Columns["ReleaseYear"].Width = 100;
            dgvBookList.Columns["Remarks"].Width     = 100;


            dgvBookList.Columns["BookID"].Visible = false;
            List <BookDto> bookList = new List <BookDto>();

            try
            {
                bookList = BookDao.GetAll();
            }
            catch (Exception ex) { }


            if (bookList.Count > 0)
            {
                for (int i = 0; i < bookList.Count; i++)
                {
                    dgvBookList.Rows.Add();
                    dgvBookList.Rows[i].Cells["BookID"].Value      = bookList[i].BookID;
                    dgvBookList.Rows[i].Cells["BookName"].Value    = bookList[i].BookName;
                    dgvBookList.Rows[i].Cells["AuthorName"].Value  = bookList[i].AuthorName;
                    dgvBookList.Rows[i].Cells["ReleaseYear"].Value = bookList[i].ReleseYear;
                    dgvBookList.Rows[i].Cells["Remarks"].Value     = bookList[i].Remarks;
                }
            }
        }
Example #3
0
        public ActionResult Rate(int id, int moznost)
        {
            int value = 0;

            BookLikesDao      bookLikesDao = new BookLikesDao();
            IList <BookLikes> list         = bookLikesDao.GetAll();

            BookDao      bookDao = new BookDao();
            IList <Book> books   = bookDao.GetAll();

            BookLikes finalBL = null;
            int       UserId  = new KnihovnaUserDao().GetByLogin(User.Identity.Name).Id;


            foreach (BookLikes bl in list)
            {
                if (bl.UserId == UserId && bl.BookId == id)
                {
                    finalBL = bl;
                    break;
                }
            }

            if (finalBL == null)
            {
                value = 1;
            }
            else
            {
                value = -1;
            }

            // Like
            if (value == 1)
            {
                if (finalBL == null)
                {
                    BookLikes like = new BookLikes();
                    like.Value  = moznost;
                    like.UserId = new KnihovnaUserDao().GetByLogin(User.Identity.Name).Id;
                    like.BookId = id;

                    bookLikesDao.Create(like);
                }
            }
            else if (value == -1) // Unlike
            {
                foreach (BookLikes bl in list)
                {
                    if (bl.UserId == UserId && bl.BookId == id)
                    {
                        finalBL = bl;
                        break;
                    }
                }

                if (finalBL != null)
                {
                    bookLikesDao.Delete(finalBL);
                }
            }

            if (User.Identity.IsAuthenticated)
            {
                foreach (Book b in books)
                {
                    if (CurrentUserRatedBook(b))
                    {
                        b.RateValue = -1;
                    }
                    else
                    {
                        b.RateValue = 1;
                    }
                }
            }

            List <Book> fb = books as List <Book>;

            if (Request.IsAjaxRequest())
            {
                return(PartialView("Index", fb));
            }

            // return RedirectToAction("Index");
            return(View("Index", fb));
        }
        void Start()
        {
            CustomerDao     customerDao = new CustomerDao();
            List <Customer> customers   = customerDao.GetAll();

            BookDao     bookDao = new BookDao();
            List <Book> books   = bookDao.GetAll();

            foreach (var customer in customers)
            {
                Console.WriteLine(customer.ToString());
            }

            Console.Write("\nEnter customer id: ");
            int id;

            if (Int32.TryParse(Console.ReadLine(), out id))
            {
                Customer c = customerDao.GetById(id);
                if (c == null)
                {
                    Console.WriteLine($"No customer with id {id}");
                }
                else
                {
                    Console.WriteLine(c);
                }
            }
            else
            {
                Console.WriteLine("invalid id");
            }

            Console.WriteLine();

            foreach (var book in books)
            {
                Console.WriteLine(book.ToString());
            }

            Console.Write("\nEnter book id: ");

            if (Int32.TryParse(Console.ReadLine(), out id))
            {
                Book b = bookDao.GetById(id);
                if (b == null)
                {
                    Console.WriteLine($"No book with id {id}");
                }
                else
                {
                    Console.WriteLine(b);
                }
            }
            else
            {
                Console.WriteLine("invalid id");
            }

            Console.ReadKey();
        }