Ejemplo n.º 1
0
        /// <summary>
        /// Delete a Person record, and all dependent records.
        /// </summary>
        /// <param name="dataContext"></param>
        /// <param name="personId"></param>
        /// <returns></returns>
        private bool DeletePerson(RockContext dataContext, int personId)
        {
            var personService = new PersonService(dataContext);

            var person = personService.Get(personId);

            if (person == null)
            {
                return(false);
            }

            // Delete Person Views
            var personViewedService = new PersonViewedService(dataContext);

            var personViewedQuery = personViewedService.Queryable()
                                    .Where(x => x.TargetPersonAlias.PersonId == person.Id || x.ViewerPersonAlias.PersonId == person.Id);

            personViewedService.DeleteRange(personViewedQuery);

            // Delete Communications
            var communicationService = new CommunicationService(dataContext);

            var communicationQuery = communicationService.Queryable()
                                     .Where(x => x.SenderPersonAlias.PersonId == person.Id);

            communicationService.DeleteRange(communicationQuery);

            // Delete Communication Recipients
            var recipientsService = new CommunicationRecipientService(dataContext);

            var recipientsQuery = recipientsService.Queryable()
                                  .Where(x => x.PersonAlias.PersonId == person.Id);

            recipientsService.DeleteRange(recipientsQuery);

            // Delete Interactions
            var interactionService = new InteractionService(dataContext);

            var interactionQuery = interactionService.Queryable()
                                   .Where(x => x.PersonAlias.PersonId == person.Id);

            interactionService.DeleteRange(interactionQuery);

            // Delete Person Aliases
            var personAliasService = new PersonAliasService(dataContext);

            personAliasService.DeleteRange(person.Aliases);

            // Delete Person Search Keys
            var personSearchKeyService = new PersonSearchKeyService(dataContext);

            var searchKeys = person.GetPersonSearchKeys(dataContext);

            personSearchKeyService.DeleteRange(searchKeys);

            // Delete Person
            personService.Delete(person);

            return(true);
        }
        /// <summary>
        /// Creates the person alias data.
        /// </summary>
        private static void CreatePersonAliasData()
        {
            var tedDeckerGuid = TestGuids.TestPeople.TedDecker.AsGuid();

            var personAliasService = new PersonAliasService(_rockContext);
            var personService      = new PersonService(_rockContext);
            var tedDecker          = personService.Get(tedDeckerGuid);
            var aliasPersonId      = personService.Queryable().Max(p => p.Id) + 1;

            personAliasService.DeleteRange(personAliasService.Queryable().Where(pa => pa.AliasPersonId >= aliasPersonId));
            _rockContext.SaveChanges();

            for (var i = 0; i < NUMBER_OF_ALIASES; i++)
            {
                personAliasService.Add(new PersonAlias {
                    Person = tedDecker, AliasPersonGuid = Guid.NewGuid(), AliasPersonId = aliasPersonId + i, ForeignKey = KEY
                });
            }

            _rockContext.SaveChanges();

            var personAlias = personAliasService.Queryable().Where(pa => pa.Person.Guid == tedDeckerGuid && pa.ForeignKey == KEY).Take(NUMBER_OF_ALIASES).Select(p => p.Id).ToList();

            _personAliasIds = personAlias;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete the test data
        /// </summary>
        private static void DeleteTestData()
        {
            using (var rockContext = new RockContext())
            {
                var stepService = new StepService(rockContext);
                var stepQuery   = stepService.Queryable().Where(s => s.ForeignKey == ForeignKey);
                stepService.DeleteRange(stepQuery);
                rockContext.SaveChanges();
            }

            using (var rockContext = new RockContext())
            {
                var stepProgramService = new StepProgramService(rockContext);
                var stepProgramQuery   = stepProgramService.Queryable().Where(sp => sp.ForeignKey == ForeignKey);
                stepProgramService.DeleteRange(stepProgramQuery);
                rockContext.SaveChanges();
            }

            using (var rockContext = new RockContext())
            {
                var personSearchKeyService = new PersonSearchKeyService(rockContext);
                var personSearchKeyQuery   = personSearchKeyService.Queryable()
                                             .Where(psk =>
                                                    psk.PersonAlias.Person.ForeignKey == ForeignKey ||
                                                    PersonGuids.Contains(psk.PersonAlias.Person.Guid));
                personSearchKeyService.DeleteRange(personSearchKeyQuery);
                rockContext.SaveChanges();
            }

            using (var rockContext = new RockContext())
            {
                var personAliasService = new PersonAliasService(rockContext);
                var personAliasQuery   = personAliasService.Queryable()
                                         .Where(pa =>
                                                pa.Person.ForeignKey == ForeignKey ||
                                                PersonGuids.Contains(pa.Person.Guid));
                personAliasService.DeleteRange(personAliasQuery);
                rockContext.SaveChanges();
            }

            using (var rockContext = new RockContext())
            {
                var personService = new PersonService(rockContext);
                var personQuery   = personService.Queryable()
                                    .Where(p =>
                                           p.ForeignKey == ForeignKey ||
                                           PersonGuids.Contains(p.Guid));
                personService.DeleteRange(personQuery);
                rockContext.SaveChanges();
            }
        }
        /// <summary>
        /// Delete the test data
        /// </summary>
        private static void DeleteTestData()
        {
            var rockContext = new RockContext();

            var stepProgramService = new StepProgramService(rockContext);
            var stepProgramQuery   = stepProgramService.Queryable().Where(sp => sp.ForeignKey == ForeignKey);

            stepProgramService.DeleteRange(stepProgramQuery);
            rockContext.SaveChanges();

            var dataViewFilterService = new DataViewFilterService(rockContext);
            var dvfQuery = dataViewFilterService.Queryable().Where(dvf => dvf.DataView.ForeignKey == ForeignKey || dvf.ForeignKey == ForeignKey);

            dataViewFilterService.DeleteRange(dvfQuery);
            rockContext.SaveChanges();

            var dataViewService = new DataViewService(rockContext);
            var dvQuery         = dataViewService.Queryable().Where(dv => dv.ForeignKey == ForeignKey);

            dataViewService.DeleteRange(dvQuery);
            rockContext.SaveChanges();

            var personSearchKeyService = new PersonSearchKeyService(rockContext);
            var personSearchKeyQuery   = personSearchKeyService.Queryable().Where(psk => psk.PersonAlias.Person.ForeignKey == ForeignKey);

            personSearchKeyService.DeleteRange(personSearchKeyQuery);

            var personAliasService = new PersonAliasService(rockContext);
            var personAliasQuery   = personAliasService.Queryable().Where(pa => pa.Person.ForeignKey == ForeignKey || pa.ForeignKey == ForeignKey);

            personAliasService.DeleteRange(personAliasQuery);
            rockContext.SaveChanges();

            var personService = new PersonService(rockContext);
            var personQuery   = personService.Queryable().Where(p => p.ForeignKey == ForeignKey);

            personService.DeleteRange(personQuery);
            rockContext.SaveChanges();
        }