public async Task <Result> Handle(RegisterCandidateCommand request, CancellationToken cancellationToken) { var candidateName = new CandidateName(request.FirstName, request.LastName); _repo.Add(new Domain.Entities.Candidate(candidateName, request.Birthday, request.CurrentPosition, request.Note)); await _repo.UnitOfWork.SaveEntitiesAsync(); return(Result.Ok()); }
public Candidate(CandidateName name, DateTime?birthday, string currentPosition, string note) : this() { if (!string.IsNullOrWhiteSpace(currentPosition) && currentPosition.Length > CURRENT_POSITION_LEN) { throw new ArgumentOutOfRangeException(nameof(currentPosition), $"Should not be more than {CURRENT_POSITION_LEN}"); } if (!string.IsNullOrWhiteSpace(note) && note.Length > NOTE_LEN) { throw new ArgumentOutOfRangeException(nameof(note), $"Should not be more than {NOTE_LEN}"); } CandidateName = name; Birthday = birthday; CurrentPosition = currentPosition; Note = note; }
public async Task <Result> Handle(UpdateCandidateCommand request, CancellationToken cancellationToken) { var dbCandidate = await _repo.Get(request.Id); if (dbCandidate == null) { return(Result.Failure("Candidate not found!")); } var candidateName = new CandidateName(request.FirstName, request.LastName); dbCandidate.UpdateName(candidateName); dbCandidate.UpdateBirthday(request.Birthday); dbCandidate.UpdateCurrentPosition(request.CurrentPosition); dbCandidate.UpdateNote(request.Note); _repo.Update(dbCandidate); await _repo.UnitOfWork.SaveEntitiesAsync(); return(Result.Ok()); }
public void UpdateName(CandidateName name) { CandidateName = name; }
/// <inheritdoc /> public bool Includes(CandidateName candidate) { var length = Guard.NotNull(candidate, nameof(candidate)).Name.Length; return(length >= MinLength && length <= MaxLength); }
/// <inheritdoc /> public bool Includes(CandidateName candidate) { Guard.NotNull(candidate, nameof(candidate)); return(Allowed.IndexOf(candidate.First) != -1); }