Example #1
0
 public ApiHelper(string domain, string currentAccount)
 {
     try
     {
         var multiRegionHostedSolution = new MultiRegionHostedSolution("teamlabsite");
         Tenant = multiRegionHostedSolution.GetTenant(domain);
         CoreContext.TenantManager.SetCurrentTenant(Tenant);
         CurrentAccountId = !string.IsNullOrEmpty(currentAccount) ? new Guid(currentAccount) : Tenant.OwnerId;
         ApiClient = new ApiClient(Tenant.GetTenantDomain());
         Cookie = multiRegionHostedSolution.CreateAuthenticationCookie(Tenant.HostedRegion, Tenant.TenantId, CurrentAccountId);
         SecurityContext.AuthenticateMe(Cookie);
     }
     catch (Exception e)
     {
         Log.ErrorFormat("ApiHelper: StackTrace:{0}, Message: {1}", e.StackTrace, e.Message);
     }
 }
Example #2
0
        private void ChangeApiStatus(int status, string userId)
        {
            try
            {
                var userAccount = GetUserAccount();
                if (userAccount == null) return;

                var tenant = CoreContext.TenantManager.GetTenant(userAccount.Tenant);
                var cookie = (string)Context.Request.Environment["server.UserCookie"];

                var apiClient = new ApiClient(tenant.GetTenantDomain());
                var request = new ApiRequest(string.Format("crm/voip/opers/{0}", userId), cookie)
                    {
                        Method = HttpMethod.Put
                    };
                request.Parameters.Add(new RequestParameter {Name = "status", Value = status});
                apiClient.GetResponse(request);
            }
            catch(ApiErrorException e)
            {
                Log.ErrorFormat("ChangeApiStatus userId: {0}, ErrorStackTrace: {1}, ErrorMessage:{2}", userId, e.ErrorStackTrace, e.ErrorMessage);
                throw;
            }
            catch(Exception e)
            {
                Log.Error("ChangeApiStatus userId:" + userId, e);
                throw;
            }
        }
Example #3
0
        private void SaveCall(string callId, string answeredBy, int status)
        {
            var userAccount = GetUserAccount();
            if (userAccount == null) return;

            var tenant = CoreContext.TenantManager.GetTenant(userAccount.Tenant);
            var cookie = (string)Context.Request.Environment["server.UserCookie"];

            var apiClient = new ApiClient(tenant.GetTenantDomain());
            var request = new ApiRequest(string.Format("crm/voip/call/{0}", callId), cookie)
                {
                    Method = HttpMethod.Post,
                    ResponseType = ResponseType.Json
                };

            request.Parameters.Add(new RequestParameter {Name = "answeredBy", Value = answeredBy});
            request.Parameters.Add(new RequestParameter {Name = "status", Value = status});

            apiClient.GetResponse(request);
        }
Example #4
0
        private string GetCall(string callId)
        {
            var userAccount = GetUserAccount();
            if (userAccount == null) return null;

            var tenant = CoreContext.TenantManager.GetTenant(userAccount.Tenant);
            var cookie = (string)Context.Request.Environment["server.UserCookie"];

            var apiClient = new ApiClient(tenant.GetTenantDomain());
            var request = new ApiRequest(string.Format("crm/voip/call/{0}", callId), cookie)
                {
                    Method = HttpMethod.Get,
                    ResponseType = ResponseType.Json
                };

            return apiClient.GetResponse(request).Response;
        }