public ElectionVM(ElectionDTO row) { Id = row.Id; Name = row.Name; StartDate = row.StartDate; EndDate = row.EndDate; }
public List <PartyProfileDTO> GetAllPartyProfiles(ElectionDTO election) { try { using (connection = DataConnection.GetConnection()) { connection.Open(); MySqlCommand command = new MySqlCommand($"SELECT * FROM PartyProfile WHERE ElectionID=@ElectionID", connection); command.Parameters.AddWithValue("@ElectionID", election.ID); MySqlDataReader reader = command.ExecuteReader(); List <PartyProfileDTO> partyProfileDTOs = new List <PartyProfileDTO>(); while (reader.Read()) { partyProfileDTOs.Add(new PartyProfileDTO() { ID = (int)reader["ID"], Votes = (int)reader["Votes"], Seats = (int)reader["Seats"], Party = partyRepository.GetPartyByID((int)reader["PartyID"]) }); } return(partyProfileDTOs); } } catch (MySqlException) { throw new Exceptions.PartyProfile.SearchFailedException("Het ophalen van alle partij profielen is mislukt."); } }
public ElectionDTO GetElectionByID(int id) { try { ElectionDTO election = new ElectionDTO(); using (connection = DataConnection.GetConnection()) { connection.Open(); using (MySqlCommand command = new MySqlCommand("SELECT * FROM Election WHERE ID=@ElectionID", connection)) { command.Parameters.AddWithValue("@ElectionID", id); using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { election.ID = (int)reader["ID"]; election.Name = (string)reader["Name"]; election.DistributableSeats = (int)reader["DistributableSeats"]; election.Date = (DateTime)reader["Date"]; } return(election); } } } } catch (MySqlException) { throw new GetElectionByIDFailedException("We konden de door u verzochte verkiezing niet vinden."); } }
public async Task <ElectionDTO> GetElectionDetailsByAddressAsync(string electionAddress) { ElectionDTO election = await _commonDbContext.Elections .Include(e => e.Candidates) .ProjectTo <ElectionDTO>(_mapper.ConfigurationProvider) .SingleOrDefaultAsync(e => e.Address == electionAddress); //find user list var _candidates = election.Candidates; var candidates = await _commonDbContext.Users .Where(u => _candidates.Select(c => c.CandidateAddress).Contains(u.PublicKey)) .ToListAsync(); // push username foreach (var candidate in election.Candidates) { candidate.CandidateName = candidates.Any(c => c.PublicKey == candidate.CandidateAddress) ? candidates.Single(c => c.PublicKey == candidate.CandidateAddress).Name : ""; } //if (election == null) // throw new NotFoundException("election"); return(election); }
public async Task <IActionResult> PutElection(long id, ElectionDTO electionDTO) { if (id != electionDTO.ElectionId) { return(BadRequest()); } var election = await _context.Elections.FindAsync(id); if (election == null) { return(NotFound()); } election.ElectionType = electionDTO.ElectionType; election.ElectionDate = electionDTO.ElectionDate; _context.Entry(election).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!ElectionExists(id)) { return(NotFound()); } return(NoContent()); }
public void CreateElection(ElectionDTO election) { if (election.Date == null || election.Name == null || election.DistributableSeats <= 0) { throw new CreatingElectionFailedException("Niet alle benodigde gegevens zijn ingevuld."); } Context.CreateElection(election); }
public static ElectionDTO GetElectionDTO(Election election) { ElectionDTO dto = new ElectionDTO { ID = election.ID, Name = election.Name, DistributableSeats = election.DistributableSeats, Date = election.Date }; return(dto); }
public static Election GetElectionFromDTO(ElectionDTO dto) { Election election = new Election { ID = dto.ID, Name = dto.Name, DistributableSeats = dto.DistributableSeats, Date = dto.Date }; return(election); }
public async Task <ActionResult <Election> > PostElection(ElectionDTO electionDTO) { var election = new Election { ElectionType = electionDTO.ElectionType, ElectionDate = electionDTO.ElectionDate }; _context.Elections.Add(election); await _context.SaveChangesAsync(); return(CreatedAtAction("GetElection", new { id = election.ElectionId }, ElectionToDTO(election))); }
public async Task <IActionResult> CreateElection([FromBody] ElectionDTO electionDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var election = _mapper.Map <Election>(electionDTO); election.DateCreated = DateTime.Now; _repository.CreateElection(election); await _unitOfWork.CompleteAsync(); return(Ok()); }
public async Task <ElectionDTO> GetElectionAsync(int electionId) { ElectionDTO election = await _commonDbContext.Elections .Include(e => e.Candidates) .ProjectTo <ElectionDTO>(_mapper.ConfigurationProvider) .SingleOrDefaultAsync(e => e.Id == electionId); if (election == null) { throw new NotFoundException("election"); } return(election); }
public void CreateElection(ElectionDTO election) { try { using (connection = DataConnection.GetConnection()) { connection.Open(); using (MySqlCommand command = new MySqlCommand("INSERT INTO Election(Name, DistributableSeats, Date) VALUES (@Name, @DistributableSeats, @Date)", connection)) { command.Parameters.AddWithValue("@Name", election.Name); command.Parameters.AddWithValue("@DistributableSeats", election.DistributableSeats); command.Parameters.AddWithValue("@Date", election.Date); command.ExecuteNonQuery(); } } } catch (MySqlException) { throw new CreatingElectionFailedException("De door u ingevoerde verkiezing kan niet worden aangemaakt."); } }
public void Save(ElectionDTO election) { try { using (connection = DataConnection.GetConnection()) { connection.Open(); using (MySqlCommand command = new MySqlCommand("UPDATE Election SET Name=@Name, DistributableSeats=@DistributableSeats, Date=@Date WHERE ID=@ElectionID", connection)) { command.Parameters.AddWithValue("@ElectionID", election.ID); command.Parameters.AddWithValue("@Name", election.Name); command.Parameters.AddWithValue("@DistributableSeats", election.DistributableSeats); command.Parameters.AddWithValue("@Date", election.Date); command.ExecuteNonQuery(); } } } catch (MySqlException) { throw new UpdatingElectionFailedException("Opslaan verkiezing is mislukt."); } }
public async Task <IActionResult> GetElectionDetails(int electionId) { ElectionDTO election = await _electionService.GetElectionDetailsByIdAsync(electionId); return(Ok(election)); }
public List <PartyProfileDTO> GetAllPartyProfiles(ElectionDTO election) { return(Context.GetAllPartyProfiles(election)); }
public void Save(ElectionDTO election) { Context.Save(election); }
public async Task <IActionResult> GetElectionDetailsByAddress(string electionAddress) { ElectionDTO election = await _electionService.GetElectionDetailsByAddressAsync(electionAddress); return(Ok(election)); }