Beispiel #1
0
        public ActionResult CheckOutBook(int serial)
        {
            // Encapsulate in try/catch block in case of error
            try
            {
                using (Team6LibraryContext db = new Team6LibraryContext())
                {
                    // Create the CheckedOut object
                    CheckedOut checkedOut = new CheckedOut()
                    {
                        CardNum = (uint)card, Serial = (uint)serial
                    };

                    // Add and save the new entry
                    db.CheckedOut.Add(checkedOut);
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                // In case of exception, write it to debug in addition to throwing it
                System.Diagnostics.Debug.WriteLine(e);
                throw e;
            }

            // Placeholder
            return(Json(new { success = true }));
        }
Beispiel #2
0
        public ActionResult ReturnBook(int serial)
        {
            // You may have to cast serial to a (uint)
            try
            {
                using (Team6LibraryContext db = new Team6LibraryContext())
                {
                    // Create the CheckedOut object
                    CheckedOut checkedOut = new CheckedOut()
                    {
                        CardNum = (uint)card, Serial = (uint)serial
                    };

                    // Delete and save the new entry
                    db.CheckedOut.Remove(checkedOut);
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                // In case of exception, write it to debug in addition to throwing it
                System.Diagnostics.Debug.WriteLine(e);
                throw e;
            }

            return(Json(new { success = true }));
        }
Beispiel #3
0
        public ActionResult AllTitles()
        {
            // Encapsulate in try/catch block in case of error
            try
            {
                using (Team6LibraryContext db = new Team6LibraryContext())
                {
                    // Run the query
                    var query = from tit in db.Titles
                                join inv in db.Inventory
                                on tit.Isbn equals inv.Isbn
                                into titJoinInv

                                from join1 in titJoinInv.DefaultIfEmpty()
                                join chkOut in db.CheckedOut
                                on join1.Serial equals chkOut.Serial
                                into titJoinInvJoinChkOut

                                from join2 in titJoinInvJoinChkOut.DefaultIfEmpty()
                                join pat in db.Patrons
                                on join2.CardNum equals pat.CardNum
                                into titJoinInvJoinChkOutJoinPat

                                from join3 in titJoinInvJoinChkOutJoinPat.DefaultIfEmpty()
                                select new
                    {
                        isbn   = tit.Isbn,
                        title  = tit.Title,
                        author = tit.Author,
                        serial = join1 == null ? null : (uint?)(join1.Serial),
                        name   = join3 == null ? "" : join3.Name
                    };

                    return(Json(query.ToArray()));
                }
            }
            catch (Exception e)
            {
                // In case of exception, write it to debug in addition to throwing it
                System.Diagnostics.Debug.WriteLine(e);
                throw e;
            }
        }
Beispiel #4
0
        public IActionResult CheckLogin(string name, int cardnum)
        {
            // Determine if login is successful or not.
            bool loginSuccessful = false;

            try
            {
                using (Team6LibraryContext db = new Team6LibraryContext())
                {
                    // Run a query for users with matching name and cardnum
                    var query = from p in db.Patrons
                                where p.Name == name && p.CardNum == cardnum
                                select p;

                    // See if any patrons matched the query
                    if (query.Count() == 1)
                    {
                        loginSuccessful = true;
                    }
                }
            }
            catch (Exception e)
            {
                // In case of exception, write it to debug in addition to throwing it
                System.Diagnostics.Debug.WriteLine(e);
                throw e;
            }



            if (!loginSuccessful)
            {
                return(Json(new { success = false }));
            }
            else
            {
                user = name;
                card = cardnum;
                return(Json(new { success = true }));
            }
        }
Beispiel #5
0
        public ActionResult ListMyBooks()
        {
            try
            {
                using (Team6LibraryContext db = new Team6LibraryContext())
                {
                    // Run the query
                    var query = from tit in db.Titles
                                join inv in db.Inventory
                                on tit.Isbn equals inv.Isbn
                                into titJoinInv

                                from join1 in titJoinInv.DefaultIfEmpty()
                                join chkOut in db.CheckedOut
                                on join1.Serial equals chkOut.Serial
                                into titJoinInvJoinChkOut

                                from join2 in titJoinInvJoinChkOut.DefaultIfEmpty()
                                where join2.CardNum == card

                                select new
                    {
                        isbn   = tit.Isbn,
                        title  = tit.Title,
                        author = tit.Author,
                        serial = (uint?)(join1.Serial)
                    };

                    return(Json(query.ToArray()));
                }
            }
            catch (Exception e)
            {
                // In case of exception, write it to debug in addition to throwing it
                System.Diagnostics.Debug.WriteLine(e);
                throw e;
            }
        }