예제 #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 save comment of user
         * productId: product id
         * comments: comment from logged user
         * fullName: full name of logged user (default is empty string)
         * email: email of logged user (default is empty string)
         * cms_db: Controll class from DataMode.DataStore
         * userId: Id of logged user
         */
        public async Task <int> SaveComments(long idObject, string comments, string fullName, string email, Ctrl cms_db, long userId, int objType, string objTypeName, long parentId)
        {
            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
            }
            if (objType == (int)EnumCore.ObjTypeId.san_pham)
            {
                Product        product        = cms_db.GetObjProductById(idObject);
                Classification classification = cms_db.GetObjClasscifiById((int)Extension.EnumCore.StateType.cho_duyet);
                if (product != null)
                {
                    ContentComment comment = new ContentComment();
                    comment.ParentCommentId = parentId;
                    comment.ContentObjId    = idObject;
                    comment.ContentObjName  = product.ProductName;
                    comment.Title           = null;
                    comment.CommentText     = StripHTMLAndScript(comments); //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       = objType;
                    comment.ObjTypeName     = objTypeName;
                    try
                    {
                        return(await cms_db.AddComment(comment));
                    }
                    catch (Exception ex)
                    {
                        Core core = new Core();
                        core.AddToExceptionLog("SaveComments", "ProductController", "Create comment error: " + ex.Message, userId);
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                Microsite mic = cms_db.GetObjMicrositeByID(idObject);
                if (mic != null)
                {
                    ContentComment comment = new ContentComment();
                    comment.ParentCommentId = parentId;
                    comment.ContentObjId    = idObject;
                    comment.ContentObjName  = mic.Name;
                    comment.Title           = null;
                    comment.CommentText     = StripHTMLAndScript(comments); //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         = (int)EnumCore.StateType.cho_phep;
                    comment.StateName       = "Cho phép";
                    comment.CrtdGuestUserId = null;
                    comment.LikeCount       = null;
                    comment.LastLikedDT     = null;
                    comment.IPAddress       = GetIPAddress();
                    comment.ObjTypeId       = objType;
                    comment.ObjTypeName     = objTypeName;
                    try
                    {
                        return(await cms_db.AddComment(comment));
                    }
                    catch (Exception ex)
                    {
                        Core core = new Core();
                        core.AddToExceptionLog("SaveComments", "ProductController", "Create comment error: " + ex.Message, userId);
                        return(0);
                    }
                }
                return(0);
            }
        }