예제 #1
0
        private bool SaveMessageHashtags(IEnumerable <string> tags, long messageId, out string error)
        {
            error = string.Empty;
            try
            {
                foreach (var tag in tags.Distinct())
                {
                    if (String.IsNullOrEmpty(tag) || tag.Length == 1)
                    {
                        continue;
                    }

                    var name = tag.Substring(1);

                    var entity = DiscussionHashtagRepository.Get(x => x.HashTag.ToLower() == name.ToLower());

                    if (entity == null)
                    {
                        continue;
                    }

                    if (DiscussionMessageHashtagRepository.IsAny(x => x.MessageId == messageId && x.HashtagId == entity.HashtagId))
                    {
                        continue;
                    }

                    DiscussionMessageHashtagRepository.Add(new DSC_MessageHashtags
                    {
                        MessageId   = messageId
                        , HashtagId = entity.HashtagId
                    });
                }

                DiscussionMessageHashtagRepository.UnitOfWork.CommitAndRefreshChanges();

                return(true);
            }
            catch (Exception ex)
            {
                DiscussionMessageHashtagRepository.UnitOfWork.RollbackChanges();
                error = Utils.FormatError(ex);
                Logger.Error("SaveMessageHashtags", messageId, ex, CommonEnums.LoggerObjectTypes.Discussion);
                return(false);
            }
        }
예제 #2
0
        private bool SaveHashtags(IEnumerable <string> tags, int userId, out string error)
        {
            error = string.Empty;
            try
            {
                foreach (var tag in tags.Distinct())
                {
                    if (String.IsNullOrEmpty(tag) || tag.Length == 1)
                    {
                        continue;
                    }

                    var name = tag.Substring(1);

                    var exists = DiscussionHashtagRepository.IsAny(x => x.HashTag.ToLower() == name.ToLower());

                    if (exists)
                    {
                        continue;
                    }

                    DiscussionHashtagRepository.Add(new DSC_Hashtags
                    {
                        HashTag     = name
                        , AddOn     = DateTime.Now
                        , CreatedBy = userId
                    });
                }

                DiscussionHashtagRepository.UnitOfWork.CommitAndRefreshChanges();

                return(true);
            }
            catch (Exception ex)
            {
                DiscussionHashtagRepository.UnitOfWork.RollbackChanges();
                error = Utils.FormatError(ex);
                Logger.Error("save message hash tags", userId, ex, CommonEnums.LoggerObjectTypes.Discussion);
                return(false);
            }
        }
예제 #3
0
        public HashTagDTO GetHashTagDto(long tagId)
        {
            var entity = DiscussionHashtagRepository.GetById(tagId);

            return(entity == null ? new HashTagDTO() : entity.Entity2HashTagDto());
        }
예제 #4
0
        private long?FindHashtagByName(string q)
        {
            var entity = DiscussionHashtagRepository.Get(x => x.HashTag.ToLower() == q.ToLower());

            return(entity == null ? (long?)null : entity.HashtagId);
        }