Exemple #1
0
        public async Task <JsonResult> GetDynamicsApplications()
        {
            // create a DataServiceCollection to add the record
            DataServiceCollection <Contexts.Microsoft.Dynamics.CRM.Adoxio_application> ApplicationCollection = new DataServiceCollection <Contexts.Microsoft.Dynamics.CRM.Adoxio_application>(_system);

            // get all applications in Dynamics filtered by the applying person
            //var dynamicsApplicationList = await _system.Adoxio_applications.AddQueryOption("$filter", "_adoxio_applyingperson_value eq 7d4a5b20-e352-e811-8140-480fcfeac941").ExecuteAsync();

            // get all applications in Dynamics
            var dynamicsApplicationList = await _system.Adoxio_applications.ExecuteAsync();

            List <ViewModels.AdoxioApplication> adoxioApplications = new List <AdoxioApplication>();

            ViewModels.AdoxioApplication adoxioApplication = null;

            if (dynamicsApplicationList != null)
            {
                foreach (var dynamicsApplication in dynamicsApplicationList)
                {
                    adoxioApplication      = new ViewModels.AdoxioApplication();
                    adoxioApplication.name = dynamicsApplication.Adoxio_name;
                    //adoxioApplication.applyingPerson = dynamicsApplication.Adoxio_ApplyingPerson.Adoxio_contact_adoxio_application_ApplyingPerson.ToString();
                    Guid?applyingPersonId = dynamicsApplication._adoxio_applyingperson_value;

                    if (applyingPersonId != null)
                    {
                        // fetch a contact
                        Contexts.Microsoft.Dynamics.CRM.Contact contact = await _system.Contacts.ByKey(contactid : applyingPersonId).GetValueAsync();

                        adoxioApplication.applyingPerson = contact.Fullname;
                    }

                    adoxioApplication.jobNumber = dynamicsApplication.Adoxio_jobnumber;

                    Guid?adoxio_licencetypeId = dynamicsApplication._adoxio_licencetype_value;
                    if (adoxio_licencetypeId != null)
                    {
                        Adoxio_licencetype adoxio_licencetype = await _system.Adoxio_licencetypes.ByKey(adoxio_licencetypeid : adoxio_licencetypeId).GetValueAsync();

                        adoxioApplication.licenseType = adoxio_licencetype.Adoxio_name;
                    }

                    adoxioApplications.Add(adoxioApplication);
                }
            }

            return(Json(adoxioApplications));
        }
Exemple #2
0
        public static AdoxioLicenseType ToViewModel(this Adoxio_licencetype dynamicsLicenseType)
        {
            AdoxioLicenseType result = new AdoxioLicenseType();

            // fetch the establishment and get name and address
            Guid?licenceTypeId = dynamicsLicenseType.Adoxio_licencetypeid;

            if (dynamicsLicenseType.Adoxio_licencetypeid != null)
            {
                result.id = dynamicsLicenseType.Adoxio_licencetypeid.ToString();
            }
            result.code = dynamicsLicenseType.Adoxio_code;
            result.name = dynamicsLicenseType.Adoxio_name;

            return(result);
        }
        public async static Task <AdoxioLicense> ToViewModel(this Adoxio_licences dynamicsLicense, Interfaces.Microsoft.Dynamics.CRM.System _system)
        {
            AdoxioLicense adoxioLicenseVM = new AdoxioLicense();

            // fetch the establishment and get name and address
            Guid?adoxioEstablishmentId = dynamicsLicense._adoxio_establishment_value;

            if (adoxioEstablishmentId != null)
            {
                Interfaces.Microsoft.Dynamics.CRM.Adoxio_establishment establishment = await _system.Adoxio_establishments.ByKey(adoxio_establishmentid : adoxioEstablishmentId).GetValueAsync();

                adoxioLicenseVM.establishmentName    = establishment.Adoxio_name;
                adoxioLicenseVM.establishmentAddress = establishment.Adoxio_addressstreet
                                                       + ", " + establishment.Adoxio_addresscity
                                                       + " " + establishment.Adoxio_addresspostalcode;
            }

            // fetch the licence status
            int?adoxio_licenceStatusId = dynamicsLicense.Statuscode;

            if (adoxio_licenceStatusId != null)
            {
                adoxioLicenseVM.licenseStatus = dynamicsLicense.Statuscode.ToString();
            }

            // fetch the licence type
            Guid?adoxio_licencetypeId = dynamicsLicense._adoxio_licencetype_value;

            if (adoxio_licencetypeId != null)
            {
                Adoxio_licencetype adoxio_licencetype = await _system.Adoxio_licencetypes.ByKey(adoxio_licencetypeid : adoxio_licencetypeId).GetValueAsync();

                adoxioLicenseVM.licenseType = adoxio_licencetype.Adoxio_name;
            }

            // fetch license number
            adoxioLicenseVM.licenseNumber = dynamicsLicense.Adoxio_licencenumber;

            return(adoxioLicenseVM);
        }
        /// <summary>
        /// Get a contact by their Guid
        /// </summary>
        /// <param name="system"></param>
        /// <param name="distributedCache"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static async Task <Adoxio_licencetype> GetLicenceTypeById(this Microsoft.Dynamics.CRM.System system, Guid id)
        {
            Adoxio_licencetype result = null;

            // fetch from Dynamics.
            try
            {
                result = await system.Adoxio_licencetypes.ByKey(id).GetValueAsync();
            }
            catch (DataServiceQueryException dsqe)
            {
                if (dsqe.Message.Contains("Does Not Exist"))
                {
                    result = null;
                }
                else
                {
                    throw;
                }
            }

            return(result);
        }