public ActionResult NewComment(CommentViewModel model)
        {
            model.DatePosted = DateTime.Now;
            model.User       = User.Identity.Name;
            model.id         = Guid.NewGuid();


            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                var newComment = ModelMapper.ModelToEntity(model);
                repo.AddOrUpdate(newComment);
                return(Content("Comment added"));
            }

            return(Content("Couldn't add comment"));
        }
        public ActionResult NewComment(CommentViewModel model)
        {
            var identity = (ClaimsIdentity)User.Identity;
            var sid      = identity.Claims.First(x => x.Type == ClaimTypes.Sid);

            model.UserID = int.Parse(sid.Value);

            model.DatePosted = DateTime.Now;


            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                var newComment = EntityModelMapper.ModelToEntity(model);
                repo.AddOrUpdate(newComment);
                return(Content("Comment added"));
            }

            return(Content("Couldn't add comment"));
        }
示例#3
0
 public bool AddOrUpdate(Comment comment)
 {
     return(_repo.AddOrUpdate(comment));
 }
示例#4
0
        public void Post([FromBody] CommentModel model)
        {
            var entity = CommentModelToEntity(model);

            commentRepository.AddOrUpdate(entity);
        }