示例#1
0
        public ActionResult AddComment(Guid id, string albumComment)
        {
            var album  = albumrepo.AddComment(id, albumComment);
            var albums = AlbumModelMapping.ModelToEntity(album);

            return(PartialView("IndexPartial", albums));
        }
示例#2
0
        public ActionResult Comment(int id, String comment)
        {
            AlbumRepository albums = new AlbumRepository();
            AlbumModel album = albums.GetById(id, withUser: true);
            UserRepository users = new UserRepository();
            UserModel user = users.GetByUsername(HttpContext.User.Identity.Name);

            NewCommentModel newComment = new NewCommentModel();
            //Wylaczone komentowanie
            if (!album.CommentsAllow)
            {
                newComment.Message = "You can't comment this album";
                return Json(newComment);
            }

            CommentModel model = new CommentModel();
            model.Album = album;
            model.Body = comment;
            model.Date = DateTime.Now;
            model.User = user;

            //Komentarze wlasciciela albumu sa automatycznie akceptowane, komentarze innego uzytkownika sa akceptowane
            //jesli wylaczono opcje autoryzacji
            newComment.Accepted = (album.User.Id == user.Id) || !album.CommentsAuth;
            newComment.Body = comment;
            newComment.Date = model.Date.ToString("dd/MM/yyyy HH:mm:ss");
            newComment.UserName = user.Login;
            newComment.Link = @Url.Action("ViewProfile", "User", new { userName = model.User.Login });

            model.Accepted = newComment.Accepted;
            if (user != null)
            {
                if (albums.AddComment(model))
                {
                    newComment.Id = model.Id ?? 1;
                    newComment.Message = "Your comment has been saved.";
                    //funkcja automatycznie sprawdza czy wyslac powiadomienie
                    Helpers.NotifyCommentObserver(model);
                }
                else
                {
                    newComment.Message = "Can't add comment.";
                    newComment.Body = null;
                }

            }
            else
            {
                newComment.Body = null;
                newComment.Message = "You need to be logged in to comment";
            }

            return Json(newComment);
        }