public void ThenTheSearchResultListShouldDisplayTheBooksInTheFollowingOrder(Table table)
        {
            var expectedBookList = new List<Book>();

            foreach (var tableRow in table.Rows)
            {
                var author = tableRow["Author"];
                var title = tableRow["Title"];

                var book = new Book { Author = author, Title = title };
                expectedBookList.Add(book);
            }

            var itemCount = selenium.FindElements(By.XPath("//table[@id='searchResultTable']/tbody/tr")).Count();
            var resultBookList = new List<Book>();
            const int headerCount = 0;
            for (int i = headerCount + 1; i <= itemCount; i++)
            {
                string title = selenium.FindElements(By.XPath("//table/tbody/tr[" + i + "]/td[@class='title']")).First().Text;
                string author = selenium.FindElements(By.XPath("//table/tbody/tr[" + i + "]/td[@class='author']")).First().Text;
                resultBookList.Add(new Book { Title = title, Author = author });
            }

            var expextedTitleList = expectedBookList.Select(ebl => ebl.Title).ToList();
            var resultTitleList = resultBookList.Select(ral => ral.Title).ToList();

            CollectionAssert.AreEqual(expextedTitleList, resultTitleList);
        }
        public IHttpActionResult PutBook(int id, Book book)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != book.Id)
            {
                return BadRequest();
            }

            db.Entry(book).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 public BookViewModel(Book book)
 {
     this.categoryNames = new HashSet<string>();
     this.Id = book.Id;
     this.Title = book.Title;
     this.Description = book.Description;
     this.EditionType = book.EditionType;
     this.Price = book.Price;
     this.Copies = book.Copies;
     this.AuthorId = book.AuthorId;
     this.ReleaseDate = book.ReleaseDate;
 }
 public BookDetailedViewModel(Book book)
 {
     this.Id = book.Id;
     this.Title = book.Title;
     this.Desciption = book.Desciption;
     this.Edition = book.Edition;
     this.Price = book.Price;
     this.Copies = book.Copies;
     this.AuthorId = book.AuthorId;
     this.AuthorName = book.Author.FirstName + " " + book.Author.LastName;
     this.Categories = book.Categories.Select(c => c.Name).ToList();
 }
        public IHttpActionResult PostBook(Book book)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Books.Add(book);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = book.Id }, book);
        }
 public AuthorBooksViewModel(Book book)
 {
     Title = book.Title;
     Description = book.Description;
     Price = book.Price;
     Copies = book.Copies;
     ReleaseDate = book.ReleaseDate;
     Edition = book.Edition;
     AgeRestriction = book.AgeRestriction;
     Categories = new List<CategoryViewModel>();
     foreach (var category in book.Categories)
     {
         Categories.Add(new CategoryViewModel(category));
     }
 }
        public IHttpActionResult AddBook(AddBooksBindingModels  model)
        {
            if (model == null)
            {
                this.ModelState.AddModelError("model", "the model is empty");
            }
            if (!ModelState.IsValid)
            {
                return this.BadRequest(ModelState);
            }

            var categories = model.Categories.Split(' ') ;
            var categoryList = new List<Category>();

            if (categories.Count() != 0)
            {

                foreach (var categoryName in categories)
                {
                    Category cat = new Category()
                    {
                        Name = categoryName
                    };
                    categoryList.Add(cat);
                }
            }

            var book = new Book()
            {
                Title = model.Title,
                Description = model.Description ?? null,
                Edition = model.Edition,
                Price = model.Price,
                AgeRestriction = model.Restriction,
                Copies = model.Copies,
                ReleaseDate = model.ReleaseDate,
                Author = db.Authors.First(a => a.Id==model.AuthorId) ?? null,
                RelatedBooks = db.Books.Where(b => b.Id == model.BookId).ToList().Count == 0 ? null : db.Books.Where(b => b.Id == model.BookId).ToList(),
                Categories = categoryList ?? null

            };
            db.Books.Add(book);
            db.SaveChanges();
            return this.Ok("created book  with id = "+ book.Id);
        }
Beispiel #8
0
 public void GivenTheFollowingBooks(Table givenBooks)
 {
     var db = new BookShopEntities();
     foreach (var row in givenBooks.Rows)
     {
         Book book = new Book { Author = row["Author"], Title = row["Title"] };
         if (givenBooks.Header.Contains("Price"))
             book.Price = Convert.ToDecimal(row["Price"]);
         else
             book.Price = _bookDefaultPrice;
         if (givenBooks.Header.Contains("Id"))
             _catalogContext.ReferenceBooks.Add(row["Id"], book);
         else
             _catalogContext.ReferenceBooks.Add(book.Title, book);
         db.AddToBooks(book);
     }
     db.SaveChanges();
 }
        public IHttpActionResult ChangeBook(int id ,Book changedBook)
        {
            var book = db.Books.First(b => b.Id == id);
            if (book ==null)
            {
                return this.NotFound();
            }
            book.Id=changedBook.Id == 0 ? book.Id : changedBook.Id;
            book.Copies = changedBook.Copies == 0 ? book.Copies : changedBook.Copies;
            book.Price = changedBook.Price == 0 ? book.Price : changedBook.Price;
            book.ReleaseDate = changedBook.ReleaseDate ?? book.ReleaseDate;
            book.Title = changedBook.Title == String.Empty ? book.Title : changedBook.Title;
            book.AgeRestriction = changedBook.AgeRestriction;
            book.Edition = changedBook.Edition;
            book.Author = changedBook.Author ?? book.Author;
            book.Categories = changedBook.Categories ?? book.Categories;
            book.Description = changedBook.Description == String.Empty ? book.Description : changedBook.Description;
            book.RelatedBooks = changedBook.RelatedBooks ?? book.RelatedBooks;

            db.SaveChanges();
            return this.Ok("changes has been made");
        }
 public BookSimpleViewModel(Book book)
 {
     this.Id = book.Id;
     this.Title = book.Title;
 }
        public IHttpActionResult PostBook([FromBody] BookPostBindingModel bookPost)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var categories = bookPost.Categories.Split(' ').Select(c => c.Trim()).ToList();
            var categoryList = new List<Category>();
            foreach (var category in categories)
            {
                var categoryDb = this.db.Categories.FirstOrDefault(ca => ca.Name == category);
                if (categoryDb == null)
                {
                    categoryList.Add(new Category() {Name = category});
                }
                else
                {
                    categoryList.Add(categoryDb);
                }
            }

            var newBook = new Book()
            {
                Title = bookPost.Title,
                Description = bookPost.Description,
                Price = bookPost.Price,
                Copies = bookPost.Copies,
                Edition = bookPost.EditinType,
                AgeRestriction = bookPost.AgeRestriction,
                Categories = categoryList,
                AuthorId = 1
            };

            db.Books.Add(newBook);
            db.SaveChanges();

            return this.Ok(bookPost);
        }
 public BookViewModel(Book book)
 {
     Title = book.Title;
 }
        public IHttpActionResult PostBook([FromBody]AddBookBindingModel bookBindingModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Book book = new Book(bookBindingModel.Title,
                bookBindingModel.Description,
                bookBindingModel.EditionType,
                bookBindingModel.Price,
                bookBindingModel.Copies,
                bookBindingModel.ReleaseDate);

            context.Books.Add(book);
            context.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = book.Id }, book);
        }
        public IHttpActionResult CreateBook([FromBody]BookBindingModel bindingBook)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var book = new Book() 
            {
                Title = bindingBook.Title,
                Edition = bindingBook.Edition,
                Price = bindingBook.Price,
                Copies = bindingBook.Copies,
                AuthorId = bindingBook.AuthorId
            };
            foreach (var item in bindingBook.Categories)
            {
                book.Categories.Add(new Category() { Name = item.Name});
            }

            context.SaveChanges();

            return this.Ok(book);
        }
 public SearchedBookViewModel(Book book)
 {
     Id = book.Id;
     Title = book.Title;
 }
        //POST/api/books
        public void PostBook(string title, string description, double price, int copies,
            DateTime releasedData, EditionType edition, int AgeRestriction, string categoryNames)
        {
            Book newBook = new Book()
            {
            Title = title,
            Description = description,
            Edition = edition,
            ReleaseDate = releasedData,
            Price = price,
            Copies = copies,
            AgeRestriction = AgeRestriction
            };
            string[] bookCategories = categoryNames.Split(' ').ToArray();
            foreach (var category in bookCategories)
            {
                var currentCategory = this.Data.Categories.First(c => c.Name == category);
                newBook.Categories.Add(currentCategory);

            }
            this.Data.Books.Add(newBook);
            this.Data.SaveChanges();
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Books EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBooks(Book book)
 {
     base.AddObject("Books", book);
 }
 /// <summary>
 /// Create a new Book object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="author">Initial value of the Author property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 public static Book CreateBook(global::System.Int32 id, global::System.String author, global::System.String title, global::System.Decimal price)
 {
     Book book = new Book();
     book.Id = id;
     book.Author = author;
     book.Title = title;
     book.Price = price;
     return book;
 }
        public IHttpActionResult PutBook(int id, [FromBody]PutBookBindingModel bookBindingModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Author author = context.Authors.Find(bookBindingModel.AuthorId);

            if (author == null)
            {
                return BadRequest("No author with specified AuthorId.");
            }

            var book = new Book(id,
                bookBindingModel.Title,
                bookBindingModel.Description,
                bookBindingModel.EditionType,
                bookBindingModel.Price,
                bookBindingModel.Copies,
                bookBindingModel.ReleaseDate,
                author.Id);

            context.Entry(book).State = EntityState.Modified;

            try
            {
                context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 public SearchBookViewModel(Book book)
 {
     this.Id = book.Id;
     this.Title = book.Title;
 }