コード例 #1
0
        public ClassifiedsViewModel Add(ClassifiedsViewModel ClassifiedsVM)
        {
            var classifieds = ClassifiedsVM.AddModel();
            List <ClassifiedsTag> ClassifiedsTag = new List <ClassifiedsTag>();

            classifieds.ClassifiedsTags = ClassifiedsTag;
            if (!string.IsNullOrEmpty(classifieds.Tags))
            {
                var tags = classifieds.Tags.Split(',');
                foreach (string t in tags)
                {
                    var tagId = TextHelper.ToUnsignString(t);
                    if (!_tagRepository.FindAll(x => x.Id == tagId).Any())
                    {
                        Tag tag = new Tag {
                            Id   = tagId,
                            Name = t,
                            Type = CommonConstants.BlogTag
                        };
                        _tagRepository.Add(tag);
                    }

                    var classifiedsTag = new ClassifiedsTag {
                        TagId = tagId
                    };
                    classifieds.ClassifiedsTags.Add(classifiedsTag);
                }
            }
            _Classifieds.Add(classifieds);
            return(ClassifiedsVM);
        }
コード例 #2
0
 public void Update(ClassifiedsViewModel blog)
 {
     _Classifieds.Update(blog.AddModel());
     if (!string.IsNullOrEmpty(blog.Tags))
     {
         string[] tags = blog.Tags.Split(',');
         foreach (string t in tags)
         {
             var tagId = TextHelper.ToUnsignString(t);
             if (!_tagRepository.FindAll(x => x.Id == tagId).Any())
             {
                 Tag tag = new Tag {
                     Id   = tagId,
                     Name = t,
                     Type = CommonConstants.ProductTag
                 };
                 _tagRepository.Add(tag);
             }
             _ClassifiedsTag.RemoveMultiple(_ClassifiedsTag.FindAll(x => x.Id == blog.Id).ToList());
             ClassifiedsTag classifiedsTag = new ClassifiedsTag {
                 ClassifiedsId = blog.Id,
                 TagId         = tagId
             };
             _ClassifiedsTag.Add(classifiedsTag);
         }
     }
 }
コード例 #3
0
 public static BlogTagViewModel ToModel(this ClassifiedsTag blogTag)
 {
     return(Mapper.Map <BlogTagViewModel>(blogTag));
 }