public async Task<UserInEventDTO> AddUserToEvent(UserInEventDTO userInEvent) { User user = await _dbContext.Users .Include(u => u.UserInEvents).ThenInclude(ue => ue.Event) .FirstOrDefaultAsync(u => u.Id == userInEvent.UserId); Event evt = await _dbContext.Events .FirstOrDefaultAsync(e => e.Id == userInEvent.EventId); UserInEvent newUserInEvent = new UserInEvent { Event = evt, User = user }; await _dbContext.UserInEvents.AddAsync(newUserInEvent); await _dbContext.SaveChangesAsync(); return userInEvent; }
public async Task <IActionResult> AddUserToEvent(UserInEventDTO newUserInEvent) { return(Ok(await _userInEvent.AddUserToEvent(newUserInEvent))); }