Beispiel #1
0
        public async Task <long> CreateApplicant(Core.Applicant.Applicant applicant)
        {
            await _context.Applicants.AddAsync(applicant);

            await _context.SaveChangesAsync();

            return(applicant.Id);
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Email")] Elector elector)
        {
            if (ModelState.IsValid)
            {
                _context.Add(elector);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(elector));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,ApplicantProfileWebSite")] Applicant applicant)
        {
            if (ModelState.IsValid)
            {
                _context.Add(applicant);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(applicant));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("Id,Applicant,ElectionCount")] ApplicantVotes applicantVotes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(applicantVotes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(applicantVotes));
        }
        public async Task <IActionResult> Create([Bind("Id,ElectorId,ApplicantId")] Election election)
        {
            if (ModelState.IsValid)
            {
                _context.Add(election);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicantId"] = new SelectList(_context.Applicant, "Id", "Id", election.ApplicantId);
            ViewData["ElectorId"]   = new SelectList(_context.Set <Elector>(), "Id", "Id", election.ElectorId);
            return(View(election));
        }
Beispiel #6
0
        public async Task <bool> Create(Applicant applicant)
        {
            var success = false;

            _databaseContext.Applicant.Add(applicant);

            var numberOfApplicantsCreated = await _databaseContext.SaveChangesAsync();

            if (numberOfApplicantsCreated == 1)
            {
                success = true;
            }

            return(success);
        }
        public async Task <TEntity> AddAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                await _applicantContext.AddAsync(entity);

                await _applicantContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception)
            {
                throw new Exception($"{nameof(entity)} could not be saved");
            }
        }
Beispiel #8
0
        /// <summary>
        /// Add applicant. return the custom exception if entity null. Also logs the exception if unable to save entity.
        /// </summary>
        /// <param name="entity"> take the entity as a parameter </param>
        /// <returns>Returns the created applicant</returns>
        public async Task <TEntity> AddAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new HahnException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                await _applicantContext.AddAsync(entity);

                await _applicantContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw new HahnException($"{nameof(entity)} could not be saved");
            }
        }
 public async Task <int> AddApplicant(Applicant applicant)
 {
     _context.Applicants.Add(applicant);
     return(await _context.SaveChangesAsync());
 }