public virtual void Delete(string[] ids, string[] memberTypes = null)
 {
     using (var repository = RepositoryFactory())
     {
         var members = GetByIds(ids, null, memberTypes);
         if (!members.IsNullOrEmpty())
         {
             foreach (var member in members)
             {
                 MemberEventventPublisher.Publish(new MemberChangingEvent(EntryState.Deleted, member));
             }
             repository.RemoveMembersByIds(members.Select(m => m.Id).ToArray());
             CommitChanges(repository);
             foreach (var member in members)
             {
                 DynamicPropertyService.DeleteDynamicPropertyValues(member);
                 var seoObject = member as ISeoSupport;
                 if (seoObject != null)
                 {
                     CommerceService.DeleteSeoForObject(seoObject);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Create or update members in database
        /// </summary>
        /// <param name="members"></param>
        public virtual void SaveChanges(Member[] members)
        {
            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = RepositoryFactory())
                using (var changeTracker = GetChangeTracker(repository))
                {
                    var existingMemberEntities = repository.GetMembersByIds(members.Where(m => !m.IsTransient()).Select(m => m.Id).ToArray());

                    foreach (var member in members)
                    {
                        var memberEntityType = AbstractTypeFactory <Member> .AllTypeInfos.Where(t => t.MappedType != null && t.IsAssignableTo(member.MemberType)).Select(t => t.MappedType).FirstOrDefault();

                        if (memberEntityType != null)
                        {
                            var dataSourceMember = AbstractTypeFactory <MemberDataEntity> .TryCreateInstance(memberEntityType.Name);

                            if (dataSourceMember != null)
                            {
                                dataSourceMember.FromModel(member, pkMap);

                                var dataTargetMember = existingMemberEntities.FirstOrDefault(m => m.Id == member.Id);
                                if (dataTargetMember != null)
                                {
                                    changeTracker.Attach(dataTargetMember);
                                    dataSourceMember.Patch(dataTargetMember);
                                    MemberEventventPublisher.Publish(new MemberChangingEvent(EntryState.Modified, member));
                                }
                                else
                                {
                                    repository.Add(dataSourceMember);
                                    MemberEventventPublisher.Publish(new MemberChangingEvent(EntryState.Added, member));
                                }
                            }
                        }
                    }

                    CommitChanges(repository);
                    pkMap.ResolvePrimaryKeys();
                }

            //Save dynamic properties
            foreach (var member in members)
            {
                DynamicPropertyService.SaveDynamicPropertyValues(member);
            }

            CommerceService.UpsertSeoForObjects(members.OfType <ISeoSupport>().ToArray());
        }
        /// <summary>
        /// Create or update members in database
        /// </summary>
        /// <param name="members"></param>
        public virtual void CreateOrUpdate(Member[] members)
        {
            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = RepositoryFactory())
                using (var changeTracker = GetChangeTracker(repository))
                {
                    var dataExistMembers = repository.GetMembersByIds(members.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray());
                    foreach (var member in members)
                    {
                        var dataSourceMember = TryCreateDataMember(member);
                        if (dataSourceMember != null)
                        {
                            dataSourceMember.FromMember(member, pkMap);
                            var dataTargetMember = dataExistMembers.FirstOrDefault(x => x.Id == member.Id);
                            if (dataTargetMember != null)
                            {
                                changeTracker.Attach(dataTargetMember);
                                dataSourceMember.Patch(dataTargetMember);
                                MemberEventventPublisher.Publish(new MemberChangingEvent(EntryState.Modified, member));
                            }
                            else
                            {
                                repository.Add(dataSourceMember);
                                MemberEventventPublisher.Publish(new MemberChangingEvent(EntryState.Added, member));
                            }
                        }
                    }
                    CommitChanges(repository);
                    pkMap.ResolvePrimaryKeys();
                }
            //Save dynamic properties
            foreach (var member in members)
            {
                DynamicPropertyService.SaveDynamicPropertyValues(member);
            }
        }