Example #1
0
        public void CheckInItem(int assetId)
        {
            var item = _context.LibraryAssets.FirstOrDefault(asset => asset.Id == assetId);

            //_context.Update(item);
            //remove existing checkouts
            RemoveExistingCheckouts(assetId);
            //close existing checkput history
            CloseExistingCheckouts(assetId, _now);
            //look for existing hold
            var currentHolds = _context.Holds
                               .Include(h => h.LibraryAsset)
                               .Include(h => h.LibraryCard)
                               .Where(h => h.LibraryAsset.Id == assetId);

            //checkout  earliest hold
            if (currentHolds.Any())
            {
                var earliestHold = currentHolds.OrderBy(holds => holds.HoldPlaced).FirstOrDefault();
                if (earliestHold != null)
                {
                    var card = earliestHold.LibraryCard;
                    _context.Remove(earliestHold);
                    _context.SaveChanges();
                    CheckOutAsset(assetId, card.Id);
                }
            }
            else
            {
                //set item status available
                UpdateAssetStatus(assetId, "Available");
            }

            _context.SaveChanges();
        }
Example #2
0
        public void MarkFound(int id)
        {
            var item = _context.LibraryAssets
                       .First(a => a.Id == id);

            _context.Update(item);
            item.Status = _context.Statuses.FirstOrDefault(a => a.Name == "Available");
            var now = DateTime.Now;

            // remove any existing checkouts on the item
            var checkout = _context.Checkouts
                           .FirstOrDefault(a => a.LibraryAsset.Id == id);

            if (checkout != null)
            {
                _context.Remove(checkout);
            }

            // close any existing checkout history
            var history = _context.CheckoutHistories
                          .FirstOrDefault(h => h.LibraryAsset.Id == id &&
                                          h.CheckedIn == null);

            if (history != null)
            {
                _context.Update(history);
                history.CheckedIn = now;
            }

            _context.SaveChanges();
        }
        private void RemoveExistingCheckouts(int assetId)
        {
            var checkout = _context.Checkouts.FirstOrDefault(co => co.LibraryAsset.Id == assetId);

            if (checkout != null)
            {
                _context.Remove(checkout);
            }
        }
Example #4
0
        private void RemoveExistingCheckouts(int id)
        {
            var checkout = _context.Checkouts.FirstOrDefault(a => a.LibraryAsset.ID == id);

            if (checkout != null)
            {
                _context.Remove(checkout);
            }
        }
        void RemoveExistingCheckouts(int assetId)
        {
            var checkout = _Context.CheckOuts.FirstOrDefault(c => c.LibraryAsset.Id == assetId);

            if (checkout != null)
            {
                _Context.Remove(checkout);
            }
        }
        private void RemoveExistingCheckouts(int assetId)
        {
            //remove any existing checkout on the item
            var checkout = _context.CheckOuts.FirstOrDefault(ch => ch.LibraryAsset.Id == assetId);

            if (checkout != null)
            {
                _context.Remove(checkout);
            }
        }
        private void RemoveExistingCheckouts(int assetId)
        {
            Checkout previousCheckout = _context.Checkouts.FirstOrDefault(co => co.LibraryAsset.Id == assetId);

            if (previousCheckout != null)
            {
                _context.Remove(previousCheckout);
                _context.SaveChanges();
            }
        }
        private void CheckoutToEarliestHold(int assetId, IQueryable <Holds> currentHolds)
        {
            var earliestHold = currentHolds.OrderBy(h => h.HoldPlaced).FirstOrDefault();

            var card = earliestHold.LibraryCard;

            _context.Remove(earliestHold);
            _context.SaveChanges();
            CheckOutItem(assetId, card.Id);
        }
        private void removeCheckout(int assetId)
        {
            var checkout = _context.checkOut
                           .FirstOrDefault(c => c.LibraryAsset.id == assetId);

            if (checkout != null)
            {
                _context.Remove(checkout);
            }
        }
        private void RemoveExistingCheckouts(int assetId)
        {
            CheckOut checkout = context.CheckOuts
                                .FirstOrDefault(e => e.LibraryAsset.Id == assetId);

            if (checkout != null)
            {
                context.Remove(checkout);
            }
        }
Example #11
0
        private void RemoveExistingCheckouts(int assetId)
        {
            //If the item is found, remove any existing checkout
            var checkout = _context.Checkouts.FirstOrDefault(co => co.LibraryAsset.Id == assetId);

            if (checkout != null)
            {
                _context.Remove(checkout);
            }
        }
        private void CloseExistingCheckOutHistory(int id)
        {
            var history = _context.CheckOutHistories.FirstOrDefault(e => e.LibraryAsset.ID == id && e.CheckedIn == null);

            if (history != null)
            {
                _context.Remove(history);
                history.CheckedIn = DateTime.Now;
            }
        }
Example #13
0
        private void CheckoutToEarliestHold(int id, IQueryable <Hold> currentHolds)
        {
            var earliestHold = currentHolds
                               .OrderBy(holds => holds
                                        .HoldPlaced).FirstOrDefault();
            var card = earliestHold.LibraryCard;

            _context.Remove(earliestHold);
            _context.SaveChanges();
        }
        private async Task RemoveExistingCheckouts(int assetId)
        {
            var checkout = await _context.Checkouts
                           .FirstOrDefaultAsync(x => x.LibraryAsset.Id == assetId);

            if (checkout != null)
            {
                _context.Remove(checkout);
            }
        }
        private void CheckoutToEarliestHold(int id, IQueryable <Hold> currentHolds)
        {
            var earliestHold = currentHolds.OrderBy(holds => holds.HoldPlaced).FirstOrDefault();

            var card = earliestHold.LibraryCard;

            _context.Remove(earliestHold);
            _context.SaveChanges(); //Remove earliest hold since it  is now longer needed when it's been checked out

            CheckoutItem(id, card.Id);
        }
Example #16
0
        private void CheckouToEarliestHold(int assetId, IEnumerable <Hold> currentHolds)
        {
            var earliestHold = currentHolds
                               .OrderBy(hold => hold.HoldPlaced)
                               .FirstOrDefault();
            var card = earliestHold.LibraryCard;

            _context.Remove(earliestHold);
            _context.SaveChanges();
            CheckInItem(/*assetId*/ card.Id);
        }
Example #17
0
        private void RemoveExistingCheckouts(int assetId)
        {
            var checkout = _context.Checkouts
                           .Include(a => a.LibraryAsset)
                           .Include(a => a.LibraryCard)
                           .FirstOrDefault(a => a.LibraryAsset.Id == assetId);

            if (checkout != null)
            {
                _context.Remove(checkout);
            }
        }
        public void deleteAsset(int Id)
        {
            var asset = _context.LibraryAsset.FirstOrDefault(a => a.Id == Id);
            var holds = _context.Holds.Include(a => a.LibraryAsset).Where(a => a.LibraryAsset.Id == Id);

            foreach (Holds item in holds)
            {
                _context.Remove(item);
            }
            _context.Remove(asset);
            _context.SaveChanges();
        }
Example #19
0
        private void CheckOutToEarliest(int id, IQueryable <Hold> currentHodlds)
        {
            var earliestHold = currentHodlds.OrderBy(holds => holds.HoldPlaced).
                               FirstOrDefault();

            var card = earliestHold.LibraryCard;

            _context.Remove(earliestHold);


            CheckOutItem(id, card.Id);
        }
Example #20
0
        public void CheckInItem(int assetId)
        {
            var now = DateTime.Now;

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

            _context.Update(item);

            // remove any existing checkouts on the item
            var checkout = _context.Checkouts
                           .Include(c => c.LibraryAsset)
                           .Include(c => c.LibraryCard)
                           .FirstOrDefault(a => a.LibraryAsset.Id == assetId);

            if (checkout != null)
            {
                _context.Remove(checkout);
            }

            // close any existing checkout history
            var history = _context.CheckoutHistories
                          .Include(h => h.LibraryAsset)
                          .Include(h => h.LibraryCard)
                          .FirstOrDefault(h =>
                                          h.LibraryAsset.Id == assetId &&
                                          h.CheckedIn == null);

            if (history != null)
            {
                _context.Update(history);
                history.CheckedIn = now;
            }

            // look for current holds
            var currentHolds = _context.Holds
                               .Include(a => a.LibraryAsset)
                               .Include(a => a.LibraryCard)
                               .Where(a => a.LibraryAsset.Id == assetId);

            // if there are current holds, check out the item to the earliest
            if (currentHolds.Any())
            {
                CheckoutToEarliestHold(assetId, currentHolds);
                return;
            }

            // otherwise, set item status to available
            item.Status = _context.Statuses.FirstOrDefault(a => a.Name == "Available");

            _context.SaveChanges();
        }
Example #21
0
        private void RemoveExistingCheckouts(int assetId)
        {
            // remove any existing checkouts on the item
            var checkout = _context.Checkouts
                           .FirstOrDefault(co => co.LibraryAsset.Id == assetId);

            if (checkout != null)
            {
                // Tracking Item for deletion not deleted until
                // _context.SaveChanges();
                _context.Remove(checkout);
            }
        }
        public void CheckoutToEarliestHolds(int assetId, IQueryable <Hold> currentHolds)
        {
            var earliestHold = currentHolds
                               .OrderBy(holds => holds.HoldPlaced)
                               .FirstOrDefault();

            // Get the id of the library card that made the earliest hold
            var card = earliestHold.LibraryCard;

            _context.Remove(earliestHold);
            _context.SaveChanges();
            CheckOutItem(assetId, card.Id);
        }
        private void CheckoutToEarliestHold(int assetId, IQueryable <Hold> currentHolds)
        {
            // COME BACK AND STUDY THIS METHOD IN-DEPTH
            var earliestHold = currentHolds
                               .OrderBy(holds => holds.HoldPlaced)
                               .FirstOrDefault();

            var card = earliestHold.LibraryCard;

            _context.Remove(earliestHold);
            _context.SaveChanges();

            CheckOutItem(assetId, card.Id);
        }
Example #24
0
        private void CheckOutToEarliestHold(int assetId, IQueryable <Hold> currentHolds)
        {
            Hold earlistHold = currentHolds
                               .OrderBy(x => x.HoldPlaced)
                               .FirstOrDefault();

            LibraryCard card = earlistHold.LibraryCard;

            //Once the hold has been fulfilled to a CheckOut, we no longer
            //need a hold on it, as it has been checked out to LibraryCard with earliest hold
            _context.Remove(earlistHold);
            _context.SaveChanges();
            CheckOutItem(assetId, card.Id);
        }
Example #25
0
        private void UpdatePublishedBooks(string[] selectedBooks, Publishers publisherToUpdate)
        {
            if (selectedBooks == null)
            {
                publisherToUpdate.PublishedBooks = new List <PublishedBook>();
                return;
            }
            var selectedBooksHS = new HashSet <string>(selectedBooks);
            var publishedBooks  = new HashSet <int>
                                      (publisherToUpdate.PublishedBooks.Select(c => c.Book.ID));

            foreach (var book in _context.Books)
            {
                if (selectedBooksHS.Contains(book.ID.ToString()))
                {
                    if (!publishedBooks.Contains(book.ID))
                    {
                        publisherToUpdate.PublishedBooks.Add(new PublishedBook {
                            PublisherID = publisherToUpdate.ID, BookID = book.ID
                        });
                    }
                }
                else
                {
                    if (publishedBooks.Contains(book.ID))
                    {
                        PublishedBook bookToRemove = publisherToUpdate.PublishedBooks.FirstOrDefault(i => i.BookID == book.ID);
                        _context.Remove(bookToRemove);
                    }
                }
            }
        }
 public int DeleteAuthor(Guid authorId)
 {
     try
     {
         if (_libraryContext != null)
         {
             var author = _libraryContext.Authors.FirstOrDefault(x => x.AuthorId == authorId);
             if (author != null)
             {
                 _libraryContext.Remove(author);
                 return(1);
             }
             else
             {
                 return(0);
             }
         }
         else
         {
             return(0);
         }
     }
     catch (Exception ex)
     {
         //log exception
         return(0);
     }
 }
Example #27
0
        public string DeleteAuthor(Guid authorId)
        {
            try
            {
                if (_libraryContext != null)
                {
                    var author = _libraryContext.Authors.FirstOrDefault(x => x.AuthorId == authorId);
                    if (author != null)
                    {
                        _libraryContext.Remove(author);
                        _libraryContext.SaveChanges();
                    }
                }
                else
                {
                    return("Record hasn't deleted properly");
                }
            }
            catch (Exception ex)
            {
                //log exception
                return(ex.Message);
            }

            return("Record has deleted successfully");
        }
Example #28
0
        public void Delete(int bookId)
        {
            var book = GetByID(bookId);

            using (var context = new LibraryContext()) {
                context.Remove(book);
                context.SaveChanges();
            }
        }
Example #29
0
        public RedirectToActionResult Delete(int id)
        {
            Book b = new Book();

            b = _context.Books.SingleOrDefault(x => (x.Id == id));
            _context.Remove(b);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Catalog"));
        }
Example #30
0
        public bool RemoveTome(int?tomeId)
        {
            //ha van rá aktív kölcsönzés,nem tudjuk törölni
            foreach (var loan in _context.Loans)
            {
                if (loan.TomeId == tomeId && loan.IsActive)
                {
                    return(false);
                }
            }

            var tome = _context.Tomes.FirstOrDefault(l => l.Id == tomeId);

            _context.Remove(tome);

            try
            {
                _context.SaveChanges();
            }
            catch
            {
                return(false);
            }

            //az összes erre leadott kölcsönzést is törölni kell
            foreach (var loan in _context.Loans)
            {
                if (loan.TomeId == tomeId)
                {
                    _context.Remove(loan);
                }
            }

            try
            {
                _context.SaveChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }