Ejemplo n.º 1
0
        public Product Add(Product product)
        {
            var productReturn = _productRepository.Add(product);

            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(product.Tags))
            {
                string[] tags     = product.Tags.Split(',');
                var      length   = tags.Length;
                var      dataTags = _tagRepository.GetAll().ToList();
                for (var i = 0; i < length; i++)
                {
                    var tagId = StringHelperUtility.ToUnsignString(tags[i]);
                    if (!dataTags.Any(x => x.ID == tagId))
                    {
                        Tag tag = new Tag()
                        {
                            ID   = tagId,
                            Name = tags[i],
                            Type = Constant.ProductTag
                        };
                        _tagRepository.Add(tag);
                    }
                    ProductTag productTag = new ProductTag()
                    {
                        ProductID = productReturn.ID,
                        TagID     = tagId
                    };
                    _productTagRepository.Add(productTag);
                }
                _unitOfWork.Commit();
            }
            return(productReturn);
        }
Ejemplo n.º 2
0
        public Product Add(Product product)
        {
            var lstStrIDTag = new List <string>();
            var addproduct  = _productRepository.Add(product);

            _unitOfWork.Commit();

            if (!string.IsNullOrEmpty(product.Tags))
            {
                string[] tags = product.Tags.Split(',');
                for (int i = 0; i < tags.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(tags[i]);
                    var xx    = lstStrIDTag.Where(x => x.Equals(tagId));
                    if (xx.Count() == 0)
                    {
                        if (_tagRepository.Count(x => x.ID == tagId) == 0)
                        {
                            Tag tag = new Tag();
                            tag.ID   = tagId;
                            tag.Name = tags[i];
                            tag.Type = CommonConstants.ProductTag;
                            _tagRepository.Add(tag);
                            lstStrIDTag.Add(tagId);
                        }

                        ProductTag productTag = new ProductTag();
                        productTag.ProductID = product.ProductID;
                        productTag.TagID     = tagId;
                        _productTagRepository.Add(productTag);
                    }
                }
            }
            return(addproduct);
        }
Ejemplo n.º 3
0
        public Product Add(Product Product)
        {
            var product = _productRepository.Add(Product);

            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(Product.Tags))
            {
                string[] tags = Product.Tags.Split(',');
                for (var i = 0; i < tags.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(tags[i]);
                    if (_tagRepository.Count(x => x.ID == tagId) == 0)
                    {
                        Tag tag = new Tag();
                        tag.ID   = tagId;
                        tag.Name = tags[i];
                        tag.Type = CommonConstants.ProductTag;
                        _tagRepository.Add(tag);
                    }

                    ProductTag productTag = new ProductTag();
                    productTag.ProductID = Product.ID;
                    productTag.TagID     = tagId;
                    _productTagRepository.Add(productTag);
                }
            }
            return(product);
        }
Ejemplo n.º 4
0
        public Product Add(Product Product)
        {
            //Thêm mới Product vào database để sinh ra Product.ID để thêm vào bảng ProductTag phía dưới
            var product = _productRepository.Add(Product);

            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(Product.Tags))
            {
                string[] tags = Product.Tags.Split(',');
                for (var i = 0; i < tags.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(tags[i]);
                    if (_tagRepository.Count(x => x.ID == tagId) == 0)
                    {
                        Tag tag = new Tag();
                        tag.ID   = tagId;
                        tag.Name = tags[i];
                        tag.Type = CommonConstants.ProductTag;
                        _tagRepository.Add(tag);
                    }

                    ProductTag productTag = new ProductTag();
                    productTag.ProductID = Product.ID;
                    productTag.TagID     = tagId;
                    _productTagRepository.Add(productTag);
                }
                //Lưu tất cả thay đổi vào csdl
                _unitOfWork.Commit();
            }
            return(product);
        }
Ejemplo n.º 5
0
        public int Add(BlogViewModel blogVm)
        {
            Blog blogDb = _mapper.Map <Blog>(blogVm);

            _blogRepository.Add(blogDb);
            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(blogDb.Tags))
            {
                string[] listTag = blogDb.Tags.Split(',');
                for (int i = 0; i < listTag.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(listTag[i]);
                    if (_tagRepository.FindById(tagId) == null)
                    {
                        Tag tag = new Tag()
                        {
                            Id   = tagId,
                            Name = listTag[i],
                            Type = CommonConstants.BlogTag,
                        };
                        _tagRepository.Add(tag);
                    }
                    BlogTag blogTag = new BlogTag()
                    {
                        BlogId = blogDb.Id,
                        TagId  = tagId,
                    };
                    _blogTagRepository.Add(blogTag);
                }
            }
            return(blogDb.Id);
        }
Ejemplo n.º 6
0
        public Product Add(Product product)
        {
            var productResult = _productRepository.Add(product);
            var saveResult    = _uow.Commit();

            if (saveResult)
            {
                var tags = product.Tags.Split(',');
                foreach (var tag in tags)
                {
                    var unsignTag = StringHelper.ToUnsignString(tag);
                    var tagInDb   = _tagRepository.GetMulti(x => x.ID == unsignTag).FirstOrDefault();
                    if (tagInDb == null)
                    {
                        tagInDb = new Tag()
                        {
                            ID   = unsignTag,
                            Name = tag,
                            Type = TagTypeConstant.PRODUCT
                        };
                        _tagRepository.Add(tagInDb);
                    }

                    _productTagRepository.Add(new ProductTag()
                    {
                        TagID     = tagInDb.ID,
                        ProductID = productResult.ID
                    });
                }
                _uow.Commit();
                return(productResult);
            }
            return(null);
        }
Ejemplo n.º 7
0
 public void Add(Post post)
 {
     _postRepository.Add(post);
     _unitOfWork.Commit();
     if (!string.IsNullOrEmpty(post.Tags))
     {
         string[] tags = post.Tags.Split(',');
         foreach (var tagItem in tags)
         {
             Tag tag   = new Tag();
             var tagId = StringHelper.ToUnsignString(tagItem);
             if (_tagRepository.Count(x => x.ID == tagId) == 0)
             {
                 tag.ID   = tagId;
                 tag.Name = tagItem;
                 tag.Type = CommonConstant.PostTag;
                 _tagRepository.Add(tag);
             }
             PostTag postTag = new PostTag();
             postTag.PostID = post.ID;
             postTag.TagID  = tagId;
             _postTagRepository.Add(postTag);
             _unitOfWork.Commit();
         }
     }
 }
Ejemplo n.º 8
0
        public Product Add(Product product)
        {
            product.CreatedDate = DateTime.Now;
            var addedProduct = _productRepository.Add(product);

            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(product.Tags))
            {
                string[] tags = product.Tags.Split(',');
                for (int i = 0; i < tags.Length; i++)
                {
                    var tagID = StringHelper.ToUnsignString(tags[i]);
                    if (_tagRepository.Count(p => p.ID == tagID) == 0)
                    {
                        Tag tag = new Tag()
                        {
                            ID   = tagID,
                            Name = tags[i],
                            Type = CommonConstants.ProductTag
                        };
                        _tagRepository.Add(tag);
                    }
                    ProductTag productTag = new ProductTag()
                    {
                        ProductID = addedProduct.ID,
                        TagID     = tagID
                    };
                    _productTagRepository.Add(productTag);
                }
            }

            return(addedProduct);
        }
        public ProductViewModel Add(ProductViewModel productViewModel)
        {
            var tags = productViewModel.Tags.Split(",");
            List <ProductTag> productTags = new List <ProductTag>();

            foreach (var t in tags)
            {
                var tagId = TextHelper.ToUnsignString(t);
                if (!_tagRepository.FindAll(x => x.Id == tagId).Any())
                {
                    _tagRepository.Add(new Tag()
                    {
                        Id   = tagId,
                        Name = t,
                        Type = CommonConstants.productTag
                    });
                }
                productTags.Add(new ProductTag()
                {
                    TagId = tagId
                });
            }
            var model = Mapper.Map <ProductViewModel, Product>(productViewModel);

            foreach (var item in productTags)
            {
                model.ProductTags.Add(item);
            }
            _productRepository.Add(model);
            return(productViewModel);
        }
Ejemplo n.º 10
0
        public Product Add(Product product)
        {
            var productAdd = _productRepository.Add(product);

            _unitOfWork.Commit();
            if (!String.IsNullOrEmpty(product.Tags))
            {
                String[] tags = product.Tags.Split(',');
                foreach (var tagItem in tags)
                {
                    var tagId = StringHelper.ToUnsignString(tagItem);
                    if (_tagRepository.Count(x => x.ID == tagId) == 0)
                    {
                        var tag = new Tag();
                        tag.ID   = tagId;
                        tag.Name = tagItem;
                        tag.Type = CommonConstants.ProductTag;

                        _tagRepository.Add(tag);
                        _unitOfWork.Commit();
                    }

                    ProductTag productTag = new ProductTag();
                    productTag.ProductID = productAdd.ID;
                    productTag.TagID     = tagId;
                    _productTagRepository.Add(productTag);
                    _unitOfWork.Commit();
                }
            }
            return(productAdd);
        }
Ejemplo n.º 11
0
        public Product Add(Product Product)
        {
            var product = _productRepository.Add(Product);

            _unitOfWork.Commit();                        //commit lần 1 để có giá trị(Id, name,..) để truyền xuống if
            if (!string.IsNullOrEmpty(Product.Tags))     //nếu product.tag null or empty
            {
                string[] tags = Product.Tags.Split(','); //tách chuỗi nhập vào bằng dấu [,]
                for (var i = 0; i < tags.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(tags[i]);  //chuyển đổi tag theo StringHelper
                    if (_tagRepository.Count(x => x.ID == tagId) == 0) //nếu = 0thì tạo mới tag
                    {
                        Tag tag = new Tag();
                        tag.ID   = tagId;
                        tag.Name = tags[i];
                        tag.Type = CommonConstants.ProductTag;
                        _tagRepository.Add(tag);
                    }
                    ProductTag productTag = new ProductTag();
                    productTag.ProductID = Product.ID;
                    productTag.TagID     = tagId;
                    _productTagRepository.Add(productTag);
                }
            }
            return(product);
        }
Ejemplo n.º 12
0
        public BlogViewModel Add(BlogViewModel blogVm)
        {
            var blog = Mapper.Map <BlogViewModel, Blog>(blogVm);

            if (!string.IsNullOrEmpty(blog.Tags))
            {
                var 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.BlogTag
                        };
                        _tagRepository.Add(tag);
                    }

                    var blogTag = new BlogTag {
                        TagId = tagId
                    };
                    blog.BlogTags.Add(blogTag);
                }
            }
            _blogRepository.Add(blog);
            return(blogVm);
        }
Ejemplo n.º 13
0
        public void CreatePost(Post Post)
        {
            _postsRepository.Add(Post);
            SavePost();
            if (!string.IsNullOrEmpty(Post.Tags))
            {
                string[] tags = Post.Tags.Split(',');
                foreach (var item in tags)
                {
                    string alias = StringHelper.ToUnsignString(item);
                    if (_tagRepository.Count(x => x.ID == alias) == 0)
                    {
                        Tag tag = new Tag();
                        tag.ID   = alias;
                        tag.Name = item;
                        _tagRepository.Add(tag);
                    }

                    PostTag postTag = new PostTag();
                    postTag.PostID = Post.ID;
                    postTag.TagID  = alias;
                    _postTagRepository.Add(postTag);
                }
            }
        }
Ejemplo n.º 14
0
        public Product Add(Product product)
        {
            product.PromotionPrice = 0;
            var _product = _productRepository.Add(product);

            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(product.Tags))
            {
                string[] tags = product.Tags.Split(',');
                for (var i = 0; i < tags.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(tags[i]);

                    if (_tagRepository.Count(x => x.ID == tagId) == 0)
                    {
                        Tag tag = new Tag
                        {
                            ID   = tagId,
                            Name = tags[i],
                            Type = CommonConstants.ProductTag
                        };
                        _tagRepository.Add(tag);
                    }

                    ProductTag productTag = new ProductTag
                    {
                        ProductID = product.ID,
                        TagID     = tagId
                    };
                    _productTagRepository.Add(productTag);
                }
            }
            return(_product);
        }
Ejemplo n.º 15
0
        public Post Add(Post post)
        {
            var _post = _postRepository.Add(post);

            SaveChange();
            if (!string.IsNullOrEmpty(_post.Tags))
            {
                string[] ListTags = _post.Tags.Split(',');
                foreach (var item in ListTags)
                {
                    var TagID = StringHelper.ToUnsignString(item);
                    if (_tagRepository.Count(s => s.ID == TagID) == 0)
                    {
                        Tag tag = new Tag();
                        tag.ID   = TagID;
                        tag.Name = item;
                        tag.Type = CommonConstants.PostTag;
                        _tagRepository.Add(tag);
                    }
                    PostTag postTag = new PostTag();
                    postTag.PostID = _post.ID;
                    postTag.TagID  = TagID;
                    _postTagRepository.Add(postTag);
                }
            }
            return(_post);
        }
Ejemplo n.º 16
0
        public ProductViewModel Add(ProductViewModel productViewModel)
        {
            productViewModel.SeoAlias = TextHelper.ToUnsignString(productViewModel.Name);
            var product = Mapper.Map <ProductViewModel, Product>(productViewModel);

            if (!string.IsNullOrEmpty(productViewModel.Tags))
            {
                string[] tags = productViewModel.Tags.Split(',');
                foreach (string t in tags)
                {
                    var tagId = TextHelper.ToUnsignString(t);
                    if (!tagRepository.FindAll(tag => tag.Id == tagId).Any())
                    {
                        Tag tag = new Tag
                        {
                            Id   = tagId,
                            Name = t,
                            Type = CommonConstants.ProductTag
                        };
                        tagRepository.Add(tag);
                    }
                    ProductTag productTag = new ProductTag
                    {
                        TagId = tagId
                    };
                    product.ProductTags.Add(productTag);
                }
            }
            productRepository.Add(product);
            return(productViewModel);
        }
Ejemplo n.º 17
0
        public void Add(Post post)
        {
            Post query = _postRepository.Add(post);

            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(post.Tags))
            {
                string[] listTag = post.Tags.Split(',');
                for (int i = 0; i < listTag.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(listTag[i]);
                    if (_tagReponsitory.Count(x => x.ID == tagId) == 0)
                    {
                        Tag tag = new Tag()
                        {
                            ID   = tagId,
                            Name = listTag[i],
                            Type = CommonConstant.PostTag,
                        };
                        _tagReponsitory.Add(tag);
                    }
                    PostTag postTag = new PostTag()
                    {
                        PostID = query.ID,
                        TagID  = tagId,
                    };
                    _postTagRepository.Add(postTag);
                }
            }
        }
Ejemplo n.º 18
0
        public async Task <ProductViewModel> AddAsync(ProductViewModel productVm)
        {
            Product product = _mapper.Map <Product>(productVm);
            await _productRepository.AddAsync(product);

            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(product.Tag))
            {
                string[] listTag = product.Tag.Split(',');
                for (int i = 0; i < listTag.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(listTag[i]);
                    if (_tagRepository.FindById(tagId) == null)
                    {
                        Tag tag = new Tag()
                        {
                            Id   = tagId,
                            Name = listTag[i],
                            Type = CommonConstants.ProductTag,
                        };
                        _tagRepository.Add(tag);
                    }
                    ProductTag productTag = new ProductTag()
                    {
                        ProductId = product.Id,
                        TagId     = tagId,
                    };
                    _productTagRepository.Add(productTag);
                }
            }
            return(productVm);
        }
Ejemplo n.º 19
0
        public Product Add(Product Product)
        {
            var product = _ProductRepository.Add(Product);

            Save();
            if (!string.IsNullOrEmpty(Product.Tags))
            {
                string[] ListTags = Product.Tags.Split(',');
                foreach (var item in ListTags)
                {
                    var TagID = StringHelper.ToUnsignString(item);
                    if (_tagRepository.Count(s => s.ID == TagID) == 0)
                    {
                        Tag tag = new Tag();
                        tag.ID   = TagID;
                        tag.Name = item;
                        tag.Type = CommonConstants.ProductTag;
                        _tagRepository.Add(tag);
                    }
                    ProductTag productTag = new ProductTag();
                    productTag.ProductID = Product.ID;
                    productTag.TagID     = TagID;
                    _productTagRepository.Add(productTag);
                }
            }
            return(product);
        }
Ejemplo n.º 20
0
        public Product Add(Product Product)
        {
            var product = _productRepository.Add(Product);

            _unitOfWork.Commit();

            if (!String.IsNullOrEmpty(Product.Tags))
            {
                string[] tags = Product.Tags.Split(',');

                for (var i = 0; i < tags.Length; i++)
                {
                    // tagID in database with data type string.
                    var tagID = HelperMethods.ToUnsignString(tags[i]);

                    // Check string tag not in database will create it.
                    if (_tagRepository.Count(x => x.ID == tagID) == 0)
                    {
                        Tag tag = new Tag();
                        tag.ID   = tagID;
                        tag.Name = tags[i];
                        tag.Type = CommonConstants.ProductTag;
                        _tagRepository.Add(tag);
                    }

                    ProductTag productTag = new ProductTag();
                    productTag.ProductID = Product.ID;
                    productTag.TagID     = tagID;
                    _productTagRepository.Add(productTag);
                }
            }
            return(product);
        }
Ejemplo n.º 21
0
        public void Add(BlogViewModel blogViewModel)
        {
            var blog = Mapper.Map <BlogViewModel, Blog>(blogViewModel);
            var tags = blogViewModel.Tags.Split(",");

            if (tags.Length > 0)
            {
                foreach (var item in tags)
                {
                    var tag = TextHelper.ToUnsignString(item);
                    _tagRepository.Add(new Tag()
                    {
                        Id   = tag,
                        Name = item,
                        Type = CommonConstants.blogTag
                    });

                    blog.BlogTags.Add(new BlogTag()
                    {
                        TagId = tag,
                    });
                }
            }
            _blogRepository.Add(blog);
        }
Ejemplo n.º 22
0
 public bool Add(CreateTagDto tag)
 {
     if (_tagRepository.Add(tag) != 0)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 23
0
        public ProductViewModel Add(ProductViewModel productVm)
        {
            if (!string.IsNullOrEmpty(productVm.Tag))
            {
                //Product product = new Product();
                //product = new Product() { Name = "Product tets", DateCreated = DateTime.Now, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "product-test", Price = 1000, Status = Status.Active, OriginalPrice = 1000 ,
                //    CategoryId=6,
                // ProductTags = new List<ProductTag>()
                // {
                //     new ProductTag(){TagId="tag"}
                // }
                //};
                //_productRepository.Add(product);
                Product           product     = Mapper.Map <ProductViewModel, Product>(productVm);
                List <ProductTag> productTags = new List <ProductTag>();
                string[]          arrTag      = productVm.Tag.Split(',');
                foreach (var tag in arrTag)
                {
                    var tagId = TextHelper.ToUnsignString(tag);
                    if (!_tagRepository.FindAll(x => x.Id == tagId).Any())
                    {
                        Tag t = new Tag
                        {
                            Id   = tagId,
                            Name = tag,
                            Type = CommonConstants.ProductTag
                        };
                        _tagRepository.Add(t);
                    }

                    ProductTag producttag = new ProductTag
                    {
                        TagId = tagId
                    };
                    productTags.Add(producttag);
                }
                //ProductTag p = new ProductTag();
                //p.TagId = "tag";
                //p.ProductId = 6;
                //_productTagRepository.Add(p);
                //product.ProductTags.Add(p);
                foreach (var item in productTags)
                {
                    product.ProductTags.Add(item);
                }
                //ProductTag productTag = new ProductTag();
                //productTag.TagId = "Tag";
                //product.ProductTags.Add(productTags = new List<ProductTag>() {
                //    new ProductTag() {TagId = "Tag"}
                //});
                _productRepository.Add(product);
            }
            return(productVm);
        }
Ejemplo n.º 24
0
        public void AddGoodsCategory(GoodsCategoryDTO goodsCategoryDTO, string operatorId)
        {
            var obj = new Domains.Aggregates.GoodsCategory
            {
                Name     = goodsCategoryDTO.Name,
                ParentId = goodsCategoryDTO.ParentId,
                Icon     = goodsCategoryDTO.Icon
            };

            obj.GenerateId();
            _goodsCategoryRepository.Add(obj);

            if (goodsCategoryDTO.Tags != null && goodsCategoryDTO.Tags.Count() > 0)
            {
                foreach (var item in goodsCategoryDTO.Tags)
                {
                    var o = new Domains.Aggregates.Tag {
                        CategoryId = obj.Id, CreatedBy = operatorId, CreatedOn = DateTime.Now, Name = item.Name
                    };
                    o.GenerateId();
                    _tagRepository.Add(o);
                }
            }

            _dbUnitOfWork.Commit();
        }
Ejemplo n.º 25
0
        private List <LunchTag> ConvertTagViewModelsToTags(List <TagViewModel> tagvms)
        {
            List <LunchTag> tags = new List <LunchTag>();

            foreach (TagViewModel tvm in tagvms)
            {
                Tag tag = _tagRepository.GetByName(tvm.Naam);
                if (tag == null)
                {
                    if (tvm.Kleur == null)
                    {
                        tag = new Tag {
                            Naam = tvm.Naam, Kleur = "#000000"
                        }
                    }
                    ;
                    else
                    {
                        tag = new Tag {
                            Naam = tvm.Naam, Kleur = tvm.Kleur
                        }
                    };
                    _tagRepository.Add(tag);
                    _tagRepository.SaveChanges();
                }
                LunchTag lunchTag = new LunchTag {
                    Tag = tag
                };
                tags.Add(lunchTag);
            }
            return(tags);
        }

        #endregion
    }
Ejemplo n.º 26
0
        public void TagPost(int postId, string tag)
        {
            if (string.IsNullOrEmpty(tag))
            {
                throw new ArgumentException("Tag name is invalid");
            }

            var post = _postRepository.AsQuery().FirstOrDefault(p => p.Id == postId);

            if (post == null)
            {
                throw new ArgumentException(string.Format("Specified post (id={0}) does not exist", postId));
            }

            var tagEntity = _tagRepository.AsQuery().FirstOrDefault(t => t.Name == tag);

            // check if a given post is already tagged with tag specified
            if (tagEntity == null || !post.Tags.Any(pt => pt.Id == tagEntity.Id))
            {
                if (tagEntity == null)
                {
                    tagEntity = new Repositories.Entities.Tag
                    {
                        Name = tag
                    };
                    _tagRepository.Add(tagEntity);
                }
                post.Tags.Add(tagEntity);
            }
        }
Ejemplo n.º 27
0
        public ActionResult Add(Tag obj)
        {
            try
            {
                var tag = tagRepository.GetAll().FirstOrDefault(x => x.Name.Trim() == obj.Name.Trim());
                if (tag != null)
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        Messenger = "Tên thẻ tag đã tồn tại",
                    }, JsonRequestBehavior.AllowGet));
                }
                tagRepository.Add(obj);

                return(Json(new
                {
                    IsSuccess = true,
                    Messenger = "Thêm mới thành công",
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    IsSuccess = false,
                    Messenger = string.Format("Thêm mới thất bại")
                }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 28
0
        public void AddServiceCategory(CategoryDTO categoryDTO, string operatorId)
        {
            var obj = new Domains.Aggregates.Category
            {
                Name          = categoryDTO.Name,
                ParentId      = categoryDTO.ParentId,
                Mark          = categoryDTO.Mark,
                ApplicationId = categoryDTO.AppId
            };

            obj.GenerateId();
            _serviceCategoryRepository.Add(obj);

            if (categoryDTO.Tags != null && categoryDTO.Tags.Count() > 0)
            {
                foreach (var item in categoryDTO.Tags)
                {
                    var o = new Domains.Aggregates.Tag {
                        CategoryId = obj.Id, CreatedBy = operatorId, CreatedOn = DateTime.Now, Name = item.Name
                    };
                    o.GenerateId();
                    _tagRepository.Add(o);
                }
            }

            _dbUnitOfWork.Commit();
        }
Ejemplo n.º 29
0
        private void AddTagsToContainers(string tags, IEnumerable <ITagContainer> tagContainers)
        {
            if (!string.IsNullOrEmpty(tags))
            {
                string[] tagNames = tags.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (tagNames.Length > 0)
                {
                    foreach (string t in tagNames)
                    {
                        string tagName = t.NullSafe().StripHtml();

                        if (!string.IsNullOrEmpty(tagName))
                        {
                            ITag tag = _tagRepository.FindByName(tagName);

                            if (tag == null)
                            {
                                tag = _factory.CreateTag(tagName);
                                _tagRepository.Add(tag);
                            }

                            foreach (ITagContainer container in tagContainers)
                            {
                                container.AddTag(tag);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 30
0
        public void CanAddTag()
        {
            int actual = _tagRepository.Add("Running");

            Assert.AreEqual(3, _tagRepository.GetAll().Count);
            Assert.AreEqual(3, actual);
        }