Example #1
0
        public async Task <GetSessionResponse> GetSession(GetSessionRequest request)
        {
            var response = new GetSessionResponse();

            using (var uow = _uowFactory.GetUnitOfWork())
            {
                var session = await uow.SessionRepo.GetSessionById(new Repositories.DatabaseRepos.SessionRepo.Models.GetSessionByIdRequest()
                {
                    Id = request.Id
                });

                if (session == null)
                {
                    response.Notifications.AddError($"Could not find session with Id {request.Id}");
                    return(response);
                }

                if (session.User_Id.HasValue)
                {
                    var user = await uow.UserRepo.GetUserById(new Repositories.DatabaseRepos.UserRepo.Models.GetUserByIdRequest()
                    {
                        Id = session.User_Id.Value
                    });

                    response.User = user;
                }

                response.Session = session;

                uow.Commit();
                return(response);
            }
        }
Example #2
0
        public GetSessionResponse GetSession(GetSessionRequest getSessionRequest)
        {
            Log(Logger.LogMessageType.Info, "->   -------------------- Comienza la ejecución del método Registration.GetSession", Logger.LoggingLevelType.Medium);
            GetSessionResponse response = null;

            try
            {
                Log(Logger.LogMessageType.Info, String.Format("Llamando a AgentRegistration.Login con los parametros: User={0}, DeviceType={1}", getSessionRequest.Request.User, getSessionRequest.Request.DeviceType), Logger.LoggingLevelType.Low);
                LoginResponseInternal loginResponse = AuthenticationProvider.LoginInternal(new LoginRequestInternal()
                {
                    DeviceType = getSessionRequest.Request.DeviceType,
                    Password   = getSessionRequest.Request.Password,
                    User       = getSessionRequest.Request.User
                });
                response = new GetSessionResponse()
                {
                    Response = new GetSessionResponseBody()
                    {
                        ResponseCode    = loginResponse.ResponseCode,
                        ResponseMessage = loginResponse.ResponseMessage,
                        SessionID       = loginResponse.SessionID,
                        TransactionID   = loginResponse.TransactionID
                    }
                };
                Log(Logger.LogMessageType.Info, String.Format("Parametros de respuesta de AgentRegistration.Login: LoginResult={0}, Message={1} ", response.Response.ResponseCode, response.Response.ResponseMessage), Logger.LoggingLevelType.Low);
            }
            catch (Exception e)
            {
                Log(Logger.LogMessageType.Error, "Excepcion en el metodo Registration.Login: "******"->   -------------------- Termina la ejecución del método Registration.Login", Logger.LoggingLevelType.Medium);
            return(response);
        }
Example #3
0
        public async Task <GetSessionResponse> GetSession(GetSessionRequest request)
        {
            var response = new GetSessionResponse();

            using (var uow = _uowFactory.GetUnitOfWork())
            {
                var session = await uow.SessionRepo.GetSessionById(new Infrastructure.Repositories.SessionRepo.Models.GetSessionByIdRequest()
                {
                    Id = request.Id
                });

                if (session == null)
                {
                    response.Notifications.AddError($"Could not find session with Id {request.Id}");
                    return(response);
                }

                var logs = await uow.SessionRepo.GetSessionLogsBySessionId(new Infrastructure.Repositories.SessionRepo.Models.GetSessionLogsBySessionIdRequest()
                {
                    Session_Id = request.Id
                });

                var logEvents = await uow.SessionRepo.GetSessionLogEventsBySessionId(new Infrastructure.Repositories.SessionRepo.Models.GetSessionLogEventsBySessionIdRequest()
                {
                    Session_Id = request.Id
                });

                if (session.User_Id.HasValue)
                {
                    var user = await uow.UserRepo.GetUserById(new Infrastructure.Repositories.UserRepo.Models.GetUserByIdRequest()
                    {
                        Id = session.User_Id.Value
                    });

                    response.User = user;
                }

                var eventsLookup = await _cache.SessionEvents();

                response.Session = session;
                response.Logs    = logs.Select(l =>
                {
                    var eventIds = logEvents.Where(le => le.Session_Log_Id == l.Id).Select(le => le.Event_Id);
                    return(new SessionLog()
                    {
                        Entity = l,
                        Events = eventsLookup.Where(e => eventIds.Contains(e.Id)).Select(e => new SessionLogEvent()
                        {
                            Event = e,
                            Message = logEvents.FirstOrDefault(le => le.Event_Id == e.Id).Message
                        }).ToList()
                    });
                }).ToList();

                uow.Commit();
                return(response);
            }
        }
        public async Task <GetSessionResponse> GetSession()
        {
            var response = new GetSessionResponse();

            // get or create a new session
            var session = await _sessionProvider.Get <SessionEntity>(SessionConstants.SessionEntity);

            if (session == null)
            {
                // flush any authenticated cookies in the event the application restarts
                await _httpContextAccessor.HttpContext.SignOutAsync();

                await _sessionProvider.Clear();

                var userAgent = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent].FirstOrDefault();

                using (var uow = _uowFactory.GetUnitOfWork())
                {
                    response.SessionEntity = await uow.SessionRepo.CreateSession(new Repositories.DatabaseRepos.SessionRepo.Models.CreateSessionRequest()
                    {
                        User_Agent = userAgent,
                        Created_By = ApplicationConstants.SystemUserId
                    });

                    uow.Commit();
                }

                await _sessionProvider.Set(SessionConstants.SessionEntity, response.SessionEntity);

                return(response);
            }
            response.SessionEntity = session;

            var sessionLogId = await _sessionProvider.Get <int?>(SessionConstants.SessionLogId);

            if (sessionLogId != null)
            {
                response.SessionLogId = sessionLogId.Value;
            }

            var isDebug = await _sessionProvider.Get <bool?>(SessionConstants.IsDebug);

            if (isDebug != null)
            {
                response.IsDebug = isDebug ?? false;
            }

            return(response);
        }
Example #5
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetSessionResponse response = new GetSessionResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Session", targetDepth))
                {
                    var unmarshaller = SessionUnmarshaller.Instance;
                    response.Session = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetSessionResponse response = new GetSessionResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("activeContexts", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <ActiveContext, ActiveContextUnmarshaller>(ActiveContextUnmarshaller.Instance);
                    response.ActiveContexts = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("dialogAction", targetDepth))
                {
                    var unmarshaller = DialogActionUnmarshaller.Instance;
                    response.DialogAction = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("recentIntentSummaryView", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <IntentSummary, IntentSummaryUnmarshaller>(IntentSummaryUnmarshaller.Instance);
                    response.RecentIntentSummaryView = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("sessionAttributes", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
                    response.SessionAttributes = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("sessionId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.SessionId = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Example #7
0
        internal static GetSessionResponse GetSession(GetSessionRequest getSessionRequest)
        {
            LoginRequestInternal loginRequest = new LoginRequestInternal()
            {
                User       = getSessionRequest.Request.User,
                Password   = getSessionRequest.Request.Password,
                DeviceType = getSessionRequest.Request.DeviceType
            };
            LoginResponseInternal  loginResponse          = AuthenticationProvider.LoginInternal(loginRequest);
            GetSessionResponse     getSessionResponse     = new GetSessionResponse();
            GetSessionResponseBody getSessionResponseBody = new GetSessionResponseBody()
            {
                ResponseCode    = loginResponse.ResponseCode,
                ResponseMessage = loginResponse.ResponseMessage,
                SessionID       = loginResponse.SessionID,
                TransactionID   = loginResponse.TransactionID
            };

            getSessionResponse.Response = getSessionResponseBody;
            return(getSessionResponse);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetSessionResponse response = new GetSessionResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("interpretations", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Interpretation, InterpretationUnmarshaller>(InterpretationUnmarshaller.Instance);
                    response.Interpretations = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("messages", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Message, MessageUnmarshaller>(MessageUnmarshaller.Instance);
                    response.Messages = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("sessionId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.SessionId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("sessionState", targetDepth))
                {
                    var unmarshaller = SessionStateUnmarshaller.Instance;
                    response.SessionStateValue = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Example #9
0
        /// <param name='customName'>
        /// </param>
        /// <param name='body'>
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="GetSessionResponseException">
        /// Thrown when the operation returned an invalid status code
        /// </exception>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <HttpOperationResponse <GetSessionResponse> > GetWithHttpMessagesAsync(string customName = default(string), UpdateSession body = default(UpdateSession), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            string accept = "application/json";
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("customName", customName);
                tracingParameters.Add("body", body);
                tracingParameters.Add("accept", accept);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
            }
            // Construct URL
            var           _baseUrl         = Client.BaseUri.AbsoluteUri;
            var           _url             = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "session/edit/{CustomName}").ToString();
            List <string> _queryParameters = new List <string>();

            if (customName != null)
            {
                _queryParameters.Add(string.Format("CustomName={0}", System.Uri.EscapeDataString(customName)));
            }
            if (_queryParameters.Count > 0)
            {
                _url += "?" + string.Join("&", _queryParameters);
            }
            // Create HTTP transport objects
            var _httpRequest = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("GET");
            _httpRequest.RequestUri = new System.Uri(_url);
            // Set Headers
            if (accept != null)
            {
                if (_httpRequest.Headers.Contains("Accept"))
                {
                    _httpRequest.Headers.Remove("Accept");
                }
                _httpRequest.Headers.TryAddWithoutValidation("Accept", accept);
            }


            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            if (body != null)
            {
                _requestContent      = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings);
                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
                _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
            }
            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if (!_httpResponse.IsSuccessStatusCode)
            {
                var ex = new GetSessionResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                try
                {
                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    GetSessionResponse _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <GetSessionResponse>(_responseContent, Client.DeserializationSettings);
                    if (_errorBody != null)
                    {
                        ex.Body = _errorBody;
                    }
                }
                catch (JsonException)
                {
                    // Ignore the exception
                }
                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new HttpOperationResponse <GetSessionResponse>();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            string _defaultResponseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            try
            {
                _result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <GetSessionResponse>(_defaultResponseContent, Client.DeserializationSettings);
            }
            catch (JsonException ex)
            {
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw new SerializationException("Unable to deserialize the response.", _defaultResponseContent, ex);
            }
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
Example #10
0
        public async Task <IActionResult> GetSession(string fromLanguage, string learningLanguage)
        {
            var session = await _api.GetSession(new GetSessionRequest()
            {
                ChallengeTypes   = new string[] { "characterIntro", "characterMatch", "characterSelect", "dialogue", "form", "judge", "listen", "name", "listenComprehension", "listenTap", "readComprehension", "select", "selectPronunciation", "selectRecording", "selectTranscription", "translate" },
                FromLanguage     = fromLanguage,
                LearningLanguage = learningLanguage,
                Type             = "GLOBAL_PRACTICE"
            });

            currentSession           = session;
            currentSession.StartTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            var sessionChallenges = (session.Challenges as JArray).ToObject <List <Challenge> >();

            var challenges = new List <SimpleChallenge>();

            foreach (var challenge in sessionChallenges)
            {
                switch (challenge.Type)
                {
                case "form":
                    challenges.Add(new SimpleChallenge()
                    {
                        Question = challenge.Metadata.correct_solutions[0], Answer = challenge.SolutionTranslation
                    });
                    break;

                case "translate":
                    challenges.Add(new SimpleChallenge()
                    {
                        Question = challenge.Prompt, Answer = challenge.CorrectSolutions[0]
                    });
                    break;

                case "judge":
                    challenges.Add(new SimpleChallenge()
                    {
                        Question = challenge.Prompt, Answer = challenge.Choices[challenge.CorrectIndices[0]].ToString()
                    });
                    break;

                case "listenTap":
                case "listen":
                    challenges.Add(new SimpleChallenge()
                    {
                        Question = challenge.Prompt, Answer = challenge.SolutionTranslation
                    });
                    break;

                case "name":
                    challenges.Add(new SimpleChallenge()
                    {
                        Question = challenge.Prompt, Answer = challenge.CorrectSolutions[0]
                    });
                    break;

                case "characterIntro":
                    challenges.Add(new SimpleChallenge()
                    {
                        Question = challenge.Prompt, Answer = challenge.Choices[challenge.Metadata["correct_option_index"]].ToString()
                    });
                    break;
                }
            }

            return(Ok(new Session()
            {
                Id = session.Id,
                Challenges = challenges.ToArray()
            }));
        }
Example #11
0
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="GetSessionResponseException">
        /// Thrown when the operation returned an invalid status code
        /// </exception>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <HttpOperationResponse <GetSessionResponse> > DeleteWithHttpMessagesAsync(Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
            }
            // Construct URL
            var _baseUrl = Client.BaseUri.AbsoluteUri;
            var _url     = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "session").ToString();
            // Create HTTP transport objects
            var _httpRequest = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("DELETE");
            _httpRequest.RequestUri = new System.Uri(_url);
            // Set Headers
            if (Client.Accept != null)
            {
                if (_httpRequest.Headers.Contains("Accept"))
                {
                    _httpRequest.Headers.Remove("Accept");
                }
                _httpRequest.Headers.TryAddWithoutValidation("Accept", Client.Accept);
            }


            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if (!_httpResponse.IsSuccessStatusCode)
            {
                var ex = new GetSessionResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                try
                {
                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    GetSessionResponse _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <GetSessionResponse>(_responseContent, Client.DeserializationSettings);
                    if (_errorBody != null)
                    {
                        ex.Body = _errorBody;
                    }
                }
                catch (JsonException)
                {
                    // Ignore the exception
                }
                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new HttpOperationResponse <GetSessionResponse>();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            string _defaultResponseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            try
            {
                _result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <GetSessionResponse>(_defaultResponseContent, Client.DeserializationSettings);
            }
            catch (JsonException ex)
            {
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw new SerializationException("Unable to deserialize the response.", _defaultResponseContent, ex);
            }
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
        public async Task <GetSessionResponse> GetSession()
        {
            var response = new GetSessionResponse();

            // get or create a new session
            var session = await _sessionProvider.Get <SessionEntity>(SessionConstants.SessionEntity);

            if (session == null)
            {
                // flush any authenticated cookies in the event the application restarts
                await _httpContextAccessor.HttpContext.SignOutAsync();

                await _sessionProvider.Remove(SessionConstants.User);

                using (var uow = _uowFactory.GetUnitOfWork())
                {
                    session = await uow.SessionRepo.CreateSession(new Infrastructure.Repositories.SessionRepo.Models.CreateSessionRequest()
                    {
                        Created_By = ApplicationConstants.SystemUserId
                    });

                    uow.Commit();

                    await _sessionProvider.Set(SessionConstants.SessionEntity, session);
                }
            }
            response.Id           = session.Id;
            response.SessionLogId = await _sessionProvider.Get <int>(SessionConstants.SessionLogId);

            // get or hydrate user from session
            var user = await _sessionProvider.Get <User>(SessionConstants.User);

            if (user == null &&
                session.User_Id.HasValue)
            {
                using (var uow = _uowFactory.GetUnitOfWork())
                {
                    user        = new User();
                    user.Entity = await uow.UserRepo.GetUserById(new Infrastructure.Repositories.UserRepo.Models.GetUserByIdRequest()
                    {
                        Id = session.User_Id.Value
                    });

                    uow.Commit();

                    var usersRoles = await _cache.UserRoles();

                    var userRoleIds = usersRoles.Where(ur => ur.User_Id == user.Entity.Id).Select(ur => ur.Role_Id);

                    var rolePermissions = await _cache.RolePermissions();

                    var userRolePermissionIds = rolePermissions.Where(rc => userRoleIds.Contains(rc.Role_Id)).Select(rc => rc.Permission_Id);

                    var permissionsLookup = await _cache.Permissions();

                    var userPermissionsData = permissionsLookup.Where(c => userRolePermissionIds.Contains(c.Id));

                    var rolesLookup = await _cache.Roles();

                    var userRolesData = rolesLookup.Where(r => userRoleIds.Contains(r.Id));

                    foreach (var userPermission in userPermissionsData)
                    {
                        user.PermissionKeys.Add(userPermission.Key);
                    }

                    foreach (var userRole in userRolesData)
                    {
                        user.RoleIds.Add(userRole.Id);
                    }

                    await _sessionProvider.Set(SessionConstants.User, user);
                }
            }
            response.User = user;

            return(response);
        }