示例#1
0
        public void AddComment_ItemSentToDAL_ValidItemNoParrent(CommentDTO commentDto, Game game)
        {
            // Arrange
            _mock.Setup(a => a.Repository <Game>().FindBy(It.IsAny <Expression <Func <Game, bool> > >()))
            .Returns(new List <Game> {
                game
            });

            // Act
            _commentService.AddEntity(commentDto, game.Key);

            // Assert
            Mock.Verify(_mock);
        }
 public ActionResult AddComment()
 {
     if (Session["User"] is UserEntity user)
     {
         CommentEntity comment = new CommentEntity
         {
             Conetnt = Request.Form["content"].ToString(),
             UserId  = user.Id,
             MovieId = Convert.ToInt32(Request.Form["movieId"]),
             ParId   = 0
         };
         if (_commentService.AddEntity(comment))
         {
             return(Json(new ResultModel {
                 StatusCode = System.Net.HttpStatusCode.OK, Message = "Success"
             }));
         }
         else
         {
             return(Json(new ResultModel {
                 StatusCode = System.Net.HttpStatusCode.InternalServerError, Message = "An Error Occured When Saving Data"
             }));
         }
     }
     else
     {
         return(Redirect(""));
     }
 }
示例#3
0
        public HttpResponseMessage Post(string gamekey, [FromBody] CommentViewModel model)
        {
            if (!User.IsInRole("Admin"))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Access denied"));
            }

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            model.GameKey = gamekey;
            var commentDto = Mapper.Map <CommentDTO>(model);

            _commentService.AddEntity(commentDto, gamekey);
            return(Request.CreateResponse(HttpStatusCode.Created));
        }
示例#4
0
        public ActionResult NewComment(CommentViewModel newComment)
        {
            _logger.Info("Request to GameController.NewComment");
            if (ModelState.IsValid)
            {
                var commentDto = Mapper.Map <CommentViewModel, CommentDTO>(newComment);
                commentDto.GameId = _gameService.GetByKey(commentDto.GameKey).Id;
                if (_commentService.IsExist(newComment.Id))
                {
                    _commentService.EditEntity(commentDto, newComment.GameKey);
                }
                else
                {
                    _commentService.AddEntity(commentDto, newComment.GameKey);
                }

                return(PartialView("Success"));
            }
            return(PartialView("NewComment", newComment));
        }