Esempio n. 1
0
 // POST api/books
 public HttpResponseMessage Post(Book book)
 {
     var bookResource = _addBookQueryHandler.Execute(book);
     var httpResponseMessage = Request.CreateResponse(HttpStatusCode.Created, bookResource);
     httpResponseMessage.Headers.Location = bookResource.Self.Href;
     return httpResponseMessage;
 }
        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;
        }
 public BookResource Execute(Book bookToAdd)
 {
     var book = _bookRepository.Add(bookToAdd);
     var resource = _bookResourceMapper.MapToResouce(book);
     return resource;
 }
 public Book Add(Book book)
 {
     book.Id = GetNextId();
     Books.Add(book);
     return book;
 }
 public AlreadyCheckedInException(Book book)
     : base(string.Format("Book {0} is already checked in", book.Id))
 {
 }