コード例 #1
0
ファイル: BookController.cs プロジェクト: PPRO/projectBlog
        public ActionResult DeleteBook(int id)
        {
            try
            {
                BookDao bookDao = new BookDao();
                Book book = bookDao.GetById(id);

                if ( book.ImageName != null )
                    System.IO.File.Delete(Server.MapPath("~/image/articleImage/" + book.ImageName));

                bookDao.Delete(book);

                TempData["message-success"] = "Článek" + book.Title + "byla smazan.";

            }
            catch ( Exception exception )
            {

                throw;
            }

            return RedirectToAction("Index");
        }
コード例 #2
0
        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();
        }