Пример #1
0
        /*
         * TRI-28062016 Add reply to comment
         * productId: ID of Product
         * replyContent: Reply contains from user
         * commentId: ID of comment
         * fullName: Full name of logged user
         * email: Email of logged user (default is empty string)
         * cms_db: DataModel Controller
         * userId: ID of logged user
         */
        public async Task <ObjContentComment> ReplyComments(long productId, string replyContent, int commentId, string fullName, string email, Ctrl cms_db, long userId)
        {
            if (fullName.Length > 250)
            {
                fullName = fullName.Substring(0, 249); //To make it fix to column data type length
            }

            if (email.Length > 250)
            {
                email = email.Substring(0, 249); //To make it fix to column data type length
            }

            Product        product        = cms_db.GetObjProductById(productId);
            Classification classification = cms_db.GetObjClasscifiById((int)Extension.EnumCore.StateType.cho_duyet);

            if (product != null)
            {
                ContentComment comment = new ContentComment();
                comment.ParentCommentId = commentId;
                comment.ContentObjId    = productId;
                comment.ContentObjName  = product.ProductName;
                comment.Title           = null;
                comment.CommentText     = StripHTMLAndScript(replyContent); //Keep comment clearn without html injection
                comment.FullName        = fullName;
                comment.EmailAddress    = email;
                comment.CrtdDT          = DateTime.Now;
                comment.AprvdDT         = null;
                comment.AprvdUID        = null;
                comment.AprvdUerName    = null;
                comment.StateId         = classification.ClassificationId;
                comment.StateName       = classification.ClassificationNM;
                comment.CrtdGuestUserId = null;
                comment.LikeCount       = null;
                comment.LastLikedDT     = null;
                comment.IPAddress       = GetIPAddress();
                comment.ObjTypeId       = (int)Extension.EnumCore.ObjTypeId.san_pham;
                comment.ObjTypeName     = "san_pham";
                try
                {
                    await cms_db.AddComment(comment);

                    ObjContentComment objContentComment = GetCommentById(comment.CommentId, cms_db, userId);
                    return(objContentComment);
                }
                catch (Exception ex)
                {
                    Core core = new Core();
                    core.AddToExceptionLog("ReplyComments", "ProductController", "Save reply on comment error: " + ex.Message, userId);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
 /*
  * Method getting comment by comment ID
  * commentId: ID of product (from product detail page)
  * cms_db: Controll class from DataMode.DataStore
  */
 public ObjContentComment GetCommentById(long commentId, Ctrl cms_db, long userId)
 {
     try
     {
         ObjContentComment comment = new ObjContentComment();
         string            query   = "SELECT cm.*, mc.ThumbURL AS UserAvatar, ur.Id AS UserId FROM ContentComment cm LEFT JOIN dbo.[User] ur "
                                     + "ON cm.EmailAddress = ur.EMail LEFT JOIN MediaContent mc ON ur.Id = mc.ContentObjId WHERE cm.CommentId = '" + commentId + "' ORDER BY cm.CrtdDT DESC";
         using (var context = new alluneedbEntities())
         {
             System.Data.Entity.Infrastructure.DbRawSqlQuery <ObjContentComment> data = db.Database.SqlQuery <ObjContentComment>(query);
             comment = data.FirstOrDefault();
         }
         return(comment);
     }
     catch (Exception ex)
     {
         Core core = new Core();
         core.AddToExceptionLog("GetCommentById", "ProductController", "Get comment by ID Error: " + ex.Message, userId);
         return(null);
     }
 }