Пример #1
0
        public void AutoFix(Person person, List <Vote> voteList, PeopleModel peopleModel, ref bool saveNeeded)
        {
            var oldCombined = person.CombinedInfo;

            peopleModel.SetCombinedInfos(person);

            if (person.CombinedInfo == oldCombined)
            {
                //didn't need to fix it
                return;
            }

            saveNeeded = true;

            foreach (var vote in voteList.Where(v => v.PersonGuid == person.PersonGuid))
            {
                vote.PersonCombinedInfo = person.CombinedInfo;
            }
        }
Пример #2
0
        private void UpgradeOldData()
        {
            var Db           = GetNewDbContext();
            var personCacher = new PersonCacher(Db);
            var testInfo     = personCacher.AllForThisElection.Select(p => new { p.CombinedInfo }).FirstOrDefault();

            if (testInfo == null)
            {
                return;
            }

            if (testInfo.CombinedInfo.HasContent() && !testInfo.CombinedInfo.Contains("^"))
            {
                return;
            }

            // fix all data
            var voteCacher = new VoteCacher(Db);

            var people = personCacher.AllForThisElection;
            var votes  = voteCacher.AllForThisElection;

            var peopleModel = new PeopleModel();
            var saveNeeded  = false;

            foreach (var person in people)
            {
                AutoFix(person, votes, peopleModel, ref saveNeeded);
            }

            if (saveNeeded)
            {
                Db.SaveChanges();

                new LogHelper().Add("Updated person combined infos");
            }

            personCacher.DropThisCache();
            voteCacher.DropThisCache();
        }