Beispiel #1
0
        public AddHouseholdResponse AddHousehold([FromBody] AddHouseholdRequest request)
        {
            var response = new AddHouseholdResponse();

            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 = _houseRepository.AddHousehold(request.Name, 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);
        }
Beispiel #2
0
        public CommunicationResponse UpdateHousehold([FromBody] UpdateHouseholdRequest request)
        {
            var response = new AddHouseholdResponse();

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

                UpdateHousehold updateHousehold = new UpdateHousehold
                {
                    Id   = request.Id,
                    Name = request.Name
                };
                bool rowUpdated = _houseRepository.UpdateHousehold(updateHousehold);

                if (rowUpdated == false)
                {
                    response.AddError("The given House Id does not correspond to an existing Household");
                    return(response);
                }
            }
            catch (ErrorCodeException exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", exception.Code);
            }
            catch (Exception exception)
            {
                response.AddError($"An unexpected exception occured: {exception}");
            }

            return(response);
        }