예제 #1
0
        public ActionResult Comment(BookComment comment, int CommentBookID, string Comment_Content)
        {
            #region
            BooksDetails a = new BooksDetails(CommentBookID);
            int          UserID;
            var          UserComment = a.Bc;
            ViewBag.Comment = UserComment;
            UserID          = Convert.ToInt32(Session["User_id"]);
            //string textarea = Request["Comment_Content"];
            if (ModelState.IsValid)
            {
                if (Comment_Content != "")
                {
                    comment.UserID          = UserID;
                    comment.BookID          = CommentBookID;
                    comment.Comment_Content = Comment_Content;
                    comment.Comment_Time    = System.DateTime.Now;
                    imall.AddComment(comment);
                    UserComment     = a.Bc;
                    ViewBag.Comment = UserComment;
                    return(PartialView(ViewBag.Comment as IEnumerable <BookComment>));
                }
                else
                {
                    return(PartialView(ViewBag.Comment as IEnumerable <BookComment>));
                }
            }
            return(PartialView(ViewBag.Comment as IEnumerable <BookComment>));

            #endregion
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("BookCommentID,UserID,BookID,Comment,CommentDate,CommentEnabled")] BookComment bookComment)
        {
            if (id != bookComment.BookCommentID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bookComment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookCommentExists(bookComment.BookCommentID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserID"] = new SelectList(_context.ApplicationUsers, "Id", "FirstName", bookComment.UserID);
            ViewData["BookID"] = new SelectList(_context.Book, "BookID", "Edition", bookComment.BookID);
            return(View(bookComment));
        }
        public ActionResult New(BookComment bookComment)
        {
            bookComment.Likes        = 0;
            bookComment.DataAprobare = DateTime.Now;
            bookComment.Book         = db.Books.Find(bookComment.BookId);
            bookComment.UserId       = User.Identity.GetUserId();
            bookComment.User         = db.Users.Find(bookComment.UserId);

            try
            {
                if (ModelState.IsValid)
                {
                    db.BookComments.Add(bookComment);
                    db.SaveChanges();
                    TempData["message"] = "Comentariul a fost adăugat!";
                    return(Content("Succes"));
                }
                else
                {
                    return(Content("Error"));
                }
            }
            catch (Exception e)
            {
                TempData["message"] = "Excepție: " + e.Message;
                return(View("~/Views/Shared/NoRight.cshtml"));
            }
        }
예제 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("CommentId,Comments,ThisDateTime,BookISBN,Rating")] BookComment bookComment)
        {
            if (id != bookComment.CommentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bookComment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookCommentExists(bookComment.CommentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(bookComment));
        }
 public ActionResult Edit(int id, BookComment requestBookComment)
 {
     try
     {
         BookComment bookComment = db.BookComments.Find(id);
         if (ModelState.IsValid)
         {
             var UserId = User.Identity.GetUserId();
             if (User.IsInRole("Administrator") || UserId == bookComment.UserId)
             {
                 if (TryUpdateModel(bookComment))
                 {
                     bookComment.Comentariu   = requestBookComment.Comentariu;
                     bookComment.DataAprobare = DateTime.Now;
                     db.SaveChanges();
                 }
                 return(Content("Succes"));
             }
             else
             {
                 return(Content("NoRight"));
             }
         }
         else
         {
             return(Content("Error"));
         }
     }
     catch (Exception e)
     {
         return(Content("Exception:" + e.Message));
     }
 }
예제 #6
0
        public BookComment Add(string content, int bookId, string userId)
        {
            if (string.IsNullOrWhiteSpace(content) || string.IsNullOrWhiteSpace(userId))
            {
                return(null);
            }

            var user = this.users.GetById(userId);

            if (user == null)
            {
                return(null);
            }

            var comment = new BookComment()
            {
                Content  = content,
                BookId   = bookId,
                AuthorId = user.Id
            };

            this.bookComments.Add(comment);
            this.bookComments.SaveChanges();
            return(this.bookComments.GetById(comment.Id));
        }
예제 #7
0
        /// <summary>
        /// 归还图书
        /// </summary>
        /// <param name="model">图书评价信息</param>
        /// <param name="userId">借阅用户</param>
        /// <returns>true or false</returns>
        public bool Return(CommentBookModel model, int userId)
        {
            if (model == null)
            {
                throw new InvalidOperationException("图书评价信息无效。");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                var book = dbContext.Books.FirstOrDefault(it => it.Id == model.BookId);
                if (book == null)
                {
                    throw new InvalidOperationException("借阅图书不存在。");
                }

                var borrow =
                    dbContext.BookBorrows.FirstOrDefault(
                        it =>
                        it.UserId == userId && it.BookId == model.BookId &&
                        it.Status == (int)UserBorrowStatus.Borrowing);

                if (borrow == null)
                {
                    throw new InvalidOperationException("借阅记录不存在。");
                }

                if (!book.Reader.HasValue || book.Reader.Value != userId)
                {
                    throw new InvalidOperationException("图书未被当前用户借出。");
                }

                model.ValidRating(); //验证评分

                //添加评价
                var comment = new BookComment()
                {
                    BookId      = model.BookId,
                    UserId      = userId,
                    Comment     = model.Comment,
                    Rating      = model.Rating,
                    CreatedDate = DateTime.Now
                };

                dbContext.BookComments.Add(comment);

                //更新借书记录
                borrow.Status     = (int)UserBorrowStatus.Returned;
                borrow.ReturnDate = DateTime.Now; //实际归还时间

                //更新图书状态
                book.Status = (int)BookStatus.Stored;
                book.Reader = null;

                dbContext.SaveChanges();
            }

            return(true);
        }
예제 #8
0
 private BookComment RowToBookComment(DataRow dr)
 {
     Model.BookComment bookcomment = new BookComment();
     bookcomment.BookId        = Convert.ToInt32(dr["BookId"]);
     bookcomment.CreatDateTime = Convert.ToDateTime(dr["CreatDateTime"]);
     bookcomment.Id            = Convert.ToInt32(dr["Id"]);
     bookcomment.Msg           = dr["Msg"].ToString();
     return(bookcomment);
 }
예제 #9
0
        public async Task <IActionResult> DisabledComment(int id)
        {
            BookComment bookComment = _context.BookComments.Where(bc => bc.BookCommentID == id).First();

            bookComment.CommentEnabled = false;
            _context.Update(bookComment);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", "Books", new { id = bookComment.BookID }));
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("CommentId,Comments,ThisDateTime,BookISBN,Rating")] BookComment bookComment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bookComment);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(bookComment));
        }
        public async Task <BookComment> AddBookComment(BookComment bookComment)
        {
            bookComment.User = await _applicationContext.Users.FindAsync(bookComment.UserId);

            bookComment.Book = await _applicationContext.Books.FindAsync(bookComment.BookId);

            await _applicationContext.BookComments.AddAsync(bookComment);

            await _applicationContext.SaveChangesAsync();

            return(await _applicationContext.BookComments.FirstOrDefaultAsync(w =>
                                                                              string.Equals(w.Id, bookComment.Id)));
        }
예제 #12
0
        public async Task <IActionResult> Create(string Comment, [Bind("BookCommentID,UserID,BookID,Comment,CommentDate,CommentEnabled")] BookComment bookComment)
        {
            var userId = int.Parse(_userManager.GetUserId(HttpContext.User));

            bookComment.UserID         = userId;
            bookComment.CommentDate    = DateTime.Now;
            bookComment.CommentEnabled = true;
            bookComment.Comment        = Comment;
            _context.Add(bookComment);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", "Books", new { id = bookComment.BookID }));
        }
        public static BookCommentModel ToModel(this BookComment entity)
        {
            var model = new BookCommentModel()
            {
                Id          = entity.Id,
                BookId      = entity.BookId,
                UserId      = entity.UserId,
                Comment     = entity.Comment,
                Rating      = entity.Rating.HasValue ? entity.Rating.Value : 0,
                CreatedDate = entity.CreatedDate
            };

            return(model);
        }
예제 #14
0
        public void CreateBookComment(string comment, Book book)
        {
            BookComment bc = new BookComment();

            bc.CommentID = Guid.NewGuid();
            bc.BookID    = book.BookID;
            bc.Comment   = comment;
            bc.Date      = DateTime.Now;
            bc.UserID    = DataSettings.Default.User.UserID;
            bc.Against   = 0;
            bc.Support   = 0;
            DB.BookComments.InsertOnSubmit(bc);
            DB.SubmitChanges();
        }
        public static BookComment ToEntity(this BookCommentModel model)
        {
            var entity = new BookComment()
            {
                Id          = model.Id,
                BookId      = model.BookId,
                UserId      = model.UserId,
                Comment     = model.Comment,
                Rating      = model.Rating,
                CreatedDate = model.CreatedDate
            };

            return(entity);
        }
예제 #16
0
        /// <summary>
        /// 添加或修改用户图书评论
        /// </summary>
        /// <param name="model">评论信息</param>
        /// <param name="userId">借阅用户</param>
        /// <returns>是否评论成功</returns>
        public bool Comment(CommentBookModel model, int userId)
        {
            if (model == null)
            {
                throw new InvalidOperationException("图书评价信息无效。");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                var user = dbContext.Users.SqlQuery("select * from [user] where id = 2");

                if (user != null)
                {
                }

                var book = dbContext.Books.FirstOrDefault(it => it.Id == model.BookId);
                if (book == null)
                {
                    throw new InvalidOperationException("图书不存在。");
                }

                model.ValidRating(); //验证评分

                var comment =
                    dbContext.BookComments.FirstOrDefault(it => model.CommentId.HasValue && it.Id == model.CommentId); //获取评论

                if (comment != null)                                                                                   //编辑评论
                {
                    comment.Rating  = model.Rating;
                    comment.Comment = model.Comment;
                }
                else //添加评价
                {
                    comment = new BookComment()
                    {
                        BookId      = model.BookId,
                        UserId      = userId,
                        Comment     = model.Comment,
                        Rating      = model.Rating,
                        CreatedDate = DateTime.Now
                    };

                    dbContext.BookComments.Add(comment);
                }

                //dbContext.SaveChanges();
            }

            return(true);
        }
예제 #17
0
        //Get All Commnet of Dorm
        public static List <BookComment> GetAllCommentBookDorm(string email, int id)
        {
            List <BookComment> list = new List <BookComment>();

            Mydatabase.sql = $"select {Helpers.tbUserProfile}.{Helpers.colEmailProfile},{Helpers.tbUserProfile}.{Helpers.colImageProfile},{Helpers.tbBookComment}.{Helpers.colCommentDormComment},{Helpers.tbBookComment}.{Helpers.colRatingDormComment} " +
                             $"from {Helpers.tbUserProfile},{Helpers.tbBookComment} where {Helpers.tbUserProfile}.{Helpers.colEmailProfile} = {Helpers.tbBookComment}.{Helpers.colEmailUserDormComment} " +
                             $"and {Helpers.tbBookComment}.{Helpers.colEmailOwnerDormComment} = @Email and {Helpers.tbBookComment}.{Helpers.colIdDormDormComment} = @Id;";
            try
            {
                Mydatabase.OpenConnection();
                Mydatabase.cmd.CommandType = CommandType.Text;;
                Mydatabase.cmd.CommandText = Mydatabase.sql;
                Mydatabase.cmd.Parameters.Clear();
                Mydatabase.cmd.Parameters.AddWithValue("@Email", email);
                Mydatabase.cmd.Parameters.AddWithValue("@Id", id);

                Mydatabase.rd = Mydatabase.cmd.ExecuteReader();
                while (Mydatabase.rd.Read())
                {
                    BookComment bookDorm = new BookComment();
                    bookDorm.Owner = email;
                    bookDorm.Id    = id;
                    bookDorm.User  = Mydatabase.rd.GetString(0);
                    try
                    {
                        bookDorm.Image = Helpers.ConvertByteToImageBitmap((byte[])Mydatabase.rd.GetValue(1));
                    }
                    catch (Exception exception)
                    {
                        bookDorm.Image = new System.Windows.Media.Imaging.BitmapImage(new Uri("../../images/blank_account.png", UriKind.RelativeOrAbsolute));
                    }

                    bookDorm.Comment = Mydatabase.rd.GetString(2);
                    bookDorm.Rating  = Mydatabase.rd.GetInt32(3);
                    list.Add(bookDorm);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error GetAllCommentBookDorm " + e.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mydatabase.CloseConnection();
            }

            return(list);
        }
        public ActionResult Delete(int id)
        {
            BookComment bookComment = db.BookComments.Find(id);

            if (User.IsInRole("Administrator") || User.Identity.GetUserId() == bookComment.UserId)
            {
                TempData["message"] = "Comentariul a fost șters !";
                db.BookComments.Remove(bookComment);
                db.SaveChanges();
                return(Content("Succes"));
            }
            else
            {
                return(Content("NoRight"));
            }
        }
 protected void btnBookComment_Click(object sender, EventArgs e)
 {
     if (Session["Account"] != null && txtnewcomment.Text != "")
     {
         BookComment oBookComment = new BookComment();
         oBookComment.Comment = txtnewcomment.Text;
         oBookComment.CommentDate = DateTime.Now.ToShortDateString();
         oBookComment.BookId = Convert.ToInt32(Request.QueryString["BookId"]);
         oBookComment.AccountId = ((Account)Session["Account"]).Id;
         BookCommentController oBookCommentController = new BookCommentController();
         oBookCommentController.BookCommentCreate(oBookComment);
     }
     else
     {
         Response.Redirect("UyeOl.aspx");
     }
 }
예제 #20
0
        public ActionResult AddCommentInfo(BookComment commentadd)
        {
            BookComment commentinfo = new BookComment();

            commentinfo.UserId  = commentadd.UserId;
            commentinfo.BookId  = commentadd.BookId;
            commentinfo.Msg     = commentadd.Msg;
            commentinfo.RegTime = DateTime.Now;
            if (commentbll.AddEntity(commentinfo) != null)
            {
                return(Content("ok"));
            }
            else
            {
                return(Content("no"));
            }
        }
예제 #21
0
        public ActionResult Add(IFormCollection form)
        {
            var    comment  = form["Comment"].ToString();
            var    bookISBN = form["bookISBN"].ToString();
            var    rating   = int.Parse(form["Rating"]);
            string userId;

            if (form["Anonymous"].ToString() == "Checked")
            {
                userId = null;
            }
            else
            {
                userId = form["UserId"].ToString();
            }

            BookComment artComment = new BookComment()
            {
                BookISBN     = bookISBN,
                Comments     = comment,
                Rating       = rating,
                ThisDateTime = DateTime.Now,
                UserId       = userId
            };

            var ratings = _context.Comments.Where(d => d.BookISBN.Equals(bookISBN)).ToList();
            int ratingSum;
            int ratingCount;

            ratingSum   = ratings.Sum(d => d.Rating.Value) + rating;
            ratingCount = ratings.Count() + 1;

            var book = _context.Books.Where(x => x.ISBN.Equals(bookISBN)).FirstOrDefault <Book>();

            book.Rating = ratingSum / ratingCount;


            _context.Entry(book).State = EntityState.Modified;
            _context.SaveChanges();

            _context.Comments.Add(artComment);
            _context.SaveChanges();

            return(RedirectToAction("ShowBook", "Home", new { field = bookISBN.ToString() }));
        }
        public async Task <IActionResult> Put(BookComment input, int id,
                                              [FromServices] BookCommentService service)
        {
            try
            {
                var item = await service.Update(id, input);

                return(Ok(item));
            }
            catch (HttpResponseException err)
            {
                return(err.ToResponse());
            }
            catch (Exception err)
            {
                return(StatusCode(SERVER_ERROR_CODE, err.Message));
            }
        }
예제 #23
0
        public async Task AddBookCommentAsync(int bookId, BookComment comment)
        {
            // Get book
            var book = _context.Book
                       .Where(b => b.Id == bookId)
                       .Include(b => b.ListComments)
                       .FirstOrDefault();

            // Lock for modification
            _context.Update(book);

            // Append comments
            List <BookComment> result = book.ListComments.ToList <BookComment>();

            result.Add(comment);

            book.ListComments = result;
            await _context.SaveChangesAsync();
        }
예제 #24
0
        public void DeleteBookComment_GoodArgument_Success()
        {
            var bookComment = new BookComment
            {
                Id               = "123",
                Comment          = "SomeBookComment",
                UserId           = "SomeUserId",
                BookId           = "SomeBookId",
                DateTime         = DateTime.Now,
                Book             = new Book(),
                User             = new User(),
                BookCommentLikes = new List <BookCommentLike>()
            };

            _mockCommentRepository.Setup(w => w.GetBookComment(It.IsAny <string>())).ReturnsAsync(bookComment);
            using var commentService = new CommentService(_mockCommentRepository.Object, _mapper);
            var deleteBookComment = commentService.DeleteBookComment("123");

            _mockCommentRepository.Verify(w => w.DeleteBookComment(It.IsAny <BookComment>()), Times.Once);
        }
예제 #25
0
 public void Init()
 {
     _mockCommentRepository = new Mock <ICommentRepository>();
     _mapperConfiguration   = new MapperConfiguration(cfg =>
                                                      cfg.AddProfiles(new List <Profile>
     {
         new BookCommentProfile(),
         new AuthorCommentProfile()
     }));
     _mapper      = new Mapper(_mapperConfiguration);
     _bookComment = new BookComment
     {
         Id               = Guid.NewGuid().ToString(),
         Comment          = "SomeBookComment",
         UserId           = "SomeUserId",
         BookId           = "SomeBookId",
         DateTime         = DateTime.Now,
         Book             = new Book(),
         User             = new User(),
         BookCommentLikes = new List <BookCommentLike>()
     };
     _bookComments = new List <BookComment>
     {
         _bookComment, _bookComment, _bookComment
     };
     _authorComment = new AuthorComment
     {
         Id                 = Guid.NewGuid().ToString(),
         Comment            = "SomeAuthorComment",
         UserId             = "SomeUserId",
         AuthorId           = "SomeAuthorId",
         DateTime           = DateTime.Now,
         Author             = new Author(),
         User               = new User(),
         AuthorCommentLikes = new List <AuthorCommentLike>()
     };
     _authorComments = new List <AuthorComment>
     {
         _authorComment, _authorComment, _authorComment
     };
 }
        public async Task <IActionResult> Post(BookComment input,
                                               [FromServices] BookCommentService service,
                                               [FromServices] UserService userService)
        {
            try
            {
                var customer = await userService.GetCustomer(User);

                input.CustomerId = customer.UserId;
                var item = await service.Store(input);

                return(Ok(item));
            }
            catch (HttpResponseException err)
            {
                return(err.ToResponse());
            }
            catch (Exception err)
            {
                return(StatusCode(SERVER_ERROR_CODE, err.Message));
            }
        }
예제 #27
0
        public async Task <TransactionResult> InsertCommentAsync(string id, BookComment bookComment)
        {
            try
            {
                SetCommentsCreatedDateTime(bookComment);
                var book = await GetByIdAsync(id);

                var comments = book.Comments;
                if (comments == null)
                {
                    comments = new List <BookComment>();
                }
                Utility.TrimCharProperties(typeof(BookComment), bookComment);
                comments.Add(bookComment);
                await base.Repository.UpdateAsync(book.Id, book);

                return(new TransactionResult());
            }
            catch (Exception ex)
            {
                return(GetTransactionException(ex));
            }
        }
예제 #28
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string content = context.Request["content"];

            if (IsForbid(content))
            {
                context.Response.Write("no");
            }
            else
            {
                BookComment bc = new BookComment();
                bc.BookId         = Convert.ToInt32(context.Request["bookid"]);
                bc.CreateDateTime = DateTime.Now;

                //将敏感词替换为*号
                List <Articel_Words> awList = new Articel_WordsBll().GetModelList("IsForbid=0");
                foreach (var item in awList)
                {
                    if (content.Contains(item.WordPattern))
                    {
                        content = content.Replace(item.WordPattern, "***");
                    }
                }

                bc.Msg = content;
                int r = new BookCommentBll().Add(bc);
                if (r >= 1)
                {
                    context.Response.Write("ok");
                }
                else
                {
                    context.Response.Write("error");
                }
            }
        }
예제 #29
0
        public BookComment Add(string content, int bookId, string userId)
        {
            if (string.IsNullOrWhiteSpace(content) || string.IsNullOrWhiteSpace(userId))
            {
                return null;
            }

            var user = this.users.GetById(userId);
            if (user == null)
            {
                return null;
            }

            var comment = new BookComment()
            {
                Content = content,
                BookId = bookId,
                AuthorId = user.Id
            };

            this.bookComments.Add(comment);
            this.bookComments.SaveChanges();
            return this.bookComments.GetById(comment.Id);
        }
예제 #30
0
        public ActionResult EditCommentInfo(BookComment commentupdate)
        {
            int id          = Convert.ToInt32(Request["Id"]);
            var commentinfo = commentbll.LoadEntities(c => c.Id == id).FirstOrDefault();

            if (commentinfo != null)
            {
                commentinfo.UserId = commentupdate.UserId;
                commentinfo.BookId = commentupdate.BookId;
                commentinfo.Msg    = commentupdate.Msg;
                if (commentbll.UpdateEntity(commentinfo))
                {
                    return(Content("ok"));
                }
                else
                {
                    return(Content("no"));
                }
            }
            else
            {
                return(Content("no"));
            }
        }
예제 #31
0
        public async Task <IActionResult> Details(DetailsViewModel detailsViewModel)
        {
            var user = await _userManager.GetUserAsync(User);

            switch (detailsViewModel.Action)
            {
            case "reset":
            {
                var answer = await _context.Answers
                             .Include(a => a.Book)
                             .FirstOrDefaultAsync(a => a.BookId == detailsViewModel.BookId && a.UserId == user.Id);

                answer.ReasonForRestart = detailsViewModel.ReasonForRestart;          // presence of ReasonForRestart indicates request for restart
                _context.Answers.Update(answer);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = detailsViewModel.BookId }));
            }

            case "saveOpinion":
            {
                var bookComment = await _context.BookComments
                                  .SingleOrDefaultAsync(bn => bn.UserId == user.Id &&
                                                        bn.BookId == detailsViewModel.BookId);

                if (bookComment == null)
                {
                    var newBookComment = new BookComment
                    {
                        BookId = detailsViewModel.BookId,
                        UserId = user.Id,
                        Text   = detailsViewModel.BookCommentText,
                        Share  = detailsViewModel.Share
                    };
                    _context.BookComments.Add(newBookComment);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    bookComment.Share = detailsViewModel.Share;
                    bookComment.Text  = detailsViewModel.BookCommentText;
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction("Details", new { id = detailsViewModel.BookId }));
            }

            case "answerText":
            {
                var bookOpinion = await _context.BookOpinions
                                  .SingleOrDefaultAsync(bn => bn.UserId == user.Id &&
                                                        bn.BookId == detailsViewModel.BookId);

                if (bookOpinion == null)
                {
                    var newBookOpinion = new BookOpinion
                    {
                        BookId     = detailsViewModel.BookId,
                        UserId     = user.Id,
                        AnswerText = detailsViewModel.BookOpinionText,
                        Share      = detailsViewModel.Share
                    };
                    _context.BookOpinions.Add(newBookOpinion);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    bookOpinion.Share      = detailsViewModel.Share;
                    bookOpinion.AnswerText = detailsViewModel.BookOpinionText;
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction("Details", new { id = detailsViewModel.BookId }));
            }

            case "makeNote":
            {
                var bookNote = await _context.BookNotes
                               .SingleOrDefaultAsync(bn => bn.UserId == user.Id &&
                                                     bn.BookId == detailsViewModel.BookId);

                if (bookNote == null)
                {
                    var newBookNote = new BookNote()
                    {
                        UserId = user.Id,
                        BookId = detailsViewModel.BookId,
                        Text   = detailsViewModel.BookNoteText
                    };
                    user.BookNotes.Add(newBookNote);
                    await _userManager.UpdateAsync(user);
                }
                else
                {
                    bookNote.Text = detailsViewModel.BookNoteText;
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction("Details", new { id = detailsViewModel.BookId }));
            }
            }

            return(NoContent());
        }
예제 #32
0
 public BookComment AddBookComment(long idBook, BookComment comment)
 {
     return(this.CreateNewElement <BookComment, Book>(comment, idBook));
 }