public async Task <ActionResult <Applicant> > CreateApplicant(Applicant applicant)
        {
            try
            {
                if (applicant == null)
                {
                    Log.Error($"{Section.GetValue<string>("RetreiveFromDbError")}\nCode: [{Code400}]");
                    return(BadRequest());
                }
                //var app = applicantRepository.GetApplicantByEmail(applicant.EmailAddress);
                //if (app != null)
                //{
                //    ModelState.AddModelError("email", "Applicant email already in use");
                //    return BadRequest(ModelState);
                //}
                var createdApplicant = await applicantRepository.AddApplicant(applicant);

                Log.Information($"Object created: [object=Applicant; id={createdApplicant.ID}; name={createdApplicant.Name}; \naddress={createdApplicant.Address}; e-mail={createdApplicant.EmailAddress}]");
                Log.Debug($"Created object: [{createdApplicant}]");
                return(CreatedAtAction(nameof(GetAplicant), new { id = createdApplicant.ID }, createdApplicant));
            }
            catch (Exception err)
            {
                Log.Error($"Exception occured: [{err}]\nStatusCode:{Code500}");
                return(StatusCode(Code500, Section.GetValue <string>("RetreiveFromDbError")));
            }
        }
Esempio n. 2
0
        public void AddApplicant(Applicant applicant)
        {
            IApplicantRepository repo = RepoFactory.CreateApplicantRepository();

            applicant.ApplicantID = GetApplicantID(repo.GetAll());
            repo.AddApplicant(applicant);
        }
Esempio n. 3
0
        public async Task <IActionResult> AddApplicant([FromBody] ApplicantToAddDTO applicant)
        {
            _logger.LogInformation("\t\n\n=========================================================================\n\nAccessing the Endpoint for adding an Applicant");
            try
            {
                var validationResult = _applicantInfoValidator.Validate(applicant);
                if (!validationResult.IsValid)
                {
                    _logger.LogInformation("Register Endpoint called with invalid parameters");
                    return(BadRequest(new ResponseModel(400, "Object contain one or more validation Errors", validationResult.Errors)));
                }
                var applicatToRegister = _mapper.Map <Applicant>(applicant);
                var applicationStatus  = await _appRepository.AddApplicant(applicatToRegister);

                if (applicationStatus > 0)
                {
                    _logger.LogInformation("Successful Registration call was made");
                    return(Created("add", new ResponseModel(201, "Success", applicatToRegister)));
                }
                _logger.LogInformation("Add applicant call was not successful");
                return(BadRequest(new ResponseModel(400, "Failed", applicatToRegister)));
            }
            catch (Exception ex)
            {
                _logger.LogInformation("An Error occured in the Register endpoint", ex);
                return(BadRequest(new ResponseModel(400, "Some Error occuredl!!! Please Try again", null)));
            }
        }
        public void AddApplicant(Applicant applicant)
        {
            Applicant appliee = new Applicant();

            appliee = applicant;
            _applicationRepository.AddApplicant(appliee);
        }
Esempio n. 5
0
        public ActionResult Create([Bind(Include = "ApplicantId,ApellidoParterno,ApellidoMaterno,Nombre,FechaNacimiento,Nacionalidad,Rfc,Curp")] Applicant applicant)
        {
            if (ModelState.IsValid)
            {
                _repository.AddApplicant(applicant);
                return(RedirectToAction("Index"));
            }

            return(View(applicant));
        }
Esempio n. 6
0
        public async Task <IActionResult> AddApplicant([FromBody] ApplicantResource ApplicantResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var ApplicantToAdd = _mapper.Map <ApplicantResource, Applicants>(ApplicantResource);

            _repo.AddApplicant(ApplicantToAdd);
            await _unitofwork.CompleteAsync();

            return(StatusCode(201));
        }
        public async Task <ActionResult <Applicant> > CreateApplicant(Applicant applicant)
        {
            try
            {
                if (applicant == null)
                {
                    return(BadRequest());
                }

                var createdApplicant = await applicantRepository.AddApplicant(applicant);

                return(CreatedAtAction(nameof(GetApplicant), new { id = createdApplicant.ID }, createdApplicant));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Accessing database error!"));
            }
        }
 public ActionResult <ApplicantDTO> Add([FromBody] ApplicantDTO dto)
 {
     if (ModelState.IsValid)
     {
         try
         {
             dto = _repo.AddApplicant(dto);
             _logger.LogInformation($"Applicant record inserted successfully with name {dto.Name} ");
             return(CreatedAtRoute("Get", new { id = dto.Id }, dto));
         }
         catch (Exception ex)
         {
             _logger.LogInformation($"Failed to insert record with name {dto.Name}, Error {ex.Message}");
             return(BadRequest(ex));
         }
     }
     else
     {
         StringBuilder errors = Errors();
         _logger.LogInformation($"Validation errors for record with name {dto.Name} erros : {errors} ");
         return(BadRequest(errors));
     }
 }
Esempio n. 9
0
        private static void CreateApplicant()
        {
            var applicant = new Applicant(Guid.NewGuid(), true, BloodType.ABn);

            _applicantRepository.AddApplicant(applicant);
        }
Esempio n. 10
0
 public void AddApplicant(ApplicantDto applicantDto)
 {
     _applicantRepository.AddApplicant(_mapper.Map <ApplicantDto, Applicant>(applicantDto));
 }