예제 #1
0
        public async Task <Election> AddCandidateToElectionAsync(int electionId, string candidateAddress)
        {
            Election election = await _commonDbContext.Elections
                                .Include(e => e.Candidates)
                                .SingleOrDefaultAsync(e => e.Id == electionId);

            if (election == null)
            {
                throw new NotFoundException("election");
            }

            if (!election.Candidates.Any(c => c.Candidate == candidateAddress))
            {
                ElectionCandidate candidate = new ElectionCandidate
                {
                    ElectionId = electionId,
                    Candidate  = candidateAddress
                };

                _commonDbContext.ElectionCandidates.Add(candidate);

                await _commonDbContext.SaveChangesAsync();

                election.Candidates.Add(candidate);
            }

            return(election);
        }
예제 #2
0
        public ElectionCandidate ConvertToCandidate(int?id)
        {
            var electionCandidateObj = new ElectionCandidate();

            electionCandidateObj = _registrationContext.ElectionCandidates.Where(x => x.Id == id).Select(item => new ElectionCandidate()
            {
                Id           = item.Id,
                Name         = item.Name,
                Address      = item.Address,
                Description  = item.Description,
                Mobile       = item.Mobile,
                NID          = item.NID,
                ImageUrl     = FormatFileUrl(item.ImageUrl),
                Motto        = item.Motto,
                LogoImageUrl = FormatFileUrl(item.LogoImageUrl),
                DateOfBirth  = item.DateOfBirth,
                PdfListUrl   = item.PdfListUrl.Select(g => new PdfList()
                {
                    Id   = g.Id,
                    Name = g.Name,
                    URL  = FormatFileUrl(g.URL)
                }).ToList()
            }).FirstOrDefault();

            return(electionCandidateObj);
        }
예제 #3
0
        public void EditCandidate(ElectionCandidate electionCandidate)
        {
            var obj = _electionUnitOfWork.CandidateRepository.GetById(electionCandidate.Id);

            obj.Mobile       = electionCandidate.Mobile;
            obj.Address      = electionCandidate.Address;
            obj.Description  = electionCandidate.Description;
            obj.Motto        = electionCandidate.Motto;
            obj.ImageUrl     = electionCandidate.ImageUrl;
            obj.LogoImageUrl = electionCandidate.LogoImageUrl;
            _electionUnitOfWork.CandidateRepository.Edit(obj);
            _electionUnitOfWork.Save();
        }
        public void AddModelElection(RegistrationData registrationData)
        {
            var getVoterObj1 = new ElectionCandidate();
            var getVoterObj2 = new ElectionCandidate();

            getVoterObj1 = _getService.GetElectionCandidate((int)registrationData.CID1);
            getVoterObj2 = _getService.GetElectionCandidate((int)registrationData.CID2);
            _addingService.AddElection(new MakeElection
            {
                CID1         = registrationData.CID1,
                CDName1      = getVoterObj1.Name,
                CID2         = registrationData.CID2,
                CDName2      = getVoterObj2.Name,
                ElectionName = registrationData.ElectionName,
                ElectionDate = registrationData.ElectionDate,
                Count1       = 0,
                Count2       = 0
            });
        }
예제 #5
0
 public void AddCandidate(ElectionCandidate electionCandidate)
 {
     _electionUnitOfWork.CandidateRepository.Add(electionCandidate);
     _electionUnitOfWork.Save();
 }