/// <summary> /// Delete a customer tag /// </summary> /// <param name="customerTag">Customer tag</param> public virtual void DeleteCustomerTag(CustomerTag customerTag) { if (customerTag == null) throw new ArgumentNullException("productTag"); var builder = Builders<Customer>.Update; var updatefilter = builder.Pull(x => x.CustomerTags, customerTag.Id); var result = _customerRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter).Result; _customerTagRepository.Delete(customerTag); //event notification _eventPublisher.EntityDeleted(customerTag); }
/// <summary> /// Updates the customer tag /// </summary> /// <param name="customerTag">Customer tag</param> public virtual void UpdateCustomerTag(CustomerTag customerTag) { if (customerTag == null) throw new ArgumentNullException("customerTag"); _customerTagRepository.Update(customerTag); //event notification _eventPublisher.EntityUpdated(customerTag); }
protected virtual void SaveCustomerTags(Customer customer, string[] customerTags) { if (customer == null) throw new ArgumentNullException("customer"); //product tags var existingCustomerTags = customer.CustomerTags.ToList(); var customerTagsToRemove = new List<CustomerTag>(); foreach (var existingCustomerTag in existingCustomerTags) { bool found = false; var existingCustomerTagName = _customerTagService.GetCustomerTagById(existingCustomerTag); foreach (string newCustomerTag in customerTags) { if (existingCustomerTagName.Name.Equals(newCustomerTag, StringComparison.InvariantCultureIgnoreCase)) { found = true; break; } } if (!found) { customerTagsToRemove.Add(existingCustomerTagName); _customerTagService.DeleteTagFromCustomer(existingCustomerTagName.Id, customer.Id); } } foreach (string customerTagName in customerTags) { CustomerTag customerTag; var customerTag2 = _customerTagService.GetCustomerTagByName(customerTagName); if (customerTag2 == null) { customerTag = new CustomerTag { Name = customerTagName, }; _customerTagService.InsertCustomerTag(customerTag); } else { customerTag = customerTag2; } if (!customer.CustomerTags.Contains(customerTag.Id)) { _customerTagService.InsertTagToCustomer(customerTag.Id, customer.Id); } } }