public async Task <IActionResult> PutAsync(int id, [FromBody] ApplicantInputModel input)
        {
            _logger.LogInformation("PUT applicants/" + id);
            SetRepoEndpoint();

            var validation = await new ApplicantValidator(_countryService).ValidateAsync(input);

            if (!validation.IsValid)
            {
                _logger.LogWarning("BadRequest");
                return(BadRequest(validation));
            }

            var model = await _repo.GetSingleByIdAsync(id, HttpContext.RequestAborted, trackChanges : true);

            if (model == null)
            {
                return(NotFound());
            }

            model.UpdateFromModel(input);
            await _repo.SaveUnitOfWorkAsync(HttpContext.RequestAborted);

            return(Ok(model.GetViewModel(_repo.BaseEndpointUrl)));
        }
        /// <summary>
        /// Creates a new instance of the object
        /// </summary>
        /// <param name="model">Object containing input data</param>
        public Applicant(ApplicantInputModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            UpdateFromModel(model);
        }
 /// <summary>
 /// Updates the current instance using the given model.
 /// </summary>
 /// <param name="model">Object with the applicant input data</param>
 public void UpdateFromModel(ApplicantInputModel model)
 {
     Name            = model.Name;
     FamilyName      = model.FamilyName;
     Address         = model.Address;
     Age             = model.Age;
     CountryOfOrigin = model.CountryOfOrigin;
     EmailAddress    = model.EmailAddress;
     Hired           = model.Hired;
 }
        public async Task <IActionResult> CreateAsync([FromBody] ApplicantInputModel model)
        {
            _logger.LogInformation("POST applicants");
            SetRepoEndpoint();

            var validation = await new ApplicantValidator(_countryService).ValidateAsync(model);

            if (!validation.IsValid)
            {
                _logger.LogWarning("BadRequest");
                return(BadRequest(validation));
            }

            var applicant = new Applicant(model);

            _repo.Add(applicant);
            await _repo.SaveUnitOfWorkAsync(HttpContext.RequestAborted);

            var result   = applicant.GetViewModel(_repo.BaseEndpointUrl);
            var location = result.Links.First(l => l.Action == "GET");

            return(Created(location.Href, result));
        }