public void CheckOutItem(int assetId, int LibraryCardId)
        {
            if (IsCheckedOut(assetId))
            {
                return;
                //Add logic here to handle feedback to the user!
            }
            var item = _Context.LibraryAssets
                       .FirstOrDefault(a => a.Id == assetId);

            UpdateAssetStatus(assetId, "Checked Out");
            var libraryCard = _Context.LibraryCards
                              .Include(card => card.Checkouts)
                              .FirstOrDefault(card => card.Id == LibraryCardId);
            var checkout = new CheckOut
            {
                LibraryAsset = item,
                LibraryCard  = libraryCard,
                Since        = now,
                Until        = GetDefaultCheckoutTime(now)
            };

            _Context.Add(checkout);
            var checkoutHistory = new CheckOutHistory
            {
                CheckedOut   = now,
                LibraryAsset = item,
                LibraryCard  = libraryCard
            };

            _Context.Add(checkoutHistory);
            _Context.SaveChanges();
        }
Exemplo n.º 2
0
        public void CheckOutItem(int assetId, int libraryCardId)
        {
            if (IsCheckedOut(assetId))
            {
                return; //add logic to handle user feedback here
            }

            LibraryAsset item = _context.LibraryAssets.
                                FirstOrDefault(a => a.Id == assetId);
            LibraryCard libraryCard = _context.LibraryCards
                                      .Include(c => c.CheckOuts)
                                      .FirstOrDefault(c => c.Id == libraryCardId);

            if (libraryCard != null)
            {
                UpdateAssetStatus(assetId, Status.CheckedOut);

                CheckOut CheckOut = new CheckOut(item, libraryCard, DateTime.Now);
                _context.Add(CheckOut);

                /**add a new CheckOut history. This could be handled in a
                 * shadow table in SQL Server or in a database trigger */
                CheckOutHistory CheckOutHistory = new CheckOutHistory(item, libraryCard);

                _context.Add(CheckOutHistory);
                _context.SaveChanges();
            }
            else
            {
                return;
            }
        }
        public void CheckOutItem(int assetID, int libraryCardID)
        {
            if (IsCheckedOut(assetID))
            {
                return;
            }
            var item = _context.LibraryAssets.FirstOrDefault(e => e.ID == assetID);

            UpdateAssetsStatus(assetID, "Checked Out");

            var librarayCard = _context.LibraryCards.Include(e => e.CheckOuts).FirstOrDefault(e => e.ID == libraryCardID);

            var date     = DateTime.Now;
            var checkout = new CheckOut
            {
                LibraryAsset = item,
                LibraryCard  = librarayCard,
                Since        = date,
                Until        = GetDefaultCheckOutTime(date)
            };

            _context.Add(checkout);

            var checkOutHistory = new CheckOutHistory
            {
                LibraryAsset = item,
                LibraryCard  = librarayCard,
                CheckedOut   = date
            };

            _context.Add(checkOutHistory);
            _context.SaveChanges();
        }
        private void CloseExistingCheckoutHistory(int assetId)
        {
            CheckOutHistory history = context.CheckOutHistories
                                      .FirstOrDefault(e => e.LibraryAsset.Id == assetId && e.CheckedIn == null);

            if (history != null)
            {
                context.Update(history);
                history.CheckedIn = DateTime.Now;
            }
        }
Exemplo n.º 5
0
        private void CloseExistingCheckOutHistory(int assetId, DateTime now)
        {
            CheckOutHistory history = _context.CheckOutHistories
                                      .FirstOrDefault(c => c.LibraryAsset.Id == assetId &&
                                                      /** This checks to ensure it is an open CheckOut*/
                                                      c.CheckedIn == null);

            if (history != null)
            {
                _context.Update(history);
                history.CheckedIn = now;
            }
        }
Exemplo n.º 6
0
        public void CheckOutItem(int id, int libraryCardId)
        {
            if (IsCheckedOut(id))
            {
                return;
            }

            var item = context.LibraryAssets
                       .Include(a => a.Status)
                       .First(a => a.Id == id);

            context.Update(item);

            item.Status = context.Statuses
                          .FirstOrDefault(a => a.Name == "Checked Out");

            var now = DateTime.Now;

            var libraryCard = context.LibraryCards
                              .Include(c => c.CheckOuts)
                              .FirstOrDefault(a => a.Id == libraryCardId);

            var checkOut = new CheckOut
            {
                LibraryAsset = item,
                LibraryCard  = libraryCard,
                Since        = now,
                Until        = GetDefaultCheckOutTime(now)
            };

            context.Add(checkOut);

            var checkoutHistory = new CheckOutHistory
            {
                CheckedOut   = now,
                LibraryAsset = item,
                LibraryCard  = libraryCard
            };

            context.Add(checkoutHistory);
            context.SaveChanges();
        }
        public void CheckOutItem(int assetId, int LibraryCardId)
        {
            if (IscheckedOut(assetId))
            {
                return;
            }

            var item = _context.LibraryAssets
                       .FirstOrDefault(a => a.Id == assetId);

            UpdateAssetStatus(assetId, "Checked Out");

            var librarycard = _context.LibraryCards
                              .Include(c => c.CheckOuts)
                              .FirstOrDefault(c => c.Id == LibraryCardId);

            var now = DateTime.Now;

            var checkout = new CheckOuts
            {
                LibraryAsset = item,
                LibraryCard  = librarycard,
                Since        = now,
                Until        = GetdefaultCheckoutTime(now)
            };

            _context.Add(checkout);

            var chechouthistory = new CheckOutHistory

            {
                CheckedOut   = now,
                LibraryAsset = item,
                LibraryCard  = librarycard,
            };

            _context.Add(chechouthistory);
            _context.SaveChanges();
        }
        public void CheckOutItem(int assetId, int libraryCardId)
        {
            if (IsCheckedOut(assetId))
            {
                return;
            }

            LibraryAsset libraryAsset = context.LibraryAssets.FirstOrDefault(e => e.Id == assetId);

            UpdateStatus(assetId, "Checked Out");

            LibraryCard libraryCard = context.LibraryCards
                                      .Include(card => card.Id == libraryCardId)
                                      .FirstOrDefault(card => card.Id == libraryCardId);

            DateTime now = DateTime.Now;

            CheckOut checkout = new CheckOut
            {
                LibraryAsset = libraryAsset,
                LibraryCard  = libraryCard,
                Since        = now,
                Until        = GetDefaultCheckoutTime(now)
            };

            context.Add(checkout);
            CheckOutHistory checkOutHistory = new CheckOutHistory
            {
                LibraryAsset = libraryAsset,
                LibraryCard  = libraryCard,
                CheckedOut   = now
            };

            context.Add(checkOutHistory);

            context.SaveChanges();
        }
 public void Update(CheckOutHistory entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 public void Add(CheckOutHistory entity)
 {
     _context.Add(entity);
 }