public async Task <IActionResult> Create([FromBody] Applicant Applicant) { _logger.LogDebug("Starting save"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // var deficiencies = new List<Deficiency>(); // deficiencies.Add(new Deficiency { // CategoryDeficiency = new CategoryDeficiency { Category = new Category { Name = "Test Category 1", Area = new Area { Name = "Test Area 1" } } } // }); _applicantRepository.Add( new Applicant { Id = new Random().Next(), LastName = Applicant.LastName, //Deficiencies = deficiencies }); await _applicantRepository.SaveChangesAsync(); _logger.LogDebug("Finished save"); return(CreatedAtAction(nameof(Get), new { id = Applicant.LastName }, Applicant)); }
public async Task <ApplicantGet> Add(ApplicantAdd applicantAdd) { ApplicantAddValidator applicantAddValidator = new ApplicantAddValidator(_restCountryClient); ValidationResult results = await applicantAddValidator.ValidateAsync(applicantAdd); if (!results.IsValid) { foreach (var failure in results.Errors) { throw new Exception("Property " + failure.PropertyName + " failed validation. Error was: " + failure.ErrorMessage); } } try { Applicant applicant = await _applicantRepository.Add(_mapper.Map <Applicant>(applicantAdd)); return(_mapper.Map <ApplicantGet>(applicant)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool Add(Applicant item) { if (_applicantRepository.GetSingleById(item.Id) == null && !_applicantRepository.Exists(m => m.Name.Trim().ToUpper() == item.Name.ToUpper())) { item.CreatedDate = DateTime.Now; _applicantRepository.Add(item); } return(true); }
public void PostApplicants([FromBody] string[] files) { var data = new List <Applicant>(); foreach (var file in files) { data.AddRange(_serializer.Deserialize(file, _builder)); } _repository.Add(data); }
public async Task <(ApplicantViewModel applicantViewModel, string errorMessage)> Add(ApplicantViewModel applicantViewModel) { if (await _applicantRepository.IsEmailExist(applicantViewModel.EmailAddress, null)) { return(null, Resource.Error_EmailDuplicated); } var addedApplicantViewModel = await _applicantRepository.Add(applicantViewModel); return(addedApplicantViewModel, string.Empty); }
public Applicant Add(Applicant entity) { try { return(_applicantRepository.Add(entity).Result); } catch (Exception e) { throw; } }
public async Task <int> CreateApplicant(CreateApplicantCommand command) { var applicant = new Applicant.ApplicantBuilder(_countryService) .WithName(command.Name) .WithFamily(command.Family) .WithAddress(command.Address) .WithCountryOfOrigin(command.CountryOfOrigin) .WithEmailAddress(command.EmailAddress) .WithAge(command.Age) .WithHired(command.Hired) .Build(); return(await _applicantRepository.Add(applicant)); }
public ApplicantModel Add(ApplicantModel model) { var entity = new Applicant() { Name = model.Name, FamilyName = model.FamilyName, Address = model.Address, CountryOfOrigin = model.CountryOfOrigin, EMailAddress = model.EMailAddress, Age = model.Age, Hired = model.Hired }; var result = _repository.Add(entity); model.ID = result.ID; return(model); }
public async Task <int> Add(Applicant applicant) { var validator = new ApplicantValidator(); ValidationResult result = validator.Validate(applicant); if (result.IsValid) { return(await _repository.Add(applicant)); } var exceptionMessage = String.Join(",", result.Errors.Select(x => $"{x.ErrorMessage}").ToArray()); _logger.LogError(exceptionMessage); throw new Exception(exceptionMessage); }
public void Create(Applicant applicant) { if (applicant == null) { throw new ValidationFailedException (new[] { $"{nameof(applicant)} is null or empty" }); } if (!validator.Validate(applicant, out IEnumerable <string> errors)) { throw new ValidationFailedException(errors); } var present = repo.Get(applicant.ID) != null; if (present) { throw new ApplicantAlreadyExistsException(applicant); } repo.Add(applicant); }
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)); }