Example #1
0
 public IEnumerable <BookReviews> GetReviews(int bookId)
 {
     try
     {
         string selectString = "select r.*, p.Username, p.UserPhoto from dbo.REVIEW as r inner join dbo.PERSON as p on r.PersonId = p.PersonId where BookId = @id";
         using (SqlConnection conn = new SqlConnection(connectionString))
         {
             conn.Open();
             using (SqlCommand command = new SqlCommand(selectString, conn))
             {
                 command.Parameters.AddWithValue("@id", bookId);
                 using (SqlDataReader reader = command.ExecuteReader())
                 {
                     List <BookReviews> result = new List <BookReviews>();
                     while (reader.Read())
                     {
                         BookReviews item = ReadBookReviews(reader);
                         result.Add(item);
                     }
                     return(result);
                 }
             }
         }
     }
     catch (Exception)
     {
         //future handling exceptions
         return(null);
     }
 }
Example #2
0
        public int Add(BookReviews t)
        {
            t.CreateDate = DateTime.Now;
            var result = iBookReviews_BLL.Add(t);

            return(result);
        }
Example #3
0
        public Task AddReviewAsync(string key, string username, string review, BookRating bookRating)
        {
            return(Task.Run(() =>
            {
                var bookReviewItem = new BookReviewItem
                {
                    BookRating = bookRating,
                    Text = review,
                    Username = username
                };

                var reviews = _reviewRepository.Get(key);

                if (reviews != null)
                {
                    reviews.BookReviewItems.Add(bookReviewItem);
                    _reviewRepository.Update(reviews);
                }
                else
                {
                    reviews = new BookReviews()
                    {
                        Id = key,
                        BookReviewItems = new List <BookReviewItem>
                        {
                            bookReviewItem
                        }
                    };
                    _reviewRepository.Add(reviews);
                }
            }));
        }
Example #4
0
        public void DeleteBookReviews(long id)
        {
            BookReviews BookReviews = GetBookReviews(id);

            if (BookReviews != null)
            {
                //_db.BooksReviews.Remove(BookReviews);
                _db.SaveChanges();
            }
        }
Example #5
0
        public void UpdateBookReviews(long id, BookReviews updatedBookReviews)
        {
            BookReviews BookReviews = GetBookReviews(id);

            if (BookReviews == null)
            {
                throw new Exception();
            }


            _db.SaveChanges();
        }
Example #6
0
        // Book review's
        private BookReviews ReadBookReviews(SqlDataReader reader)
        {
            int    reviewId  = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
            int    personId  = reader.IsDBNull(1) ? 0 : reader.GetInt32(1);
            int    bookId    = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
            int    rating    = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
            string rText     = reader.IsDBNull(4) ? "" : reader.GetString(4);
            string username  = reader.IsDBNull(5) ? "" : reader.GetString(5);
            string userPhoto = reader.IsDBNull(6) ? "" : reader.GetString(6);

            BookReviews item = new BookReviews()
            {
                ReviewId        = reviewId,
                PersonId        = personId,
                BookId          = bookId,
                ReviewRating    = rating,
                ReviewText      = rText,
                PersonUsername  = username,
                PersonUserPhoto = userPhoto
            };

            return(item);
        }
 public int Update(BookReviews t)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// 新增书评
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Add(BookReviews t)
        {
            var result = iBookReviews_DAL.Add(t);

            return(result);
        }
Example #9
0
 public void UpdateBooksReviews(long id, BookReviews BooksReviews)
 {
     throw new NotImplementedException();
 }
Example #10
0
 public BookReviews CreateBooksReviews(BookReviews BooksReviews)
 {
     throw new NotImplementedException();
 }
Example #11
0
 public BookReviews CreateBookReviews(BookReviews BookReviews)
 {
     _db.BookReview.Add(BookReviews);
     _db.SaveChanges();
     return(BookReviews);
 }