コード例 #1
0
        public async Task <IActionResult> List()
        {
            try
            {
                var loggedInUserId  = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;
                var userInvitations = await _planInvitationRepository.List(new Guid(loggedInUserId));

                return(Ok(userInvitations));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
コード例 #2
0
        public async Task <IEnumerable <PlanInvitationDto> > List(Guid loggedInUserId)
        {
            try
            {
                //validate user
                var currUser = await _userRepository.GetUserAsync(loggedInUserId);

                if (currUser == null)
                {
                    //log here
                    throw new UserNotFoundException("User to add does not exist");
                }
                var userInvitations = await _planInvitationRepository.List(loggedInUserId);

                if (userInvitations == null)
                {
                    return(new List <PlanInvitationDto>());
                }

                //get the inviters username
                foreach (var inv in userInvitations)
                {
                    var inviterUser = await _userRepository.GetUserAsync(inv.InvitedById);

                    if (inviterUser == null)
                    {
                        userInvitations.Remove(inv);
                    }
                    inv.InviterUsername = inviterUser.UserName;
                }
                return(userInvitations);
            }
            catch (Exception)
            {
                throw;
            }
        }