public async Task <IActionResult> GetCountriesLookup() { Log.Information("Calling get countries lookup api"); List <KeyValuePair <string, string> > countries = await _countryDataService.GetCountries(); DataGenericResponse <List <KeyValuePair <string, string> > > response = new DataGenericResponse <List <KeyValuePair <string, string> > > { Success = true, Data = countries }; if (response != null) { throw new NotImplementedException("Not implemented"); } Log.Information("Request completed"); return(new OkObjectResult(response)); }
public IActionResult Update([FromBody] UpdateApplicantViewModel request) { Log.Information("Calling update applicant api"); UpdateApplicantViewModelValidator validator = new UpdateApplicantViewModelValidator(_countryDataService, _applicantDataService, _configuration); Log.Information("Request is being validated"); var validationResult = validator.Validate(request); if (!validationResult.IsValid) { Log.Warning("Request is not valid"); DataGenericResponse <List <KeyValuePair <string, string> > > failureResponse = new DataGenericResponse <List <KeyValuePair <string, string> > >(); failureResponse.Success = false; failureResponse.Data = new List <KeyValuePair <string, string> >(); foreach (var error in validationResult.Errors) { failureResponse.Data.Add(new KeyValuePair <string, string>(error.PropertyName, error.ErrorMessage)); } return(new BadRequestObjectResult(failureResponse)); } Log.Information("Checking if applicant exists"); Applicant originalApplicant = _applicantDataService.Get(request.Id); if (originalApplicant == null) { Log.Warning("Applicant not found"); GenericResponse notFoundResponse = new GenericResponse() { Success = false }; return(new NotFoundObjectResult(notFoundResponse)); } Log.Information("Mapping request"); Applicant mappedApplicant = _mapper.Map <Applicant>(request); mappedApplicant.CreatedOn = originalApplicant.CreatedOn; mappedApplicant.ModifiedOn = originalApplicant.ModifiedOn; Log.Information("Updating applicant"); bool result = _applicantDataService.Update(mappedApplicant); GenericResponse response = new GenericResponse { Success = result }; Log.Information("Request completed"); return(new OkObjectResult(response)); }
public IActionResult Create([FromBody] CreateApplicantViewModel request) { Log.Information("Calling create applicant api"); CreateApplicantViewModelValidator validator = new CreateApplicantViewModelValidator(_countryDataService, _applicantDataService, _configuration); Log.Information("Request is being validated"); var validationResult = validator.Validate(request); if (!validationResult.IsValid) { Log.Warning("Request is not valid"); DataGenericResponse <List <KeyValuePair <string, string> > > failureResponse = new DataGenericResponse <List <KeyValuePair <string, string> > >(); failureResponse.Success = false; failureResponse.Data = new List <KeyValuePair <string, string> >(); foreach (var error in validationResult.Errors) { failureResponse.Data.Add(new KeyValuePair <string, string>(error.PropertyName, error.ErrorMessage)); } return(new BadRequestObjectResult(failureResponse)); } Log.Information("Mapping request to applicant model"); Applicant mappedApplicant = _mapper.Map <Applicant>(request); Log.Information("Creating new applicant"); int createdApplicantId = _applicantDataService.Create(mappedApplicant); DataGenericResponse <int> response = new DataGenericResponse <int>(); if (createdApplicantId > 0) { Log.Information("Applicant created successfully"); response.Success = true; response.Data = createdApplicantId; return(new OkObjectResult(response)); } Log.Warning("Error occured while creating applicant"); return(new OkObjectResult(new DataGenericResponse <int> { Success = false })); }
public IActionResult GetAll() { Log.Information("Calling get applicants list api"); List <Applicant> applicants = _applicantDataService.GetApplicantsList(); if (applicants == null) { Log.Warning("No applicants found"); GenericResponse failureResponse = new GenericResponse { Success = false }; return(new NotFoundObjectResult(failureResponse)); } Log.Information("Applicants found!"); Log.Information("Mapping applicants"); List <ApplicantListItem> mappedApplicants = _mapper.Map <List <ApplicantListItem> >(applicants); DataGenericResponse <List <ApplicantListItem> > response = new DataGenericResponse <List <ApplicantListItem> > { Success = true, Data = mappedApplicants }; Log.Information("Request completed"); return(new OkObjectResult(response)); }
public IActionResult Get([FromRoute(Name = "id")] int id) { Log.Information($"Calling get applicant by id api for id : {id}"); Applicant applicant = _applicantDataService.Get(id); if (applicant == null) { Log.Warning($"Applicant with id : {id} cannot be found"); GenericResponse failureResponse = new GenericResponse { Success = false }; return(new NotFoundObjectResult(failureResponse)); } Log.Information("Applicant found"); ApplicantViewModel mappedApplicant = _mapper.Map <ApplicantViewModel>(applicant); Log.Information("Applicant mapped"); DataGenericResponse <ApplicantViewModel> response = new DataGenericResponse <ApplicantViewModel> { Success = true, Data = mappedApplicant }; Log.Information("Request completed"); return(new OkObjectResult(response)); }