コード例 #1
0
        public IActionResult PostApplicant([FromBody] Applicant applicant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (ApplicantExists(applicant.ApplicantCode))
            {
                return(BadRequest());
            }

            try
            {
                using (var scope = new TransactionScope())
                {
                    _context.CreateApplicant(applicant);
                    scope.Complete();
                }
            }
            catch (DbUpdateException)
            {
                if (ApplicantExists(applicant.ApplicantCode))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetApplicant", new { id = applicant.ApplicantCode }, applicant));
        }
コード例 #2
0
        public async Task <long> CreateApplicant(CreateApplicantDto createApplicantDto)
        {
            var applicant = new Core.Applicant.Applicant
            {
                FirstName   = createApplicantDto.FirstName,
                LastName    = createApplicantDto.LastName,
                DateOfBirth = createApplicantDto.DateOfBirth,
                Email       = createApplicantDto.Email,
            };

            return(await _repository.CreateApplicant(applicant));
        }
コード例 #3
0
        public async Task <IActionResult> CreateApplicant([FromBody] ApplicantModel applicantModel)
        {
            var postapplicant = await _applicantRepository.CreateApplicant(applicantModel);

            if (postapplicant > 0)
            {
                return(Ok(postapplicant));
            }
            else
            {
                return(BadRequest());
            }
        }