コード例 #1
0
 public Comment CreateComment(long playlistId, string text, string userEmail)
 {
     var comment = new Comment
     {
         Text = text,
         User = userRepo.ReadUser(userEmail),
         TimeStamp = DateTime.Now
     };
     return repo.CreateComment(playlistId, comment);
 }
コード例 #2
0
        public ActionResult Create(Comment comment, long id)
        {
            var username = User.Identity.Name;

            var createdComment = playlistManager.CreateComment(id, comment.Text, User.Identity.Name);

            if(createdComment != null)
                return Json(createdComment);
            else 
                return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
        }
コード例 #3
0
        public Comment CreateComment(long playlistId, Comment comment)
        {
            var playlist = context.Playlists
                .Include(p => p.Comments)
                .Single(p => p.Id == playlistId);

            var user = context.User.Single(u => u.Id == comment.User.Id);
            comment.User = user;

            var createdComment = context.Comments.Add(comment);
            playlist.Comments.Add(createdComment);

            context.SaveChanges();
            return comment;
        }