Beispiel #1
0
        public void MarkFound(int id)
        {
            var item = _context.LibraryAssets
                       .FirstOrDefault(a => a.Id == id);

            _context.Update(item ?? throw new InvalidOperationException());
            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();
        }
Beispiel #2
0
        private void UpdateAssetStatus(int assetId, string newStatus)
        {
            var item = _context.LibraryAssets.FirstOrDefault(a => a.Id == assetId);

            _context.Update(item);

            item.Status = _context.Status.FirstOrDefault(status => status.Name == newStatus);
        }
Beispiel #3
0
        public async Task <bool> MarkLost(Guid assetId)
        {
            var item = await _context.LibraryAssets
                       .FirstAsync(a => a.Id == assetId);

            _context.Update(item);
            // TODO
            item.AvailabilityStatus = _context.Statuses
                                      .First(a => a.Name == AssetStatus.Lost);
            await _context.SaveChangesAsync();

            return(true);
        }
Beispiel #4
0
        public async Task <IActionResult> Edit(int id, [Bind("BookId,BookName,BookAuthor,BookPublisher,BookPrice,Description,Stock,Image")] Book book)
        {
            if (id != book.BookId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.BookId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Beispiel #5
0
 public void Update(T entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     _context.Attach(entity);
     _context.Update(entity);
     Save();
 }
Beispiel #6
0
        public async Task <IActionResult> Edit(int id, [Bind("id,Title,Author,Language,categoryID")] Book book)
        {
            if (id != book.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["categoryID"] = new SelectList(_context.categories, "id", "Name", book.categoryID);
            return(View(book));
        }
Beispiel #7
0
        public async Task <IActionResult> Edit(int id, [Bind("BookId,Title,AuthorId,BorrowerId")] Book book)
        {
            if (id != book.BookId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.BookId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"]   = new SelectList(_context.Authors, "AuthorId", "Name", book.AuthorId);
            ViewData["BorrowerId"] = new SelectList(_context.Customers, "CustomerId", "Name", book.BorrowerId);
            return(View(book));
        }
Beispiel #8
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,UserName,UserFirstName,UserLastName")] User user)
        {
            if (id != user.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Beispiel #9
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CollectionName,Restrictions,ContactInstructions")] SpecialCollection specialCollection)
        {
            if (id != specialCollection.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(specialCollection);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SpecialCollectionExists(specialCollection.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(specialCollection));
        }
Beispiel #10
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Active,ExpirationDate,StudentId")] LibraryCard libraryCard)
        {
            if (id != libraryCard.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(libraryCard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LibraryCardExists(libraryCard.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StudentId"] = new SelectList(_context.Student, "Id", "Id", libraryCard.StudentId);
            return(View(libraryCard));
        }
        public async Task <IActionResult> Edytuj(int id, Ksiazki ksiazka)
        {
            if (id != ksiazka.id_ksiazki)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ksiazka);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!KsiazkaExists(ksiazka.id_ksiazki))
                    {
                        return(NotFound());
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(ksiazka));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,RoomName,FloorNumber,Capacity")] Room room)
        {
            if (id != room.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(room);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoomExists(room.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(room));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,CheckoutDate,ReturnDate,StaffId,StudentId")] Checkout checkout)
        {
            if (id != checkout.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(checkout);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CheckoutExists(checkout.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StaffId"]   = new SelectList(_context.Staff, "Id", "Id", checkout.StaffId);
            ViewData["StudentId"] = new SelectList(_context.Student, "Id", "Id", checkout.StudentId);
            return(View(checkout));
        }
Beispiel #14
0
        public async Task <bool> PlaceHold(Guid assetId, int libraryCardId)
        {
            var now = DateTime.UtcNow;

            var asset = await _context.LibraryAssets
                        .Include(a => a.AvailabilityStatus)
                        .FirstAsync(a => a.Id == assetId);

            var card = await _context.LibraryCards
                       .FirstAsync(a => a.Id == libraryCardId);

            _context.Update(asset);

            if (asset.AvailabilityStatus.Name == "Available")
            {
                asset.AvailabilityStatus = await _context.Statuses
                                           .FirstAsync(a => a.Name == "On Hold");
            }

            var hold = new Hold {
                HoldPlaced  = now,
                Asset       = asset,
                LibraryCard = card
            };

            await _context.AddAsync(hold);

            await _context.SaveChangesAsync();

            return(true);
        }
Beispiel #15
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,StartDate,EndDate,RoomId,StudentId")] RoomReservation roomReservation)
        {
            if (id != roomReservation.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(roomReservation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoomReservationExists(roomReservation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoomId"]    = new SelectList(_context.Room, "Id", "Id", roomReservation.RoomId);
            ViewData["StudentId"] = new SelectList(_context.Student, "Id", "Id", roomReservation.StudentId);
            return(View(roomReservation));
        }
Beispiel #16
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,BookTitle,PublishedYear,ShelfPosition,SpecialCollectionId,AuthorId")] Book book)
        {
            if (id != book.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"]            = new SelectList(_context.Author, "Id", "Id", book.AuthorId);
            ViewData["SpecialCollectionId"] = new SelectList(_context.SpecialCollection, "Id", "Id", book.SpecialCollectionId);
            return(View(book));
        }
        public async Task <IActionResult> Detale(int id, [Bind("id_zamowienia,id_ksiazki,tytul,ilosc")] ZamowienieKsiazkiViewModel zamowienie_ksiazki)
        {
            if (zamowienie_ksiazki.ilosc > 1000 || zamowienie_ksiazki.ilosc < 1)
            {
                ModelState.AddModelError("", "Ilość książek musi mieścić się w przedziale 1-1000");
                return(RedirectToAction("Detale", "Zamowienia", id));
            }
            if (ModelState.IsValid)
            {
                var temp = new Zamowienie_ksiazki();
                temp.id_zamowienia = id;
                temp.id_ksiazki    = zamowienie_ksiazki.id_ksiazki;
                temp.ilosc         = zamowienie_ksiazki.ilosc;
                var duplikat = await _context.Zamowienie_ksiazki.FirstOrDefaultAsync(m => m.id_zamowienia == id && m.id_ksiazki == temp.id_ksiazki);

                if (duplikat != null)
                {
                    duplikat.ilosc += temp.ilosc;
                    _context.Update(duplikat);
                }
                else
                {
                    _context.Add(temp);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction("Detale", "Zamowienia", new { id = id }));
            }

            ViewData["id_ksiazki"] = new SelectList(_context.Ksiazki, "id_ksiazki", "tytuł", zamowienie_ksiazki.id_ksiazki);
            return(View(zamowienie_ksiazki.id_zamowienia));
        }
Beispiel #18
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,StaffName,StaffPassword")] Staff staff)
        {
            if (id != staff.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(staff);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StaffExists(staff.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(staff));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,AuthorName")] Author author)
        {
            if (id != author.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(author);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuthorExists(author.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
Beispiel #20
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Titulo,IdEditorial,Fecha,Costo,PrecioSugerido,Autor")] Libro libro)
        {
            if (id != libro.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(libro);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LibroExists(libro.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EditorialId"] = new SelectList(_context.Editorial, "Id", "Nombre", libro.IdEditorial);
            return(View(libro));
        }
        public async Task <bool> CheckOutItem(Guid assetId, int libraryCardId)
        {
            var now = DateTime.UtcNow;

            var isAlreadyCheckedOut = await IsCheckedOut(assetId);

            if (isAlreadyCheckedOut)
            {
                // TODO
            }

            var libraryAsset = await _context.LibraryAssets
                               .Include(a => a.AvailabilityStatus)
                               .FirstAsync(a => a.Id == assetId);

            _context.Update(libraryAsset);

            // TODO
            libraryAsset.AvailabilityStatus = await _context.Statuses
                                              .FirstAsync(a => a.Name == "Checked Out");

            var libraryCard = await _context.LibraryCards
                              .Include(c => c.Checkouts)
                              .FirstAsync(a => a.Id == libraryCardId);

            var checkout = new Data.Models.Checkout {
                Asset           = libraryAsset,
                LibraryCard     = libraryCard,
                CheckedOutSince = now,
                CheckedOutUntil = GetDefaultDateDue(now)
            };

            await _context.AddAsync(checkout);

            var checkoutHistory = new CheckoutHistory {
                CheckedOut  = now,
                Asset       = libraryAsset,
                LibraryCard = libraryCard
            };

            await _context.AddAsync(checkoutHistory);

            await _context.SaveChangesAsync();

            return(true);
        }
Beispiel #22
0
        public void SetTitle(string title, int id)
        {
            var item = _context.LibraryAssets.FirstOrDefault(a => a.Id == id);

            _context.Update(item);
            item.Title = title;
            // throw new NotImplementedException();
        }
Beispiel #23
0
        public void CheckInItem(int id)
        {
            var now = DateTime.Now;

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

            _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 == id);

            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 == id &&
                                          h.CheckedIn == null);

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

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

            // if there are current holds, check out the item to the earliest
            if (currentHolds.Any())
            {
                //CheckoutToEarliestHold(id, currentHolds);
                item.Status = _context.Statuses.FirstOrDefault(a => a.Name == "On Hold");
                _context.SaveChanges();
                return;
            }

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

            _context.SaveChanges();
        }
 public IActionResult Edit(Category make)
 {
     if (ModelState.IsValid)
     {
         _context.Update(make);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(make));
 }
        public void MarkFound(int assetid)
        {
            var now  = DateTime.Now;
            var item = context.LibraryAssets.FirstOrDefault(i => i.Id == assetid);

            context.Update(item);
            item.Status = context.Statuses.FirstOrDefault(status => status.Name == "Available");
            //item.Status = context.Statuses.Find("Available"); !!!!

            RemoveExistingCheckouts(assetid);

            CloseExistingCheckoutHistory(assetid, now);

            context.SaveChanges();
        }
        public IActionResult RemoveFromLibrary(int bookId)
        {
            Book currentBook = _libraryDB.Books.Find(bookId);

            List <Loan> thisBooksLoans = _libraryDB.Loans.Where(x => x.BookId == bookId).ToList();

            if (thisBooksLoans.Count == 0)
            {
                _libraryDB.Books.Remove(currentBook);
            }
            else
            {
                currentBook.IsActive = false;
                _libraryDB.Update(currentBook);
            }
            _libraryDB.SaveChanges();
            return(RedirectToAction("MyLibrary"));
        }
Beispiel #27
0
        public void SetDomainState(BaseEntity entity)
        {
            switch (entity.Status)
            {
            case Status.Added:
                _context.Add(entity);
                break;

            case Status.Updated:
                _context.Update(entity);
                break;

            case Status.Deleted:
                _context.Remove(entity);
                break;

            case Status.Unchanged:
                break;
            }
        }
Beispiel #28
0
        public bool Update(Autores Model)
        {
            try
            {
                var originalModel = _libraryDbContext.Autores.Single(x =>
                                                                     x.IdAutor == Model.IdAutor
                                                                     );
                originalModel.NombreAut   = Model.NombreAut;
                originalModel.ApellidoAut = Model.ApellidoAut;


                _libraryDbContext.Update(Model);
                _libraryDbContext.SaveChanges();
            }
            catch (System.Exception)
            {
                return(false);
            }
            return(true);
        }
Beispiel #29
0
        public bool Update(Tipolibro Model)
        {
            try
            {
                var originalModel = _libraryDbContext.Tipolibros.Single(x =>
                                                                        x.IdTipo == Model.IdTipo
                                                                        );
                originalModel.NombreTipo = Model.NombreTipo;



                _libraryDbContext.Update(Model);
                _libraryDbContext.SaveChanges();
            }
            catch (System.Exception)
            {
                return(false);
            }
            return(true);
        }
Beispiel #30
0
        public bool Update(Prestamos Model)
        {
            try
            {
                var originalModel = _libraryDbContext.Prestamos.Single(x =>
                                                                       x.IdPrestamo == Model.IdPrestamo
                                                                       );
                originalModel.Prestamo = Model.Prestamo;



                _libraryDbContext.Update(Model);
                _libraryDbContext.SaveChanges();
            }
            catch (System.Exception)
            {
                return(false);
            }
            return(true);
        }