コード例 #1
0
        public JoinHouseholdResponse JoinHouseholdWithInviteLink([FromBody] JoinHouseholdRequest request)
        {
            var response = new JoinHouseholdResponse();

            try
            {
                if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false)
                {
                    response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID);
                    return(response);
                }

                string     sessionId = Request.Headers["Authorization"].ToString();
                ActiveUser user      = _userService.GetUserInformationFromAuthHeader(sessionId);

                response.Id = _inviteLinkService.GetHouseholdForInviteLink(request.InviteLink);
                _houseRepository.AddPersonToHousehold(response.Id, user.PersonId);
                _userService.UpdateHouseholdForUser(sessionId, response.Id);
            }
            catch (ErrorCodeException exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", exception.Code);
            }
            catch (Exception exception)
            {
                response.AddError($"An unexpected exception occured: {exception}");
            }

            return(response);
        }
コード例 #2
0
        public void Initialize()
        {
            _accountHelper = new RealAccountHelper();
            Guid firstUserSession = _accountHelper.GenerateValidCredentials();

            _endpointHelper = new EndpointHelper();
            CreateHouseholdInviteLinkResponse inviteLinkResponse = _endpointHelper.Setup()
                                                                   .SetAuthenticationToken(firstUserSession.ToString())
                                                                   .AddHousehold(typeof(WhenTheRequestIsValid).Name)
                                                                   .CreateHouseholdInviteLink()
                                                                   .ReturnHouseholdLink();

            Guid secondUserSession = _accountHelper.GenerateValidCredentials();

            _endpointHelper.Setup().SetAuthenticationToken(secondUserSession.ToString());

            _joinHouseholdResponse = _endpointHelper.JoinHousehold(inviteLinkResponse.InviteLink);
        }