Ejemplo n.º 1
0
        public async Task <IActionResult> GiveBookToUser(string UserId, int BookId)
        {
            var userNotReturnedBook = _context.TakenBooks.Where(e => e.UserId == UserId && e.Returned == false).Count();

            if (userNotReturnedBook == 0)
            {
                DateTime localDate = DateTime.Now;


                TakenBooks take = new TakenBooks();
                take.UserId    = UserId;
                take.BookId    = BookId;
                take.TakenDate = localDate;
                take.Returned  = false;

                Book tempBook = _context.Books.Find(BookId);
                tempBook.Available = tempBook.Available - 1;

                _context.Books.Update(tempBook);



                await _context.TakenBooks.AddAsync(take);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(RedirectToAction(nameof(Index), new { returned = false }));
            }
        }
Ejemplo n.º 2
0
        /* private void UpdateTakenLessons()
         * {
         *   Table<Lesson> lessons = db.GetTable<Lesson>();
         *
         *
         *   foreach (var item in db.GetTable<Lesson>())
         *   {
         *       var query = from u in db.GetTable<TakenLessons>()
         *                   where u.LessonID == item.ID
         *                   select u;
         *       if (query.Count()==0)
         *       {
         *           TakenLessons taken = new TakenLessons();
         *           taken.LessonID = item.ID;
         *           db.GetTable<TakenLessons>().InsertOnSubmit(taken);
         *           db.SubmitChanges();
         *       }
         *   }
         * }*/


        public void SetBookToStudent()
        {
            GetStudents();

            GetBooks();

            Console.WriteLine("Enter ID of student");// get student id
            if (!int.TryParse(Console.ReadLine(), out int stID))
            {
                Console.WriteLine("Uncorrect value"); return;
            }
            if (db.GetTable <Student>().SingleOrDefault(x => x.ID == stID) == null)
            {
                Console.WriteLine("There is no such student"); return;
            }
            Console.WriteLine("Enter ID of book");
            if (!int.TryParse(Console.ReadLine(), out int bkID))
            {
                Console.WriteLine("Uncorrect value"); return;
            }
            if (db.GetTable <Book>().SingleOrDefault(x => x.ID == bkID) == null)
            {
                Console.WriteLine("There is no such book"); return;
            }
            TakenBooks taken = new TakenBooks();

            taken.BookID    = bkID;
            taken.StudentID = stID;
            if (db.GetTable <TakenBooks>().Contains(taken))
            {
                Console.WriteLine("Such entry already exists");
            }
            else
            {
                Book book = db.GetTable <Book>().Single(x => x.ID == bkID);
                if (book.Quantity >= 1)
                {
                    book.Quantity -= 1;
                    db.GetTable <TakenBooks>().InsertOnSubmit(taken);
                    db.SubmitChanges();
                }
                else
                {
                    Console.WriteLine("We don't have copy of this book");
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> ReturnBookFromUserAsync(string UserId, int BookId)
        {
            TakenBooks takenBook = _context.TakenBooks.Where(e => e.BookId == BookId && e.UserId == UserId && e.Returned == false).First();
            DateTime   localDate = DateTime.Now;

            takenBook.Returned   = true;
            takenBook.ReturnDate = localDate;


            Book tempBook = _context.Books.Find(BookId);

            tempBook.Available = tempBook.Available + 1;


            _context.Books.Update(tempBook);
            _context.TakenBooks.Update(takenBook);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 4
0
 public void ReturnBook(IBookModel book)
 {
     TakenBooks.Remove(book.ID);
     History.Add(new ReadingHistory(book.ID, book.IssueDate, book.ReturnDate));
 }
Ejemplo n.º 5
0
 public void TakeBook(IBookModel book)
 {
     TakenBooks.Add(book.ID);
 }
Ejemplo n.º 6
0
 public void BookReturned(BookCopy copy)
 {
     TakenBooks.Remove(copy);
     copy.BookReturned();
 }
Ejemplo n.º 7
0
 public void BookTaken(BookCopy copy)
 {
     copy.BookTaken(this.ID);
     TakenBooks.Add(copy);
 }