Esempio n. 1
0
        public ActionResult <string> Post([FromBody, SwaggerRequestBody(_description4swaggerCreateApplicant, Required = true)] Applicant applicant)
        {
            //if (ModelState.IsValid)  has become unnecessary. that logic is now applied automatically, ie BadRequest with added errors is called
            try {
                var createdApplicantId = _applicantManager.AddApplicant(applicant);                 // createdApplicant can not be null, so no null-checking
                _logger.LogInformation($"An applicant with ID: {createdApplicantId} has been created in the database!");

                //var request = HttpContext.Request;
                //var uri = $"{request.Host.Value}{request.Path.Value}/{createdApplicantId}";
                return(createdApplicantId.ToString());
            } catch (Exception) {
                _logger.LogError("An error occurred while trying to create a new entry. New applicant is not saved to the database.");
            }
            return(BadRequest());
        }