示例#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 JoinHouseholdResponse JoinHousehold(string inviteLink)
        {
            JoinHouseholdRequest request = new JoinHouseholdRequest
            {
                InviteLink = inviteLink
            };
            var requestBody     = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
            var response        = _fakeServer.PostAsync("/Api/v2/Household/InviteLink", requestBody).Result;
            var responseContent = response.Content.ReadAsStringAsync().Result;

            return(JsonConvert.DeserializeObject <JoinHouseholdResponse>(responseContent));
        }