public async Task <ParticipantDTO> CreateParticipant(CreateParticipantModel participant) { var newParticipant = new Participant(Guid.NewGuid(), participant.Name); await _participantRepository.AddAsync(newParticipant); return(_mapper.Map <ParticipantDTO>(newParticipant)); }
public async Task <Participant> ExecuteAsync(string firstName, string lastName) { var newParticipant = _factory.NewParticipant(new FullName(firstName, lastName)); await _participantRepository.AddAsync(newParticipant); await _unitOfWork.SaveAsync(); return(newParticipant); }
public async Task <Guid> Handle(CreateParticipantCommand request, CancellationToken cancellationToken) { var validator = new CreateParticipantCommandValidator(_participantRepository); var validationResult = await validator.ValidateAsync(request); if (validationResult.Errors.Count > 0) { throw new Exceptions.ValidationException(validationResult); } var item = _mapper.Map <Participant>(request); item = await _participantRepository.AddAsync(item); return(item.Id); }
public async Task CreateAsync(Guid userId) { var user = await _userRepository.GetAsync(userId); if (user == null) { throw new Exception($"User with user id: '{userId}' can not be found."); } var participant = await _participantRepository.GetAsync(userId); if (participant != null) { throw new Exception($"Leader with user id: '{userId}' already exists."); } participant = new Participant(user); await _participantRepository.AddAsync(participant); }
public async Task <ParticipantResponse> SaveAsync(Participant Participant) { //var existingCategory = await _categoryRepository.FindByIdAsync(id); //if (existingCategory == null) // return new CategoryResponse("Category not found."); try { await _participantRepository.AddAsync(Participant); await _unitOfWork.CompleteAsync(); return(new ParticipantResponse(Participant)); } catch (Exception ex) { // Do some logging stuff return(new ParticipantResponse($"An error occurred when saving the Participant: {ex.Message}")); } }