public async Task <Participant> CreateAsync(Participant dto, ApplicationUser user, Action <string, string> AddErrorMessage) { if (user == null) { AddErrorMessage?.Invoke("General", "Only Logged-in user can perform this operation"); return(null); } ParticipantEntity entity = _mappingService.DtoToEntity(dto); Chatroom chatroom = await _chatroomService.GetAsync(entity.ChatroomID); if (user.Id != chatroom.OwnerID) { AddErrorMessage?.Invoke("General", "Only Owner of a Chatroom can add participants!"); return(null); } ParticipantEntity createdEntity = await _repository.CreateAsync(entity); if (createdEntity != null) { await _context.SaveChangesAsync(); } createdEntity = await _repository.GetCompleteAsync(createdEntity.ID); Participant created = _mappingService.EntityToDto(createdEntity); created.Deletable = true; return(created); }
public async Task CreateParticipant(Guid id, string text1, int text2) { var participant = new Participant() { Id = id, Name = text1, Age = text2 }; await m_repository.CreateAsync(participant); }
public async Task <Participant> CreateAsync(Participant participant) { //auto assign participant.Id = Guid.NewGuid(); participant.Date = DateTime.UtcNow; var entity = await _participantRepository.CreateAsync(participant); if (entity == null) { throw new ParticipantNotCreatedException(); } return(entity); }