コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            BookSubject bookSubject = db.BookSubjects.Find(id);

            db.BookSubjects.Remove(bookSubject);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "BookSubjectID,BookID,SubjectID")] BookSubject bookSubject)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookSubject).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BookID    = new SelectList(db.Books, "BookID", "Title", bookSubject.BookID);
     ViewBag.SubjectID = new SelectList(db.Subjects, "SubjectID", "SubjectName", bookSubject.SubjectID);
     return(View(bookSubject));
 }
コード例 #3
0
        static void Main(string[] args)
        {
            CreateSection("Singletons");

            Singleton s1 = Singleton.Instance();
            Singleton s2 = Singleton.Instance();

            if (s1 == s2)
            {
                Console.WriteLine("Objects are the same instance.");
            }
            EndSection();

            CreateSection("Prototypes");

            var p1 = new ConcretePrototype1(1);

            Console.WriteLine("Original ID: {0}", p1.Id);

            var c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned ID: {0}", c1.Id);

            EndSection();

            CreateSection("Factory");

            var creators = new Creator[2];

            creators[0] = new ConcreteCreator();
            creators[1] = new ConcreteCreator2();

            foreach (Creator creator in creators)
            {
                Product product = creator.FactoryMethod();

                Console.WriteLine("Created {0}", product.GetType().Name);
            }

            EndSection();

            CreateSection("Observer pattern");

            var bookSubject = new BookSubject("Gone Girl", "True Crime");

            bookSubject.Attach(new ConcreteObserver("The Librarian"));

            bookSubject.SubjectType = "Horror";
            bookSubject.SubjectType = "Romance";

            Console.ReadKey();
        }
コード例 #4
0
        // GET: BookSubjects/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookSubject bookSubject = db.BookSubjects.Find(id);

            if (bookSubject == null)
            {
                return(HttpNotFound());
            }
            return(View(bookSubject));
        }
コード例 #5
0
        // GET: BookSubjects/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookSubject bookSubject = db.BookSubjects.Find(id);

            if (bookSubject == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BookID    = new SelectList(db.Books, "BookID", "Title", bookSubject.BookID);
            ViewBag.SubjectID = new SelectList(db.Subjects, "SubjectID", "SubjectName", bookSubject.SubjectID);
            return(View(bookSubject));
        }
コード例 #6
0
        public async Task AddSubjectToBook(int bookId, int subjectId)
        {
            Book book = await _context.Books.Include(b => b.BookSubjects).ThenInclude(bs => bs.Subject)
                        .FirstOrDefaultAsync(b => b.Id == bookId);

            Subject subject = await _context.Subjects.FindAsync(subjectId);

            BookSubject bookSubject = new BookSubject
            {
                Book    = book,
                Subject = subject
            };
            await _context.BookSubjects.AddAsync(bookSubject);

            await _context.SaveChangesAsync();
        }