Beispiel #1
0
        public static string GetBook(int userId, int bookId)
        {
            int ddays = 0;

            User user = context.Users.Find(userId);
            Book book = context.Books.Find(bookId);

            Issuance issuance = UserForGrid.FindUserIssuance(user, book);

            if (issuance == null)
            {
                ddays = -1;
            }

            if (new UserForGrid(user).HasDebts())
            {
                ddays = issuance.GetDebtDays();
            }

            book.NumOfBooks++;
            context.Issuances.Remove(issuance);
            user.Issuances.Remove(issuance);

            context.SaveChanges();

            return($"BookWasReturned|{ddays}");
        }
Beispiel #2
0
        public static string GiveBook(int userId, int bookId, DateTime deadLine)
        {
            User user = context.Users.Find(userId);
            Book book = context.Books.Find(bookId);

            Issuance issuance = UserForGrid.FindUserIssuance(user, book);

            if (issuance != null || book == null || user == null || book.NumOfBooks == 0)
            {
                return("CantGiveBook");
            }

            issuance = new Issuance()
            {
                Book = book, IssuanceDate = DateTime.Now, Deadline = deadLine
            };
            book.NumOfBooks--;
            user.Issuances.Add(issuance);
            context.SaveChanges();

            return("BookWasGiven");
        }