Exemple #1
0
        public HttpResponseMessage CheckoutALibraryBook(Guid bookId)
        {
            var libraryService = new LibraryService();

            ILibraryBook book = libraryService.Book(bookId);

            string message = string.Empty;
            if (book != null)
            {
                DateTime dueDate = DateTime.Now.AddDays(30);

                CheckoutResult result = book.Checkout();

                if (result.CheckedOutResultStatus == CheckedOutResultStatus.Ok)
                {
                    book.DueDate = dueDate;
                    return Request.CreateResponse(HttpStatusCode.OK, new { BookId = bookId, DueDate = dueDate });
                }
                message = result.Message;
            }
            else
            {
                message = "Book does not exist";
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest, message);
        }
Exemple #2
0
        public HttpResponseMessage GetAllLibraryBooksForACategory(LibraryBookCategory category)
        {
            var libraryService = new LibraryService();

            IEnumerable<ILibraryBook> books = libraryService.AllBooks(category);

            return Request.CreateResponse(HttpStatusCode.OK, books);
        }
Exemple #3
0
        public HttpResponseMessage GetAllLibraryBooks()
        {
            var libraryService = new LibraryService();

            IList<ILibraryBook> books = libraryService.AllBooks();

            return Request.CreateResponse(HttpStatusCode.OK, books);
        }
Exemple #4
0
        public HttpResponseMessage GetSortedLibraryBooks()
        {
            var libraryService = new LibraryService();

            List<CategoryBookList> listOfCategories = new List<CategoryBookList>();

            foreach (LibraryBookCategory category in Enum.GetValues(typeof(LibraryBookCategory)))
            {
                IEnumerable<ILibraryBook> books = libraryService.AllBooks(category);
                List<ILibraryBook> bookList = books.ToList<ILibraryBook>();

                ILibraryBookFineCalculator calculator = new LibraryBookFineCalculator();

                //create the object you will return to the client
                string categoryString = category.ToString();
                CategoryBookList catBookList = new CategoryBookList(bookList, categoryString, calculator.CalculateTotalFine(DateTime.Now, bookList));
                listOfCategories.Add(catBookList);
            }

            return Request.CreateResponse(HttpStatusCode.OK, listOfCategories);
        }