Example #1
0
        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;
        }
Example #2
0
 public async Task <IActionResult> AddUserToEvent(UserInEventDTO newUserInEvent)
 {
     return(Ok(await _userInEvent.AddUserToEvent(newUserInEvent)));
 }