Пример #1
0
 public void Insert(Book book)
 {
     using (var session = _provider.OpenSession())
     {
         session.Store(book);
         session.SaveChanges();
     }
 }
Пример #2
0
 public void Update(Book book)
 {
     var oldBook = FindById(book.Id);
     using (var session = _provider.OpenSession())
     {
         var old = session.Load<Book>(oldBook.Id);
         old.Author = book.Author;
         old.Title = book.Title;
         old.Description = book.Description;
         session.SaveChanges();
     }
 }
Пример #3
0
 public void Update(Book book)
 {
     _bookRepository.Update(book);
 }
Пример #4
0
 public void Insert(Book book)
 {
     _bookRepository.Insert(book);
 }
Пример #5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Library.Model.Book model)
 {
     return(dal.Update(model));
 }
Пример #6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Library.Model.Book model)
 {
     return(dal.Add(model));
 }
        public IHttpActionResult Create(Book book)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newBook = new Book
            {
                Title = book.Title,
                Rewiew = book.Rewiew

            };

            foreach (var genre in book.Genres)
            {
                var currGenreFromDb = this.data.Genres.All()
                                            .FirstOrDefault(g => g.Name == genre.Name);

                if (currGenreFromDb == null)
                {
                    currGenreFromDb = new Genre
                    {
                        Name = genre.Name
                    };
                    currGenreFromDb.Books.Add(newBook);
                    this.data.Genres.Add(currGenreFromDb);
                }

                newBook.Genres.Add(currGenreFromDb);
            }

            foreach (var author in book.Authors)
            {
                var currentAuthorFromDb = this.data.Authors.All()
                    .FirstOrDefault(a => a.FirstName == author.FirstName 
                                       && a.LastName == author.LastName);

                if (currentAuthorFromDb == null)
                {
                    currentAuthorFromDb = new Author
                    {
                        FirstName = author.FirstName,
                        LastName = author.LastName
                    };

                    currentAuthorFromDb.Books.Add(newBook);
                    this.data.Authors.Add(currentAuthorFromDb);
                }

                newBook.Authors.Add(currentAuthorFromDb);
            }

            this.data.Books.Add(newBook);
            this.data.SaveChanges();

            return Ok(newBook.BookId);
        }