public void ChangeShareHolderStatus(int shareHolderId, int newStatus) { ShareHolder sh = _context.ShareHolders .Include("VotingCards") .Include("VotingByHands") .Where(s => s.ShareHolderId == shareHolderId) .FirstOrDefault(); var newStatusInEnum = (StatusAtMeeting)newStatus; if (sh == null || sh.StatusAtMeeting == newStatusInEnum) { return; } if ((sh.StatusAtMeeting == StatusAtMeeting.Attended && newStatusInEnum == StatusAtMeeting.Delegated) || sh.StatusAtMeeting == StatusAtMeeting.Delegated && newStatusInEnum == StatusAtMeeting.Attended) { sh.StatusAtMeeting = newStatusInEnum; _context.SaveChanges(); return; } //Update Status sh.StatusAtMeeting = newStatusInEnum; StatusAtMeeting newStateInEnum = (StatusAtMeeting)newStatus; switch (newStateInEnum) { case StatusAtMeeting.Absent: //sh.RemoveAllVotingCardsAndVotingByHands(); _context.RemoveVotingCardsAndVotingByHands(sh.ShareHolderId); break; case StatusAtMeeting.Attended: CreateVotingCardsAndVotingByHands(sh); break; case StatusAtMeeting.Delegated: CreateVotingCardsAndVotingByHands(sh); break; default: throw new ArgumentOutOfRangeException(); } _context.SaveChanges(); }
public void ChangeShareHolderStatus(int shareHolderId, int newStatus) { ShareHolder sh = _shareHolderRepo.Find(shareHolderId); var newStatusInEnum = (StatusAtMeeting)newStatus; if (sh == null || sh.StatusAtMeeting == newStatusInEnum) { return; } if ((sh.StatusAtMeeting == StatusAtMeeting.Attended && newStatusInEnum == StatusAtMeeting.Delegated) || sh.StatusAtMeeting == StatusAtMeeting.Delegated && newStatusInEnum == StatusAtMeeting.Attended) { sh.StatusAtMeeting = newStatusInEnum; _shareHolderRepo.Save(); return; } //Update Status sh.StatusAtMeeting = newStatusInEnum; StatusAtMeeting newStateInEnum = (StatusAtMeeting)newStatus; switch (newStateInEnum) { case StatusAtMeeting.Absent: sh.RemoveAllVotingCardsAndVotingByHands(); break; case StatusAtMeeting.Attended: CreateVotingCardsAndVotingByHands(sh); break; case StatusAtMeeting.Delegated: CreateVotingCardsAndVotingByHands(sh); break; default: throw new ArgumentOutOfRangeException(); } _shareHolderRepo.Save(); }