public async Task<ApplicantResponseMessage> AddApplicant(ApplicantResource resource) { try { var validation = new SaveApplicantResourceValidator(); var validationResult = validation.Validate(resource); if (!validationResult.IsValid) { return new ApplicantResponseMessage { Errors = validationResult.Errors }; } var applicant = new Applicant(); applicant.Name = resource.Name; applicant.Address = resource.Address; applicant.Age = resource.Age; applicant.CountryOfOrigin = resource.CountryOfOrigin; applicant.EMailAdress = resource.EMailAdress; applicant.FamilyName = resource.FamilyName; applicant.Hired = resource.Hired; await _unitOfWork.Applicant.SaveAsync(applicant); return new ApplicantResponseMessage { ResponseMessage = "Successfully Saved" }; } catch(Exception ex) { _logger.LogInformation(ex.Message); throw ex; } }
public async Task<ApplicantResponseMessage> UpdateApplicant(string id, ApplicantResource resource) { try { var validation = new SaveApplicantResourceValidator(); var findId = await GetApplicantById(id); if (findId != null) { var validationResult = validation.Validate(resource); if (!validationResult.IsValid) { return new ApplicantResponseMessage { Errors = validationResult.Errors }; } //var applicant = new Applicant(); findId.Name = resource.Name; findId.Address = resource.Address; findId.Age = resource.Age; findId.CountryOfOrigin = resource.CountryOfOrigin; findId.EMailAdress = resource.EMailAdress; findId.FamilyName = resource.FamilyName; findId.Hired = resource.Hired; await _unitOfWork.Applicant.UpdateAsync(findId); return new ApplicantResponseMessage { ResponseMessage = "Successfully Updated" }; } else { return new ApplicantResponseMessage { ResponseMessage = "Entity To Update Can Not Be Found" }; } } catch (Exception ex) { _logger.LogInformation(ex.Message); throw ex; } }