예제 #1
0
        private void CheckComment(string commentMsg)
        {
            var comment = new AlbumComment(album, commentMsg, new AgentLoginData(agentName));

            repository.HandleTransaction(ctx => {
                new UserCommentNotifier().CheckComment(comment, entryLinkFactory, ctx);
            });
        }
예제 #2
0
        public AlbumComment AddComment(AlbumComment comment, Album album, User user)
        {
            comment.User = user;

            album.Comments.Add(comment);

            dbContext.SaveChanges();
            return(comment);
        }
        public AlbumComment AddComment(CommentModel comment, Album album, User user)
        {
            var albumComment = new AlbumComment()
            {
                Text      = comment.Text,
                CreatedAt = DateTime.Now
            };

            return(this.albumManager.AddComment(albumComment, album, user));
        }
예제 #4
0
 public CommentAlbumModel Converter(AlbumComment c)
 {
     return(new CommentAlbumModel()
     {
         Id = c.Id,
         Comment = c.Comment,
         UserId = c.UserId,
         Date = c.Date,
         DataId = c.AlbumId,
         UserInfo = userInfoDto.ConvertToUserInfoModel(c.User.UserInfoes).FirstOrDefault()
     });
 }
예제 #5
0
        public virtual void SaveOrUpdate(AlbumComment comment)
        {
            ISession session = _sessionManager.OpenSession();

            // can't seem to get this to work automagically
            if (comment.Id == -1)
            {
                session.Save(comment);
            }
            else
            {
                session.Update(comment);
            }
            session.Flush();
        }
예제 #6
0
 public HttpResponseMessage DeleteComment([FromUri] int albumId, [FromUri] long commentId)
 {
     using (var db = new OnlineMusicEntities())
     {
         AlbumComment comment = (from c in db.AlbumComments
                                 where c.Id == commentId
                                 select c).FirstOrDefault();
         if (comment == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.OK, "Không tìm thấy comment id=" + commentId));
         }
         db.AlbumComments.Remove(comment);
         db.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
 }
예제 #7
0
        protected void buttonSubmit_Click(object sender, EventArgs e)
        {
            // Nếu đã đánh dấu I agree, có nội dung comment, có tên author, email hoặc đã đăng nhập
            if (chkAgree.Checked && !string.IsNullOrEmpty(textBoxComment.Text) && ((!string.IsNullOrEmpty(textBoxAuthor.Text) && !string.IsNullOrEmpty(textBoxEmail.Text)) || PageEngine.User.Identity is User))
            {
                if (textBoxVerifierCode.Text == imageVerifier.Text)
                {
                    AlbumComment comment = new AlbumComment();
                    comment.Deleted = false;
                    if (Page.User.Identity is User)
                    {
                        comment.Author   = ((User)Page.User.Identity).FullName;
                        comment.AuthorId = ((User)Page.User.Identity);
                        comment.Email    = ((User)Page.User.Identity).Email;
                    }
                    else
                    {
                        comment.Author   = textBoxAuthor.Text;
                        comment.AuthorId = null;
                        comment.Email    = textBoxEmail.Text;
                    }

                    comment.DateCreated  = DateTime.Now;
                    comment.DateModified = DateTime.Now;
                    comment.Comment      = textBoxComment.Text;
                    comment.Status       = 0;
                    comment.Album        = _album;
                    comment.IP           = Request.UserHostAddress;
                    chkAgree.Checked     = false;
                    textBoxComment.Text  = string.Empty;

                    _galleryModule.GetAlbumService().SaveOrUpdate(comment);

                    rptReviews.DataSource = _album.Comments;
                    rptReviews.DataBind();

                    imageVerifier.Refresh();
                }
                else
                {
                    labelFailedVerified.Visible = true;
                }
            }
        }
예제 #8
0
        public HttpResponseMessage AddCommentToAlbum([FromUri] int id, [FromBody] CommentAlbumModel commentModel)
        {
            if (commentModel.DataId != id)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Dữ liệu không phù hợp"));
            }
            using (var db = new OnlineMusicEntities())
            {
                AlbumComment comment = new AlbumComment();
                commentModel.UpdateEntity(comment);
                comment.Date = DateTime.Now;
                db.AlbumComments.Add(comment);
                db.SaveChanges();

                comment.User = (from u in db.Users where u.Id == comment.UserId select u).FirstOrDefault();
                commentModel = commentDto.GetCommentQuery(db, awhereClause: null).Where(c => c.Id == comment.Id).FirstOrDefault();

                return(Request.CreateResponse(HttpStatusCode.Created, commentModel));
            }
        }
        public async Task <bool> CreateCommentAsync(string albumId, string content, User user)
        {
            ArgumentValidator.ThrowIfNullOrEmpty(albumId, nameof(albumId));
            ArgumentValidator.ThrowIfNullOrEmpty(content, nameof(content));
            ArgumentValidator.ThrowIfNull(user, nameof(user));

            var comment = new AlbumComment
            {
                AuthorId  = user.Id,
                AlbumId   = albumId,
                Comment   = content,
                CreatedOn = DateTime.UtcNow
            };

            await this.albumCommentRepository.AddAsync(comment);

            var result = await this.albumCommentRepository.SaveChangesAsync();

            return(result != 0);
        }
예제 #10
0
 public HttpResponseMessage EditComment([FromUri] int id, [FromBody] CommentAlbumModel commentModel)
 {
     if (commentModel.DataId != id)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Dữ liệu không phù hợp"));
     }
     using (var db = new OnlineMusicEntities())
     {
         AlbumComment comment = (from c in db.AlbumComments
                                 where c.Id == commentModel.Id
                                 select c).FirstOrDefault();
         if (comment == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.OK, "Không tìm thấy comment id=" + commentModel.Id));
         }
         commentModel.UpdateEntity(comment);
         db.SaveChanges();
         commentModel = commentDto.GetCommentQuery(db, awhereClause: null).Where(c => c.Id == comment.Id).FirstOrDefault();
         return(Request.CreateResponse(HttpStatusCode.OK, commentModel));
     }
 }
예제 #11
0
        protected void rptReviews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is AlbumComment)
            {
                AlbumComment comment     = (AlbumComment)e.Item.DataItem;
                Label        labelAuthor = e.Item.FindControl("labelAuthor") as Label;
                if (labelAuthor != null)
                {
                    if (comment.AuthorId != null)
                    {
                        comment.Author = comment.AuthorId.FullName;
                    }
                    labelAuthor.Text = string.Format("{0:F} by {1}", comment.DateCreated, comment.Author);
                }

                Label labelContent = e.Item.FindControl("labelContent") as Label;
                if (labelContent != null)
                {
                    labelContent.Text = string.Format("{0}", comment.Comment);
                }
            }
        }
예제 #12
0
        public static bool setComment2Album(AlbumComment albumComment, string connString)
        {
            #region code

            bool rs;
            using (var conn = new SqlConnection(connString))
            {
                try
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "sony_sp_add_album_comment";
                        cmd.Parameters.AddWithValue("@username",
                            String.IsNullOrEmpty(albumComment.UserName) ? "admin" : albumComment.UserName);
                        cmd.Parameters.AddWithValue("@albumId", albumComment.AlbumId);
                        cmd.Parameters.AddWithValue("@photoId", albumComment.PhotoId);
                        cmd.Parameters.AddWithValue("@status", albumComment.Status ? 1 : 0);
                        cmd.Parameters.AddWithValue("@comment", albumComment.Comment);
                        var returnVal = new SqlParameter("@returnVal", SqlDbType.Int)
                        {
                            Direction = ParameterDirection.Output
                        };
                        cmd.Parameters.Add(returnVal);

                        cmd.ExecuteNonQuery();
                        rs = ((int) cmd.Parameters["@returnVal"].Value != 0);
                    }
                }
                catch (Exception ex)
                {
                    writeLog("", "Add Album Comment Error: " + ex.Message, connString);
                    return false;
                }
            }
            return rs;

            #endregion
        }
예제 #13
0
        public static List<AlbumComment> getListCommentOfAlbum(int photoId, string connString)
        {
            #region code

            var lists = new List<AlbumComment>();
            using (var conn = new SqlConnection(connString))
            {
                try
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "sony_sp_get_all_album_photo_comment_by_photo_id";
                        cmd.Parameters.AddWithValue("@photoId", photoId);

                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var albumComment = new AlbumComment
                                {
                                    Id = (int) reader["id"],
                                    UserName = reader["username"].ToString(),
                                    AlbumId = (int) reader["albumId"],
                                    PhotoId = (int) reader["photoId"],
                                    Status =
                                        reader["status"].ToString().Equals("1") ||
                                        reader["status"].ToString().Equals("True"),
                                    Created = (DateTime) reader["created"],
                                    Comment = reader["comment"].ToString()
                                };
                                lists.Add(albumComment);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    writeLog("", String.Format("Get Album Comment Error: photoId={0}, CauseBy:{1}", photoId, ex.Message),
                        connString);
                    return new List<AlbumComment>();
                }
            }
            return lists;

            #endregion
        }
예제 #14
0
        /// <summary>
        ///     Get list all album comment
        /// </summary>
        /// <param name="connString"></param>
        /// <returns></returns>
        public static List<AlbumComment> getListComment(string connString)
        {
            #region code

            var lists = new List<AlbumComment>();
            using (var conn = new SqlConnection(connString))
            {
                try
                {
                    conn.Open();
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "sony_sp_get_all_album_comment";

                        using (var reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var albumComment = new AlbumComment
                                {
                                    Id = (int) reader["id"],
                                    AlbumId =
                                        String.IsNullOrEmpty(reader["albumId"].ToString()) ? 0 : (int) reader["albumId"],
                                    PhotoId =
                                        String.IsNullOrEmpty(reader["photoId"].ToString()) ? 0 : (int) reader["photoId"],
                                    Comment = reader["comment"].ToString(),
                                    Status =
                                        reader["status"].ToString().Equals("1") ||
                                        reader["status"].ToString().Equals("True"),
                                    UserName = reader["username"].ToString(),
                                    Created = (DateTime) reader["created"]
                                };
                                lists.Add(albumComment);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    writeLog("", "Get All AlbumComment Error: " + ex.Message, connString);
                    return new List<AlbumComment>();
                }
            }
            return lists;

            #endregion
        }
예제 #15
0
        public static AlbumComment getCommentById(int commentId, string connString)
        {
            #region code

            var rs = new AlbumComment();
            using (var conn = new SqlConnection(connString))
            {
                try
                {
                    conn.Open();
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "sony_sp_get_album_comment_by_id";
                        cmd.Parameters.AddWithValue("@id", commentId);

                        using (var reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                rs.AlbumId = String.IsNullOrEmpty(reader["albumId"].ToString())
                                    ? 0
                                    : (int) reader["albumId"];
                                rs.PhotoId = String.IsNullOrEmpty(reader["photoId"].ToString())
                                    ? 0
                                    : (int) reader["photoId"];
                                rs.Comment = reader["comment"].ToString();
                                rs.Status = reader["status"].ToString().Equals("1") ||
                                            reader["status"].ToString().Equals("True");
                                rs.UserName = reader["username"].ToString();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    writeLog("", "Get Album Comment Error: " + ex.Message, connString);
                    return new AlbumComment();
                }
            }
            return rs;

            #endregion
        }