コード例 #1
0
        public Library Query()
        {
            var library = new Library();

            library.Name  = "Hello World - Hypermedia Library";
            library.Self  = _linker.GetResourceLink <RootController>(request => request.Get(), "self", "Library Options", HttpMethod.Get);
            library.Links = new List <Link>();
            library.Links.Add(_linker.GetResourceLink <BooksController>(request => request.Get(), "Books", "All library books", HttpMethod.Get));
            library.Links.Add(_linker.GetResourceLink <CheckInController>(request => request.Get(), "CheckedIn", "Avalible books", HttpMethod.Get));
            library.Links.Add(_linker.GetResourceLink <CheckedOutController>(request => request.Get(), "CheckedOut", "Checked out books", HttpMethod.Get));
            return(library);
        }
コード例 #2
0
        public BookCatalogResource Query()
        {
            var books = _bookRepository.GetAll();
            BookCatalogResource resource = new BookCatalogResource();

            resource.Self  = _resourceLinker.GetResourceLink <BooksController>(request => request.Get(), "self", "Library Catalog", HttpMethod.Get);
            resource.Links = new List <Link>();
            resource.Links.Add(_resourceLinker.GetResourceLink <RootController>(request => request.Get(), "home", "Home", HttpMethod.Get));
            resource.Catalog = new List <BookResource>();
            foreach (var book in books)
            {
                resource.Catalog.Add(_bookResourceMapper.MapToResouce(book));
            }
            return(resource);
        }
コード例 #3
0
        public ThanksResource Execute()
        {
            _fineRepository.PayFines();
            var thanks = new ThanksResource();

            thanks.Links = new List <Link>();
            thanks.Links.Add(_resourceLinker.GetResourceLink <RootController>(request => request.Get(), "Home", "Home", HttpMethod.Get));
            return(thanks);
        }
コード例 #4
0
 public FinesResource Query()
 {
     if (_fineRepository.HasFines())
     {
         var fines = new FinesResource();
         fines.Links = new List <Link>();
         fines.Links.Add(_resourceLinker.GetResourceLink <FinesController>(request => request.Post(), "Fee", "Pay your Fines!!", HttpMethod.Post));
         return(fines);
     }
     return(null);
 }
コード例 #5
0
        public BookCatalogResource Query()
        {
            var books = _bookRepository.GetAll().Where(book => book.State == BookState.CheckedOut);;
            BookCatalogResource resource = new BookCatalogResource();

            resource.Self    = _resourceLinker.GetResourceLink <BooksController>(request => request.Get(), "self", "Checked Out Books", HttpMethod.Get);
            resource.Catalog = new List <BookResource>();
            foreach (var book in books)
            {
                resource.Catalog.Add(_bookResourceMapper.MapToResouce(book));
            }
            return(resource);
        }
コード例 #6
0
        public BookResource MapToResouce(Book book)
        {
            BookResource resource = new BookResource();

            resource.Id          = book.Id;
            resource.Title       = book.Title;
            resource.Author      = book.Author;
            resource.Description = book.Description;
            resource.Self        = _resourceLinker.GetResourceLink <BooksController>(request => request.Get(book.Id), "self", book.Title, HttpMethod.Get);
            resource.Links       = new List <Link>();
            if (book.IsCheckedOut)
            {
                var checkInLink = _resourceLinker.GetResourceLink <CheckInController>(request => request.Post(book.Id), "Check In", book.Title, HttpMethod.Post);
                resource.Links.Add(checkInLink);
            }

            if (book.IsCheckedIn)
            {
                var checkoutLink = _resourceLinker.GetResourceLink <CheckedOutController>(request => request.Post(book.Id), "Check Out", book.Title, HttpMethod.Post);
                resource.Links.Add(checkoutLink);
            }
            resource.Links.Add(_resourceLinker.GetResourceLink <RootController>(request => request.Get(), "Home", "Go Home", HttpMethod.Get));
            return(resource);
        }