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 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); }
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); } } }
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); }
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); }
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); }
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); }
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); }
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); } } }
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); }
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); }
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); }
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(); } } }
public Product Create(Product product) { var resultProduct = _productRepository.Add(product); _unitOfWork.Commit(); 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); } ProductTag productTag = new ProductTag(); productTag.ProductID = product.ID; productTag.TagID = tagID; _productTagRepository.Add(productTag); } } } return(resultProduct); }
public Product Add(Product Product) { //thêm mới 1 sản phẩm var product = _ProductRepository.Add(Product); _unitOfWork.Commit(); // lấy trường Tags bên sản phẩm đẩy quá bảng Tags if (!string.IsNullOrEmpty(Product.Tags)) { string[] tags = Product.Tags.Split(','); for (var i = 0; i < tags.Length; i++) { // chuyển đổi chuỗi ký tự bằng static method trong common var tagID = StringHelper.ToUnsignString(tags[i]); if (_tagRepository.Count(x => x.ID == tagID) == 0) { // tạo ra 1 đối tượng tag mới add vô bảng Tags Tag tag = new Tag { ID = tagID, Name = tags[i], Type = CommonConstants.ProductTag }; _tagRepository.Add(tag); } // add tag vừa tạo add vào bảng productTags ProductTag productTag = new ProductTag { ProductID = Product.ID, TagID = tagID }; _productTagRepository.Add(productTag); } } return(product); }
public int Count() { return(rep.Count()); }