Example #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);
            }
        }
Example #2
0
        /*
         * Method getting latest comment of a product
         * productId: ID of product (from product detail page)
         * objTypeId: Object type id (This can retrive comment for many kind like: product, media, news, videos etc...)
         * cms_db: Controll class from DataMode.DataStore
         */
        public List <ObjContentComment> GetLatestCommentByProductId(int productId, int objTypeId, Ctrl cms_db)
        {
            Product product = cms_db.GetObjProductById(productId);

            if (product != null)
            {
                try
                {
                    List <ObjContentComment> comments = new List <ObjContentComment>();
                    string query = "SELECT top (1) 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.ContentObjId = '" + productId + "' ORDER BY cm.CrtdDT DESC";
                    using (var context = new alluneedbEntities())
                    {
                        System.Data.Entity.Infrastructure.DbRawSqlQuery <ObjContentComment> data = db.Database.SqlQuery <ObjContentComment>(query);
                        comments = data.ToList();
                    }
                    if (comments.Count > 0)
                    {
                        return(comments);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    string message = ex.Message;
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        /*
         * TRI-28062016 Update like number from table dbo.ContentComment
         * 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 <int> LikeComments(int commentId, string fullName, string email, Ctrl cms_db, long userId)
        {
            ContentComment comment = db.ContentComments.SingleOrDefault(a => a.CommentId == commentId);

            if (comment != null)
            {
                int newLikeCount = 1;
                if (comment.LikeCount != null)
                {
                    newLikeCount = (int)comment.LikeCount + 1;
                }
                comment.LikeCount = newLikeCount;
                try
                {
                    await db.SaveChangesAsync();

                    return(newLikeCount);
                }
                catch (Exception ex)
                {
                    Core core = new Core();
                    core.AddToExceptionLog("LikeComments", "ProductController", "Like comment error: " + ex.Message, userId);
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }
Example #4
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);
            }
        }