Exemplo n.º 1
0
        public async Task <BaseResponse> GetUserSession(int PartnerId, int CpartyId, int TerminalId)
        {
            AvihangUserSessions avihangUserSessions = new AvihangUserSessions();
            AvihangUserInfo     avihangUserInfo     = new AvihangUserInfo();
            BaseResponse        baseResponse        = new BaseResponse();

            avihangUserSessions = _avihangUserSessionsRepository.GetByPartnerIdAndCpartyId(PartnerId, CpartyId).Result;
            if (getSessionState(avihangUserSessions) != Framework.Utility.SessionState.Ok)
            {
                var    providers    = _providersRepository.GetById((int)ProviderType.Avihang).Result;
                var    providerApis = _providerApisRepository.GetByProviderId((int)ProviderType.Avihang).Result;
                string ApiUrl       = providerApis.Where(a => a.Id == (int)AvihangApis.InternalUserSession).FirstOrDefault().Url;
                string Uri          = $"{(providers.BaseUrl.EndsWith("/") ? providers.BaseUrl : providers.BaseUrl + "/")}{(ApiUrl.StartsWith("/") ? ApiUrl.Remove(0, 1) : ApiUrl)}";
                Header header       = new Header(Uri, 1, "application/json");
                header.token           = _avihangTokensService.GetToken(TerminalId).Result.Token;
                header.clientAgentInfo = "172.16.2.9";
                header.clientIPAddress = "172.16.2.9";
                header.terminalId      = TerminalId;
                UserSessionRequest userSessionRequest = new UserSessionRequest(PartnerId, CpartyId);
                var preResponse = _factory.GetChannel().CallWebApi <BaseApiHeader, UserSessionRequest>(header, userSessionRequest);
                avihangUserSessions         = new AvihangUserSessions();
                avihangUserSessions.ResDate = DateTime.Now;
                baseResponse = Utilities.JsonTextToModel <BaseResponse>(preResponse.Content);
                baseResponse.CopyPropertiesTo(avihangUserSessions);
                baseResponse.info.CopyPropertiesTo(avihangUserSessions);
                baseResponse.info.CopyPropertiesTo(avihangUserInfo);
                await _avihangUserInfoRepository.Insert(avihangUserInfo);

                avihangUserSessions.AvihangUserInfoId = avihangUserInfo.Id;
                await _avihangUserSessionsRepository.Add(avihangUserSessions);

                await _avihangUserSessionsRepository.CommitAsync();
            }
            return(baseResponse);
        }