Esempio n. 1
0
        public HttpResponseMessage Post(Book book)
        {
            Books.Add(book);

            var response = Request.CreateResponse(HttpStatusCode.Created, book);

            string uri = Url.Link("DefaultApi", new { id = book.Isbn });
            response.Headers.Location = new Uri(uri);
            return response;
        }
Esempio n. 2
0
        public bool IsMatch(Book book)
        {
            if (after != null)
            {
                if (book.PubDate < after)
                {
                    return false;
                }
            }

            if (before != null)
            {
                if (book.PubDate > before)
                {
                    return false;
                }
            }

            return true;
        }
Esempio n. 3
0
        public IActionResult OnPost()
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            Books.Models.Author author = this.Context.Authors.Where(a => a.Name == this.Author).FirstOrDefault();
            if (author == null)
            {
                author = new Books.Models.Author()
                {
                    Name = this.Author
                };
                this.Context.Authors.Add(author);
                this.Context.SaveChanges();
            }

            var status = new Status()
            {
                IsAvailable = true
            };

            Books.Models.Book book = new Books.Models.Book()
            {
                Title          = this.Title,
                Description    = this.Description,
                BookCoverImage = this.ImageUrl,
                AuthorId       = author.Id,
                Status         = status
            };
            this.Context.Books.Add(book);
            this.Context.SaveChanges();

            return(this.RedirectToPage("/Book/Details", new { id = book.Id }));
        }