Example #1
0
        public async Task <IActionResult> AttendHappening(Guid happeningId, string userId)
        {
            if (happeningId == Guid.Empty)
            {
                return(BadRequest(nameof(happeningId)));
            }
            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest(nameof(userId)));
            }

            var user = await _userRepository.GetUserByFacebookId(userId);

            if (user == null)
            {
                return(NotFound("User not found"));
            }

            var attendingUser = new AttendingUser
            {
                FacebookId = user.FacebookId,
                FirstName  = user.FirstName
            };

            var result = await _happeningRepository.AddUserToHappening(happeningId, attendingUser);

            if (result == null)
            {
                return(StatusCode(500));
            }

            return(Ok());
        }
Example #2
0
        public async Task <Happening> AddUserToHappening(Guid happeningId, AttendingUser user)
        {
            if (happeningId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(happeningId));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var update = Builders <Happening> .Update.Push("Attendings", user);

            var result = await _context.Happenings.FindOneAndUpdateAsync(h => h.Id == happeningId, update);

            return(result);
        }