Пример #1
0
        public UserSessionPetCareResponse UpdatePetMetrics(int userId, int petId, int interactionId)
        {
            var userSessionState = _state.GetUserSession(userId);

            if (userSessionState == null)
            {
                var errorResponse = new UserSessionPetCareResponse();
                return(errorResponse.SetErrorResponse(new ErrorMessage(ErrorCode.UserSessionNotFound)));
            }

            var payload = new UserPetCareAction()
            {
                UserId        = userId,
                PetId         = petId,
                InteractionId = interactionId
            };

            var sessionRequest = new UserSessionRequest <IUserSessionData>()
            {
                Payload     = payload,
                RequestType = RequestType.Update,
                UserId      = userId
            };

            IResponse response;

            userSessionState.ProcessRequest(sessionRequest, out response);
            return((UserSessionPetCareResponse)response);
        }
        private bool TryPersistRecordUpdate(IUserSessionData processedData, out IResponse response)
        {
            if (processedData is PetVital)
            {
                var          petCareResponse = new UserSessionPetCareResponse();
                var          petMetric       = (processedData as PetVital).ToPetMetricModel();
                ErrorMessage error;
                if (!_petMetricPersister.TryPersistUpdate(petMetric, out error))
                {
                    response = petCareResponse.SetErrorResponse(error);
                    return(false);
                }

                response = petCareResponse.SetSuccessResponse(processedData as PetVital);
                return(true);
            }

            var genericError = new ErrorMessage(ErrorCode.RequestDataNotRecognised);

            response = new UserSessionResponse().SetErrorResponse(genericError);
            return(false);
        }