public void Update(Product Product) { _productRepository.Update(Product); 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); } _productTagRepository.DeleteMulti(x => x.ProductID == Product.ID); ProductTag productTag = new ProductTag(); productTag.ProductID = Product.ID; productTag.TagID = tagId; _productTagRepository.Add(productTag); } } }
private void AddProductTag(Product product, List <string> tags) { tags = tags ?? new List <string>(); if (product.Id > 0) { _productTagRepository.DeleteMulti(x => x.ProductId == product.Id); } else { product.ProductTags = new List <ProductTag>(); } if (tags.Count() > 0) { foreach (var newTag in tags) { var tag = new ProductTag(); tag.Tag = newTag; product.ProductTags.Add(tag); } } }
public void Update(Product product) { _productRepository.Update(product); if (!string.IsNullOrEmpty(product.Tags)) { string[] strTag = product.Tags.Split(','); for (int i = 0; i < strTag.Length; i++) { if (!string.IsNullOrEmpty(strTag[i])) { var tagID = StringHelper.ToUnsignString(strTag[i]); if (_tagRepository.Count(x => x.ID == tagID) == 0) { var tag = new Tag(); tag.ID = tagID; tag.Name = strTag[i]; tag.Type = CommonConstants.ProductTag; _tagRepository.Add(tag); } _productTagRepository.DeleteMulti(x => x.ProductID == product.ID); ProductTag productTag = new ProductTag(); productTag.ProductID = product.ID; productTag.TagID = tagID; _productTagRepository.Add(productTag); } } } }
public Product Delete(int id) { _productTagRepository.DeleteMulti(x => x.ProductID == id); return(_productRepository.Delete(id)); }