private static OrganizationServiceProxy GetProxyService()
        {
            IServiceManagement <IDiscoveryService>    serviceManagement    = DynamicsCrmService.GetDiscoveryService("http://10.10.30.6:5555");
            IServiceManagement <IOrganizationService> orgServiceManagement = DynamicsCrmService.GetOrganisationService("http://10.10.30.6:5555", "crm-epm");
            AuthenticationCredentials authenticationCredentials            = GetCredentials(serviceManagement.AuthenticationType, "CRM-001", "Energy4321!", "ENOMOS");

            return(GetProxy <IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, authenticationCredentials));
        }
        public CrmAccount GetAccountById(Guid crmAccountId)
        {
            CrmAccount crmAccount = new CrmAccount();

            using (OrganizationServiceProxy serviceProxy = DynamicsCrmService.GetProxyService())
            {
                using (OrganizationServiceContext serviceContext = new OrganizationServiceContext(serviceProxy))
                {
                    crmAccount = GetAccountById(serviceContext, crmAccountId);
                }
            }

            return(crmAccount);
        }
        public List <MeteringPoint> GetBeitreiberMetringPoints(Guid crmAccountId, Guid beitreiberId)
        {
            List <MeteringPoint> beitreiberMeteringPoints = new List <MeteringPoint>();

            using (OrganizationServiceProxy serviceProxy = DynamicsCrmService.GetProxyService())
            {
                using (OrganizationServiceContext serviceContext = new OrganizationServiceContext(serviceProxy))
                {
                    beitreiberMeteringPoints = this.GetBeitreiberMetringPoints(serviceContext, crmAccountId, beitreiberId);
                }
            }

            return(beitreiberMeteringPoints);
        }
        public List <CrmAccount> GetAccounts()
        {
            List <CrmAccount> crmAccounts = new List <CrmAccount>();

            using (OrganizationServiceProxy serviceProxy = DynamicsCrmService.GetProxyService())
            {
                using (OrganizationServiceContext serviceContext = new OrganizationServiceContext(serviceProxy))
                {
                    crmAccounts = this.GetAccounts(serviceContext);
                }
            }

            return(crmAccounts);
        }
        public List <CrmAccount> GetBeitreibersByAccountId(Guid crmAccountId)
        {
            List <CrmAccount> Beitreibers = new List <CrmAccount>();

            using (OrganizationServiceProxy serviceProxy = DynamicsCrmService.GetProxyService())
            {
                using (OrganizationServiceContext serviceContext = new OrganizationServiceContext(serviceProxy))
                {
                    Beitreibers = this.GetBeitreibersByAccountId(serviceContext, crmAccountId);
                }
            }

            return(Beitreibers);
        }
        public List <MeteringPoint> GetMeteringPointsForAccountId(Guid crmAccountId)
        {
            List <MeteringPoint> meteringPoints = new List <MeteringPoint>();

            using (OrganizationServiceProxy serviceProxy = DynamicsCrmService.GetProxyService())
            {
                using (OrganizationServiceContext serviceContext = new OrganizationServiceContext(serviceProxy))
                {
                    var zahplunkts = serviceContext.CreateQuery(EntityNames.D_Zählpunkt).Where(za => za.GetAttributeValue <EntityReference>(MetadataDZählpunkt.ACCOUNT).Id == crmAccountId);
                    meteringPoints = GetMeteringPointsFromEntityCollection(serviceContext, zahplunkts);
                }
            }

            return(meteringPoints);
        }
        public List <MeteringPoint> GetMeteringPoints()
        {
            List <MeteringPoint> meteringPoints = new List <MeteringPoint>();

            using (OrganizationServiceProxy serviceProxy = DynamicsCrmService.GetProxyService())
            {
                using (OrganizationServiceContext serviceContext = new OrganizationServiceContext(serviceProxy))
                {
                    IQueryable <Entity> zahplunkts = serviceContext.CreateQuery(EntityNames.D_Zählpunkt);
                    meteringPoints = this.GetMeteringPoints(serviceContext);
                }
            }

            return(meteringPoints);
        }