/// <summary>
        /// Deletes the specified Publication Comment.
        /// </summary>
        /// <param name="publicationComment">The publication comment.</param>
        public void Delete(tbl_PublicationComment publicationComment)
        {
            var publicationCommentMarks = _dataContext.tbl_PublicationMark.Where(pm => pm.PublicationCommentID == publicationComment.ID);

            foreach (var publicationCommentMark in publicationCommentMarks)
            {
                _dataContext.DeleteObject(publicationCommentMark);
            }

            _dataContext.DeleteObject(publicationComment);
            _dataContext.SaveChanges();
        }
        /// <summary>
        /// Updates the specified publication comment.
        /// </summary>
        /// <param name="publicationComment">The publication comment.</param>
        public void Update(tbl_PublicationComment publicationComment)
        {
            var updatesitePublicationComment = SelectById(publicationComment.ID);

            updatesitePublicationComment.PublicationID    = publicationComment.PublicationID;
            updatesitePublicationComment.UserID           = publicationComment.UserID;
            updatesitePublicationComment.isOfficialAnswer = publicationComment.isOfficialAnswer;
            updatesitePublicationComment.Comment          = publicationComment.Comment;
            updatesitePublicationComment.CreatedAt        = publicationComment.CreatedAt;
            updatesitePublicationComment.FileName         = publicationComment.FileName;
            _dataContext.SaveChanges();
        }
Ejemplo n.º 3
0
        public void Save(Guid PublicationID)
        {
            var publicationCommentValues = new List <PublicationCommentStructure>();

            if (ViewState["PublicationComment"] != null)
            {
                var publicationCommentValuesOld = dataManager.PublicationComment.SelectByPublicationId(PublicationID).ToList();
                publicationCommentValues = (List <PublicationCommentStructure>)ViewState["PublicationComment"];
                foreach (var publicationCommentValue in publicationCommentValues)
                {
                    publicationCommentValue.PublicationID = PublicationID;
                    var updatesitePublicationComment = new tbl_PublicationComment();
                    updatesitePublicationComment.ID               = publicationCommentValue.ID;
                    updatesitePublicationComment.PublicationID    = PublicationID;
                    updatesitePublicationComment.UserID           = publicationCommentValue.UserID;
                    updatesitePublicationComment.isOfficialAnswer = publicationCommentValue.isOfficialAnswer;
                    updatesitePublicationComment.Comment          = publicationCommentValue.Comment;
                    updatesitePublicationComment.CreatedAt        = publicationCommentValue.Date;
                    updatesitePublicationComment.FileName         = publicationCommentValue.FileName ?? "";

                    var removePublicationCommentValue = publicationCommentValuesOld.SingleOrDefault(a => a.ID == publicationCommentValue.ID);
                    if (removePublicationCommentValue != null)
                    {
                        dataManager.PublicationComment.Update(updatesitePublicationComment);
                        publicationCommentValuesOld.Remove(removePublicationCommentValue);
                    }
                    else
                    {
                        dataManager.PublicationComment.Add(updatesitePublicationComment);
                    }
                }

                if (publicationCommentValuesOld != null && publicationCommentValuesOld.Count() > 0)
                {
                    foreach (var item in publicationCommentValuesOld)
                    {
                        try
                        {
                            dataManager.PublicationComment.Delete(item);
                        }
                        catch { }
                    }
                }
            }
        }
        /// <summary>
        /// Adds the specified site id.
        /// </summary>
        /// <param name="siteId">The site id.</param>
        /// <param name="contactId">The contact id.</param>
        /// <param name="publicationId">The publication id.</param>
        /// <param name="comment">The comment.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public ActivityCommentMap Add(Guid siteId, Guid contactId, Guid publicationId, string comment, string fileName)
        {
            var publicationComment = new tbl_PublicationComment
            {
                ID               = Guid.NewGuid(),
                CreatedAt        = DateTime.Now,
                PublicationID    = publicationId,
                UserID           = contactId,
                Comment          = comment,
                isOfficialAnswer = false,
                FileName         = fileName
            };

            Add(publicationComment);

            var publicationCommentMap = new ActivityCommentMap
            {
                ID               = publicationComment.ID,
                PublicationID    = publicationComment.PublicationID,
                CreatedAt        = publicationComment.CreatedAt,
                UserFullName     = publicationComment.tbl_Contact.UserFullName,
                Comment          = publicationComment.Comment.ToHtml(),
                isOfficialAnswer = publicationComment.isOfficialAnswer,
                FormattedDate    = ((DateTime)publicationComment.CreatedAt).ToString("d MMMM в HH:mm"),
                FileName         = publicationComment.FileName
            };

            var fsp = new FileSystemProvider();

            if (!string.IsNullOrEmpty(publicationCommentMap.FileName))
            {
                publicationCommentMap.VirtualFileName = fsp.GetLink(siteId, "PublicationComments", publicationCommentMap.FileName, FileType.Attachment);
            }

            return(publicationCommentMap);
        }
 /// <summary>
 /// Add the specified Publication Comment.
 /// </summary>
 /// <param name="publicationComment">The publication comment.</param>
 /// <returns></returns>
 public tbl_PublicationComment Add(tbl_PublicationComment publicationComment)
 {
     _dataContext.tbl_PublicationComment.AddObject(publicationComment);
     _dataContext.SaveChanges();
     return(publicationComment);
 }