Beispiel #1
0
        public async Task <ActionResult> Create([Bind(Include = "LibraryBookSId,MemberId,WhenSignedOut,WhenReturned")] BookSignedOut bookSignedOut)
        {
            /*
             * 5.Enforce this restriction No member can have more than two books signed out of the library at any one time.
             */

            if (db.Members
                .Include(m => m.BookSignedOuts)
                .First(m => m.MemberId == bookSignedOut.MemberId)
                .BookSignedOuts.Any(so => so.WhenReturned == null))
            {
                ModelState.AddModelError("", "Let the user sign out one book at a time");
            }

            if (ModelState.IsValid)
            {
                db.BookSignedOuts.Add(bookSignedOut);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "Libraries"));
            }

            ViewBag.MemberId = new SelectList(db.Members, "MemberId", "FullName", bookSignedOut.MemberId);
            return(View(bookSignedOut));
        }
        public async Task <ActionResult> Create([Bind(Include = "MemberId,FullName,PostalCode")] Member member)
        {
            if (ModelState.IsValid)
            {
                db.Members.Add(member);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(member));
        }
Beispiel #3
0
        public async Task <ActionResult> Create([Bind(Include = "BookId,Title,ISBN,DateOfPublication")] BookTitle bookTitle)
        {
            if (ModelState.IsValid)
            {
                db.BookTitles.Add(bookTitle);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(bookTitle));
        }