public async Task DeletePartyAsync(PartyModel model) { using (var context = new StudentElectionContext()) { var party = context.Parties.SingleOrDefault(p => p.Id == model.Id); context.Parties.Remove(party); await context.SaveChangesAsync(); } }
public async Task UpdatePartyAsync(PartyModel model) { using (var context = new StudentElectionContext()) { var party = context.Parties.SingleOrDefault(p => p.Id == model.Id); _mapper.Map(model, party); await context.SaveChangesAsync(); } }
public async Task DeletePositionAsync(PositionModel model) { using (var context = new StudentElectionContext()) { var position = await context.Positions.SingleOrDefaultAsync(p => p.Id == model.Id); context.Positions.Remove(position); await context.SaveChangesAsync(); } }
public async Task SetBallotCodeAsync(BallotModel model) { using (var context = new StudentElectionContext()) { var ballot = await context.Ballots.SingleOrDefaultAsync(b => b.Id == model.Id); ballot.Code = model.Code; await context.SaveChangesAsync(); } }
public async Task DeleteUserAsync(UserModel model) { using (var context = new StudentElectionContext()) { var user = await context.Users.SingleOrDefaultAsync(u => u.Id == model.Id); context.Users.Remove(user); await context.SaveChangesAsync(); } }
public async Task UpdateServerTagAsync(int electionId, string tag) { using (var context = new StudentElectionContext()) { var election = await context.Elections.SingleOrDefaultAsync(e => e.Id == electionId); election.ServerTag = tag; await context.SaveChangesAsync(); } }
public async Task UpdateVoterAsync(VoterModel model) { using (var context = new StudentElectionContext()) { var voter = await context.Voters.SingleOrDefaultAsync(v => v.Id == model.Id); _mapper.Map(model, voter); await context.SaveChangesAsync(); } }
public async Task DeleteCandidateAsync(CandidateModel model) { using (var context = new StudentElectionContext()) { var candidate = await context.Candidates.SingleOrDefaultAsync(c => c.Id == model.Id); context.Candidates.Remove(candidate); await context.SaveChangesAsync(); } }
public async Task UpdatePositionAsync(PositionModel model) { using (var context = new StudentElectionContext()) { var position = await context.Positions.SingleOrDefaultAsync(p => p.Id == model.Id); _mapper.Map(model, position); await context.SaveChangesAsync(); } }
public async Task UpdateCandidateAsync(CandidateModel model) { using (var context = new StudentElectionContext()) { var candidate = await context.Candidates.SingleOrDefaultAsync(c => c.Id == model.Id); _mapper.Map(model, candidate); await context.SaveChangesAsync(); } }
public async Task FinalizeCandidatesAsync(int electionId, DateTime dateTime) { using (var context = new StudentElectionContext()) { var election = await context.Elections.SingleOrDefaultAsync(e => e.Id == electionId); election.CandidatesFinalizedAt = dateTime; await context.SaveChangesAsync(); } }
public async Task DeleteVoterAsync(VoterModel model) { using (var context = new StudentElectionContext()) { var voter = await context.Voters.SingleOrDefaultAsync(v => v.Id == model.Id); context.Voters.Remove(voter); await context.SaveChangesAsync(); } }
public async Task UpdateElectionAsync(ElectionModel model) { using (var context = new StudentElectionContext()) { var election = await context.Elections.SingleOrDefaultAsync(c => c.Id == model.Id); _mapper.Map(model, election); await context.SaveChangesAsync(); } }
public async Task <int> AddElectionAsync(ElectionModel model) { using (var context = new StudentElectionContext()) { var election = new Election(); _mapper.Map(model, election); context.Elections.Add(election); return(await context.SaveChangesAsync()); } }
public async Task InsertVoterAsync(VoterModel model) { var voter = new Voter(); _mapper.Map(model, voter); using (var context = new StudentElectionContext()) { context.Voters.Add(voter); await context.SaveChangesAsync(); } }
public async Task InsertCandidateAsync(CandidateModel model) { var candidate = new Candidate(); _mapper.Map(model, candidate); using (var context = new StudentElectionContext()) { context.Candidates.Add(candidate); await context.SaveChangesAsync(); } }
public async Task InsertPartyAsync(PartyModel model) { var party = new Party(); _mapper.Map(model, party); using (var context = new StudentElectionContext()) { context.Parties.Add(party); await context.SaveChangesAsync(); } }
public async Task InsertPositionAsync(PositionModel model) { var position = new Position(); _mapper.Map(model, position); using (var context = new StudentElectionContext()) { context.Positions.Add(position); await context.SaveChangesAsync(); } }
public async Task UpdateUserAsync(UserModel model) { using (var context = new StudentElectionContext()) { var user = await context.Users.SingleOrDefaultAsync(u => u.Id == model.Id); _mapper.Map(model, user); context.Users.Add(user); await context.SaveChangesAsync(); } }
public async Task AddUserAsync(UserModel model) { var user = new User(); _mapper.Map(model, user); using (var context = new StudentElectionContext()) { context.Users.Add(user); await context.SaveChangesAsync(); } }
public async Task InsertElectionAsync(ElectionModel model) { var election = new Election(); _mapper.Map(model, election); using (var context = new StudentElectionContext()) { context.Elections.Add(election); await context.SaveChangesAsync(); } }
public async Task InsertVotersAsync(IEnumerable <VoterModel> voters) { using (var context = new StudentElectionContext()) { foreach (var model in voters) { var voter = new Voter(); _mapper.Map(model, voter); context.Voters.Add(voter); } await context.SaveChangesAsync(); } }
public async Task InsertCandidatesAsync(IEnumerable <CandidateModel> candidates) { using (var context = new StudentElectionContext()) { foreach (var model in candidates) { var candidate = new Candidate(); _mapper.Map(model, candidate); context.Candidates.Add(candidate); } await context.SaveChangesAsync(); } }
public async Task SwitchRankAsync(PositionModel selectedPosition, PositionModel closestPosition) { using (var context = new StudentElectionContext()) { var sPosition = await context.Positions.SingleOrDefaultAsync(p => p.Id == selectedPosition.Id); sPosition.Rank = closestPosition.Rank; var cPosition = await context.Positions.SingleOrDefaultAsync(p => p.Id == closestPosition.Id); cPosition.Rank = selectedPosition.Rank; await context.SaveChangesAsync(); } }
public async Task <BallotModel> InsertBallotAsync(VoterModel voter, DateTime enteredAt) { using (var context = new StudentElectionContext()) { var ballot = new Ballot { Code = string.Empty, EnteredAt = enteredAt, VoterId = voter.Id }; context.Ballots.Add(ballot); await context.SaveChangesAsync(); } return(await GetBallotByVinAsync(voter.ElectionId, voter.Vin)); }
public async Task CastVotesAsync(int ballotId, IEnumerable <VoteModel> votes, DateTime castedAt) { using (var context = new StudentElectionContext()) { foreach (var model in votes) { var vote = new Vote(); _mapper.Map(model, vote); context.Votes.Add(vote); } var ballot = await context.Ballots.SingleOrDefaultAsync(b => b.Id == ballotId); if (ballot.CastedAt != null) { throw new InvalidOperationException("The votes from this ballot has already been casted."); } ballot.CastedAt = castedAt; await context.SaveChangesAsync(); } }