Ejemplo n.º 1
0
        public TagInfo GetByName(UserInfo userInfo, string displayName)
        {
            displayName = FormatDisplayName(displayName);
            var tag = _tagDao.GetByName(displayName);

            return(_converter.ToDataTransferObject(tag));
        }
        private IList FindFinalTags(IList originalTags, string[] tagDisplayNames)
        {
            var newTagDisplayNames = new List <string>(tagDisplayNames);

            var originalTagsReadyToSubtracted    = originalTags.Cast <Tag>().ToList();
            var newTagDisplayNamesReadyToCreated = new List <string>(newTagDisplayNames);
            var finalTags = new List <Tag>();

            foreach (var newTagDisplayName in newTagDisplayNames)
            {
                if (!String.IsNullOrEmpty(newTagDisplayName))
                {
                    foreach (Tag originalTag in originalTags)
                    {
                        if (originalTag.DisplayName.ToLower().Trim().Equals(newTagDisplayName.ToLower().Trim()))
                        {
                            finalTags.Add(originalTag);
                            newTagDisplayNamesReadyToCreated.Remove(newTagDisplayName);
                            originalTagsReadyToSubtracted.Remove(originalTag);
                        }
                    }
                }
            }

            foreach (var originalTag in originalTagsReadyToSubtracted)
            {
                SubtractTagUsedCount(originalTag);
            }

            IList candidate = null;

            if (newTagDisplayNamesReadyToCreated != null)
            {
                if (newTagDisplayNamesReadyToCreated.Count == 0)
                {
                    if (newTagDisplayNames != null && newTagDisplayNames.Count > 0)
                    {
                        candidate = _tagDao.GetByName(newTagDisplayNames);
                    }
                }
                else
                {
                    candidate = EnsureTagsCreated(newTagDisplayNamesReadyToCreated.ToArray());
                }
            }

            if (candidate != null)
            {
                foreach (Tag tag in candidate)
                {
                    if (!finalTags.Contains(tag))
                    {
                        finalTags.Add(tag);
                    }
                }
            }
            return(finalTags);
        }