/// <summary>
        /// Getthe Equipment Location record by Equipment Id and Location Id
        /// </summary>
        /// <param name="system"></param>
        /// <param name="equipmentId"></param>
        /// <param name="locationId"></param>
        /// <returns></returns>
        public static MicrosoftDynamicsCRMbcgovEquipmentlocation GetEquipmentLocationByBothIds(this IDynamicsClient system, Guid equipmentId, Guid locationId)
        {
            MicrosoftDynamicsCRMbcgovEquipmentlocation result = null;

            try
            {
                // fetch from Dynamics.
                string        filter = $"_bcgov_equipment_value eq {equipmentId} and _bcgov_location_value eq {locationId}";
                List <string> expand = new List <string> {
                    "bcgov_Equipment", "bcgov_Location"
                };
                var queryResult = system.Equipmentlocations.Get(filter: filter, expand: expand);
                foreach (var item in queryResult.Value)
                {
                    result = item;
                }
            }
            catch (OdataerrorException)
            {
                result = null;
            }

            // add the address to the location
            if (result.BcgovLocation != null && result.BcgovLocation._bcgovLocationaddressValue != null)
            {
                result.BcgovLocation.BcgovLocationAddress = system.GetCustomAddressById(result.BcgovLocation._bcgovLocationaddressValue);
            }

            return(result);
        }
Esempio n. 2
0
        public static MicrosoftDynamicsCRMbcgovEquipment GetEquipmentByIdWithChildren(this IDynamicsClient system, Guid id)
        {
            MicrosoftDynamicsCRMbcgovEquipment result;

            try
            {
                List <string> expand = new List <string>()
                {
                    "bcgov_CurrentBusinessOwner", "bcgov_CurrentLocation"
                };
                // fetch from Dynamics.
                result = system.Equipments.GetByKey(bcgovEquipmentid: id.ToString(), expand: expand);
            }
            catch (OdataerrorException)
            {
                result = null;
            }

            // add the address to the current location
            if (result.BcgovCurrentLocation != null && result.BcgovCurrentLocation._bcgovLocationaddressValue != null)
            {
                result.BcgovCurrentLocation.BcgovLocationAddress = system.GetCustomAddressById(result.BcgovCurrentLocation._bcgovLocationaddressValue);
            }

            return(result);
        }
Esempio n. 3
0
        public static MicrosoftDynamicsCRMincident GetApplicationByIdWithChildren(this IDynamicsClient system, string id)
        {
            MicrosoftDynamicsCRMincident result;

            try
            {
                List <string> expand = new List <string>()
                {
                    "bcgov_ApplicationTypeId", "bcgov_incident_customproduct_RelatedApplication", "customerid_account", "bcgov_incident_businesscontact",
                    "bcgov_BCSellersAddress", "bcgov_OutsideBCSellersAddress", "bcgov_ImportersAddress", "bcgov_OriginatingSellersAddress",
                    "bcgov_AddressofBusinessthathasGivenorLoaned", "bcgov_AddressofBusinessthathasRentedorLeased", "bcgov_EquipmentLocation", "bcgov_AddressofPersonBusiness",
                    "bcgov_incident_bcgov_certificate_Application"
                };
                // fetch from Dynamics.
                result = system.Incidents.GetByKey(incidentid: id, expand: expand);
                // expand only goes one level deep - we need the "location address"

                if (result.BcgovEquipmentLocation != null && result.BcgovEquipmentLocation._bcgovLocationaddressValue != null)
                {
                    result.BcgovEquipmentLocation.BcgovLocationAddress = system.GetCustomAddressById(result.BcgovEquipmentLocation._bcgovLocationaddressValue);
                }
            }
            catch (OdataerrorException)
            {
                result = null;
            }

            if (result != null && result.BcgovIncidentBusinesscontact != null)
            {
                for (int i = 0; i < result.BcgovIncidentBusinesscontact.Count; i++)
                {
                    try
                    {
                        result.BcgovIncidentBusinesscontact[i] = system.GetBusinessContactById(result.BcgovIncidentBusinesscontact[i].BcgovBusinesscontactid);
                    }
                    catch (OdataerrorException)
                    {
                        // ignore the exception.
                    }
                }
            }


            return(result);
        }
Esempio n. 4
0
        public static MicrosoftDynamicsCRMincident GetApplicationByIdWithChildren(this IDynamicsClient system, string id)
        {
            MicrosoftDynamicsCRMincident result;

            try
            {
                List <string> expand = new List <string>()
                {
                    "bcgov_ApplicationTypeId", "bcgov_incident_customproduct_RelatedApplication", "customerid_account", "bcgov_incident_businesscontact",
                    "bcgov_BCSellersAddress", "bcgov_OutsideBCSellersAddress", "bcgov_ImportersAddress", "bcgov_OriginatingSellersAddress",
                    "bcgov_AddressofBusinessthathasGivenorLoaned", "bcgov_AddressofBusinessthathasRentedorLeased", "bcgov_EquipmentLocation", "bcgov_AddressofPersonBusiness",
                    "bcgov_incident_bcgov_certificate_Application", "bcgov_EquipmentRecord", "bcgov_AddressWhereEquipmentWasDestroyed", "bcgov_CivicAddressofPurchaser",
                    "bcgov_PurchasersCivicAddress", "bcgov_PurchasersBusinessAddress"
                };
                // fetch from Dynamics.
                result = system.Incidents.GetByKey(incidentid: id, expand: expand);
                // expand only goes one level deep - we need the "location address"

                if (result.BcgovEquipmentLocation != null && result.BcgovEquipmentLocation._bcgovLocationaddressValue != null)
                {
                    result.BcgovEquipmentLocation.BcgovLocationAddress = system.GetCustomAddressById(result.BcgovEquipmentLocation._bcgovLocationaddressValue);
                }

                // get the full certificate data.  The initial request only has one level deep of data.

                if (result.BcgovIncidentBcgovCertificateApplication != null)
                {
                    foreach (var certificate in result.BcgovIncidentBcgovCertificateApplication)
                    {
                        // copy over child entities
                        var temp = system.GetCertificateByIdWithChildren(certificate.BcgovCertificateid);
                        if (temp != null)
                        {
                            certificate.BcgovCertificateBcgovCertificateapprovedproductCertificateId
                                = temp.BcgovCertificateBcgovCertificateapprovedproductCertificateId;
                            certificate.BcgovCertificateBcgovCertificatetermsandconditionsCertificate
                                = temp.BcgovCertificateBcgovCertificatetermsandconditionsCertificate;
                        }
                    }
                }
            }
            catch (OdataerrorException)
            {
                result = null;
            }

            if (result != null && result.BcgovIncidentBusinesscontact != null)
            {
                for (int i = 0; i < result.BcgovIncidentBusinesscontact.Count; i++)
                {
                    try
                    {
                        result.BcgovIncidentBusinesscontact[i] = system.GetBusinessContactById(result.BcgovIncidentBusinesscontact[i].BcgovBusinesscontactid);
                    }
                    catch (OdataerrorException)
                    {
                        // ignore the exception.
                    }
                }
            }


            return(result);
        }
 public static MicrosoftDynamicsCRMbcgovCustomaddress GetCustomAddressById(this IDynamicsClient system, Guid id)
 {
     return(system.GetCustomAddressById(id.ToString()));
 }