/// <summary> /// Set person's flag based on what is default for this election /// </summary> public bool ApplyVoteReasonFlags(Person person) { // using only what they have var changed = false; var reason = IneligibleReasonEnum.Get(person.IneligibleReasonGuid); if (reason == null) { // no reason, so set to true if (!person.CanVote.GetValueOrDefault()) { person.CanVote = true; changed = true; } if (!person.CanReceiveVotes.GetValueOrDefault()) { person.CanReceiveVotes = true; changed = true; } } else { // update to match what this reason implies if (person.CanVote != reason.CanVote) { person.CanVote = reason.CanVote; changed = true; } if (person.CanReceiveVotes != reason.CanReceiveVotes) { person.CanReceiveVotes = reason.CanReceiveVotes; changed = true; } } return(changed); }
/// <summary> /// Ensure the flags match the Guid /// </summary> /// <param name="people"></param> /// <param name="hub"></param> /// <param name="personSaver"></param> public void EnsureFlagsAreRight(List <Person> people, IStatusUpdateHub hub, Action <DbAction, Person> personSaver) { hub.StatusUpdate("Reviewing people", true); var currentElectionGuid = UserSession.CurrentElectionGuid; // var defaultCanVote = UserSession.CurrentElection.CanVote == "A"; // var defaultCanReceiveVotes = UserSession.CurrentElection.CanReceive == "A"; var numDone = 0; foreach (var person in people) { var changesMade = false; numDone++; if (numDone % 10 == 0) { hub.StatusUpdate("Reviewed {0} people".FilledWith(numDone), true); } if (currentElectionGuid != person.ElectionGuid) { hub.StatusUpdate("Found unexpected person. Please review. Name: " + person.C_FullName); } var matchedReason = IneligibleReasonEnum.Get(person.IneligibleReasonGuid); if (person.IneligibleReasonGuid.HasValue && matchedReason == null) { personSaver(DbAction.Attach, person); person.IneligibleReasonGuid = IneligibleReasonEnum.Ineligible_Other; hub.StatusUpdate("Found unknown ineligible reason. Set to Unknown. Name: " + person.C_FullName); changesMade = true; } if (ApplyVoteReasonFlags(person)) { personSaver(DbAction.Attach, person); changesMade = true; } // var reason = IneligibleReasonEnum.Get(person.IneligibleReasonGuid); // if (reason == null) // { // unknownIneligibleGuid = true; // } // else // { // var canVote = reason.CanVote; // var canReceiveVotes = reason.CanReceiveVotes; // // if (canVote != person.CanVote || canReceiveVotes != person.CanReceiveVotes) // { // personSaver(DbAction.Attach, person); // person.CanVote = canVote; // person.CanReceiveVotes = canReceiveVotes; // } // } // else // { // if (defaultCanVote != person.CanVote || defaultCanReceiveVotes != person.CanReceiveVotes) // { // personSaver(DbAction.Attach, person); // person.CanVote = defaultCanVote; // person.CanReceiveVotes = defaultCanReceiveVotes; // changesMade = true; // } // } if (changesMade) { // personSaver(DbAction.Save, person); Db.SaveChanges(); } } hub.StatusUpdate("Reviewed {0} people".FilledWith(numDone)); }
/// <summary> /// Ensure the flags match the Guid /// </summary> /// <param name="people"></param> /// <param name="hub"></param> /// <param name="personSaver"></param> public void EnsureFlagsAreRight(List <Person> people, IStatusUpdateHub hub, Action <DbAction, Person> personSaver) { hub.StatusUpdate("Reviewing people", true); var currentElectionGuid = UserSession.CurrentElectionGuid; var numDone = 0; foreach (var person in people) { var changesMade = false; var unknownIneligibleGuid = false; numDone++; if (numDone % 10 == 0) { hub.StatusUpdate("Reviewed {0} people".FilledWith(numDone), true); } if (currentElectionGuid != person.ElectionGuid) { hub.StatusUpdate("Reviewed {0} people".FilledWith(numDone)); hub.StatusUpdate("Found unexpected person. Please review. Name: " + person.C_FullNameFL); } if (person.IneligibleReasonGuid.HasValue) { var reason = IneligibleReasonEnum.Get(person.IneligibleReasonGuid); if (reason == null) { unknownIneligibleGuid = true; } else { var canVote = reason.CanVote; var canReceiveVotes = reason.CanReceiveVotes; if (canVote != person.CanVote || canReceiveVotes != person.CanReceiveVotes) { personSaver(DbAction.Attach, person); person.CanVote = canVote; person.CanReceiveVotes = canReceiveVotes; changesMade = true; } } } if (unknownIneligibleGuid) { personSaver(DbAction.Attach, person); person.IneligibleReasonGuid = IneligibleReasonEnum.Ineligible_Other; hub.StatusUpdate("Reviewed {0} people".FilledWith(numDone)); hub.StatusUpdate("Found unknown ineligible reason. Set to Unknown. Name: " + person.C_FullNameFL); changesMade = true; } if (changesMade) { personSaver(DbAction.Save, person); } } hub.StatusUpdate("Reviewed {0} people".FilledWith(numDone)); }