public async Task <IActionResult> GetInvoice(string id)
        {
            ViewModels.Invoice result = null;
            // query the Dynamics system to get the invoice record.
            if (string.IsNullOrEmpty(id))
            {
                return(new NotFoundResult());
            }
            else
            {
                // get the current user.
                string       temp         = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
                UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp);

                Guid adoxio_legalentityid           = new Guid(id);
                MicrosoftDynamicsCRMinvoice invoice = await _dynamicsClient.GetInvoiceById(adoxio_legalentityid);

                if (invoice == null)
                {
                    return(new NotFoundResult());
                }

                // setup the related account.
                if (invoice._accountidValue != null)
                {
                    Guid accountId = Guid.Parse(invoice._accountidValue);
                    invoice.CustomeridAccount = await _dynamicsClient.GetAccountById(accountId);
                }

                result = invoice.ToViewModel();
            }

            return(Json(result));
        }
        public async Task <IActionResult> GetCurrentAccount()
        {
            ViewModels.Account result = null;

            // get the current user.
            string       temp         = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp);

            // query the Dynamics system to get the account record.
            if (userSettings.AccountId != null && userSettings.AccountId.Length > 0)
            {
                var accountId = Guid.Parse(userSettings.AccountId);
                MicrosoftDynamicsCRMaccount account = await _dynamicsClient.GetAccountById(accountId);

                if (account == null)
                {
                    return(new NotFoundResult());
                }

                result = account.ToViewModel();
            }
            else
            {
                return(new NotFoundResult());
            }

            return(Json(result));
        }
Beispiel #3
0
        public async Task <IActionResult> GetApplicantDynamicsLegalEntity()
        {
            ViewModels.AdoxioLegalEntity result = null;

            // get the current user.
            string       temp         = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp);

            // check that the session is setup correctly.
            userSettings.Validate();

            // query the Dynamics system to get the legal entity record.
            MicrosoftDynamicsCRMadoxioLegalentity legalEntity = null;

            _logger.LogError("Find legal entity for applicant = " + userSettings.AccountId.ToString());

            legalEntity = _dynamicsClient.GetAdoxioLegalentityByAccountId(Guid.Parse(userSettings.AccountId));

            if (legalEntity == null)
            {
                return(new NotFoundResult());
            }
            // fix the account.

            result = legalEntity.ToViewModel();

            if (result.account == null)
            {
                MicrosoftDynamicsCRMaccount account = await _dynamicsClient.GetAccountById(Guid.Parse(userSettings.AccountId));

                result.account = account.ToViewModel();
            }

            return(Json(result));
        }
        public static async Task <MicrosoftDynamicsCRMadoxioApplication> GetApplicationByIdWithChildren(this IDynamicsClient system, Guid id)
        {
            MicrosoftDynamicsCRMadoxioApplication result;

            try
            {
                string[] expand = { "adoxio_localgovindigenousnationid", "adoxio_application_SharePointDocumentLocations", "adoxio_AssignedLicence" };

                // fetch from Dynamics.
                result = await system.Applications.GetByKeyAsync(id.ToString(), expand : expand);

                if (result._adoxioLicencetypeValue != null)
                {
                    result.AdoxioLicenceType = system.GetAdoxioLicencetypeById(Guid.Parse(result._adoxioLicencetypeValue));
                }

                if (result._adoxioApplicantValue != null)
                {
                    result.AdoxioApplicant = await system.GetAccountById(Guid.Parse(result._adoxioApplicantValue));
                }

                if (result.AdoxioAssignedLicence != null && result.AdoxioAssignedLicence._adoxioEstablishmentValue != null)
                {
                    result.AdoxioAssignedLicence.AdoxioEstablishment = system.GetEstablishmentById(Guid.Parse(result.AdoxioAssignedLicence._adoxioEstablishmentValue));
                }
            }
            catch (Gov.Lclb.Cllb.Interfaces.Models.OdataerrorException)
            {
                result = null;
            }
            return(result);
        }
        public static async Task <MicrosoftDynamicsCRMadoxioApplication> GetApplicationById(this IDynamicsClient system, Guid id)
        {
            MicrosoftDynamicsCRMadoxioApplication result;

            try
            {
                // fetch from Dynamics.
                result = await system.Applications.GetByKeyAsync(id.ToString());

                if (result._adoxioLicencetypeValue != null)
                {
                    result.AdoxioLicenceType = system.GetAdoxioLicencetypeById(Guid.Parse(result._adoxioLicencetypeValue));
                }

                if (result._adoxioApplicantValue != null)
                {
                    result.AdoxioApplicant = await system.GetAccountById(Guid.Parse(result._adoxioApplicantValue));
                }
            }
            catch (Gov.Lclb.Cllb.Interfaces.Models.OdataerrorException)
            {
                result = null;
            }
            return(result);
        }
Beispiel #6
0
        public static void CreateEntitySharePointDocumentLocation(this IDynamicsClient _dynamicsClient, string entityName, string entityId, string folderName, string name)
        {
            switch (entityName.ToLower())
            {
            case "account":
                var account = _dynamicsClient.GetAccountById(entityId);
                _dynamicsClient.CreateAccountDocumentLocation(account, folderName, name);
                break;

            case "application":
                var application = _dynamicsClient.GetApplicationByIdWithChildren(entityId).GetAwaiter().GetResult();
                _dynamicsClient.CreateApplicationDocumentLocation(application, folderName, name);
                break;

            case "contact":
                var contact = _dynamicsClient.GetContactById(entityId).GetAwaiter().GetResult();
                _dynamicsClient.CreateContactDocumentLocation(contact, folderName, name);
                break;

            case "worker":
                var worker = _dynamicsClient.GetWorkerByIdWithChildren(entityId).GetAwaiter().GetResult();
                _dynamicsClient.CreateWorkerDocumentLocation(worker, folderName, name);
                break;

            case "event":
                var eventEntity = _dynamicsClient.GetEventByIdWithChildren(entityId);
                _dynamicsClient.CreateEventDocumentLocation(eventEntity, folderName, name);
                break;

            case "licence":
                var licenceEntity = _dynamicsClient.GetLicenceByIdWithChildren(entityId);
                _dynamicsClient.CreateLicenceDocumentLocation(licenceEntity, folderName, name);
                break;
            }
        }
Beispiel #7
0
        public static async Task <string> GetFolderName(string entityName, string entityId, IDynamicsClient _dynamicsClient)
        {
            var folderName = "";

            switch (entityName.ToLower())
            {
            case "account":
                var account = await _dynamicsClient.GetAccountById(Guid.Parse(entityId));

                folderName = GetAccountFolderName(account);
                break;

            case "application":
                var application = await _dynamicsClient.GetApplicationById(Guid.Parse(entityId));

                folderName = GetApplicationFolderName(application);
                break;

            case "contact":
                var contact = await _dynamicsClient.GetContactById(Guid.Parse(entityId));

                folderName = GetContactFolderName(contact);
                break;

            case "worker":
                var worker = await _dynamicsClient.GetWorkerById(Guid.Parse(entityId));

                folderName = GetWorkerFolderName(worker);
                break;

            default:
                break;
            }
            return(folderName);
        }
Beispiel #8
0
        public async Task <IActionResult> GetCurrentAccount()
        {
            _logger.LogInformation(LoggingEvents.HttpGet, "Begin method " + this.GetType().Name + "." + MethodBase.GetCurrentMethod().ReflectedType.Name);
            ViewModels.Account result = null;

            // get the current user.
            string       sessionSettings = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings    = JsonConvert.DeserializeObject <UserSettings>(sessionSettings);

            _logger.LogDebug(LoggingEvents.HttpGet, "UserSettings: " + JsonConvert.SerializeObject(userSettings));

            // query the Dynamics system to get the account record.
            if (userSettings.AccountId != null && userSettings.AccountId.Length > 0)
            {
                var accountId = GuidUtility.SanitizeGuidString(userSettings.AccountId);
                MicrosoftDynamicsCRMaccount account = await _dynamicsClient.GetAccountById(new Guid(accountId));

                _logger.LogDebug(LoggingEvents.HttpGet, "Dynamics Account: " + JsonConvert.SerializeObject(account));

                if (account == null)
                {
                    // Sometimes we receive the siteminderbusienssguid instead of the account id.
                    account = await _dynamicsClient.GetAccountBySiteminderBusinessGuid(accountId);

                    if (account == null)
                    {
                        _logger.LogWarning(LoggingEvents.NotFound, "No Account Found.");
                        return(new NotFoundResult());
                    }
                }
                result = account.ToViewModel();
            }
            else
            {
                _logger.LogWarning(LoggingEvents.NotFound, "No Account Found.");
                return(new NotFoundResult());
            }

            _logger.LogDebug(LoggingEvents.HttpGet, "Current Account Result: " +
                             JsonConvert.SerializeObject(result, Formatting.Indented, new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            }));
            return(Json(result));
        }
Beispiel #9
0
        private async Task <bool> CanAccessEntity(string entityName, string entityId)
        {
            var result = false;
            var id     = Guid.Parse(entityId);

            switch (entityName.ToLower())
            {
            case "account":
                var account = await _dynamicsClient.GetAccountById(id);

                result = account != null && CurrentUserHasAccessToApplicationOwnedBy(account.Accountid);
                break;

            case "application":
                var application = await _dynamicsClient.GetApplicationById(id);

                result = application != null && CurrentUserHasAccessToApplicationOwnedBy(application._adoxioApplicantValue);
                break;

            case "contact":
                var contact = await _dynamicsClient.GetContactById(id);

                result = contact != null && CurrentUserHasAccessToContactOwnedBy(contact.Contactid);
                break;

            case "worker":
                var worker = await _dynamicsClient.GetWorkerById(id);

                result = worker != null && CurrentUserHasAccessToContactOwnedBy(worker._adoxioContactidValue);
                break;

            default:
                break;
            }
            return(result);
        }
Beispiel #10
0
        /// <summary>
        /// Returns the SharePoint document Location for a given entity record
        /// </summary>
        /// <param name="entityName"></param>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public static string GetEntitySharePointDocumentLocation(this IDynamicsClient _dynamicsClient, string entityName, string entityId)
        {
            string result = null;
            var    id     = Guid.Parse(entityId);

            try
            {
                switch (entityName.ToLower())
                {
                case "account":
                    var account         = _dynamicsClient.GetAccountById(entityId);
                    var accountLocation = account.AccountSharepointDocumentLocation.FirstOrDefault();
                    if (accountLocation != null && !string.IsNullOrEmpty(accountLocation.Relativeurl))
                    {
                        result = accountLocation.Relativeurl;
                    }
                    break;

                case "application":
                    var application         = _dynamicsClient.GetApplicationByIdWithChildren(entityId).GetAwaiter().GetResult();
                    var applicationLocation = application.AdoxioApplicationSharePointDocumentLocations.FirstOrDefault();
                    if (applicationLocation != null && !string.IsNullOrEmpty(applicationLocation.Relativeurl))
                    {
                        result = applicationLocation.Relativeurl;
                    }
                    break;

                case "contact":
                    var contact         = _dynamicsClient.GetContactById(entityId).GetAwaiter().GetResult();
                    var contactLocation = contact.ContactSharePointDocumentLocations.FirstOrDefault();
                    if (contactLocation != null && !string.IsNullOrEmpty(contactLocation.Relativeurl))
                    {
                        result = contactLocation.Relativeurl;
                    }
                    break;

                case "worker":
                    var worker         = _dynamicsClient.GetWorkerByIdWithChildren(entityId).GetAwaiter().GetResult();
                    var workerLocation = worker.AdoxioWorkerSharePointDocumentLocations.FirstOrDefault();
                    if (workerLocation != null && !string.IsNullOrEmpty(workerLocation.Relativeurl))
                    {
                        result = workerLocation.Relativeurl;
                    }
                    break;

                case "event":
                    var eventEntity   = _dynamicsClient.GetEventByIdWithChildren(entityId);
                    var eventLocation = eventEntity.AdoxioEventSharePointDocumentLocations.FirstOrDefault();
                    if (eventLocation != null && !string.IsNullOrEmpty(eventLocation.Relativeurl))
                    {
                        result = eventLocation.Relativeurl;
                    }
                    break;

                case "licence":
                    var licenceEntity   = _dynamicsClient.GetLicenceByIdWithChildren(entityId);
                    var licenceLocation = licenceEntity.AdoxioLicencesSharePointDocumentLocations.FirstOrDefault();
                    if (licenceLocation != null && !string.IsNullOrEmpty(licenceLocation.Relativeurl))
                    {
                        result = licenceLocation.Relativeurl;
                    }
                    break;
                }
            }
            catch (ArgumentNullException)
            {
                return(null);
            }
            return(result);
        }
        /// <summary>
        /// Internal implementation of method for getting the status of document types for a given entity record
        /// </summary>
        /// <param name="entityName"></param>
        /// <param name="entityId"></param>
        /// <param name="formId"></param>
        /// <param name="checkUser"></param>
        /// <returns></returns>
        public async Task <IActionResult> GetDocumentTypeStatusInternal(string entityName, string entityId, string formId, bool checkUser)
        {
            List <DocumentTypeStatus> result = null;

            if (string.IsNullOrEmpty(entityId) || string.IsNullOrEmpty(entityName) || string.IsNullOrEmpty(formId))
            {
                return(BadRequest());
            }

            // lookup the entity
            string folderName = null;

            switch (entityName.ToLower())
            {
            case "account":
                var account = _dynamicsClient.GetAccountById(entityId);
                folderName = account.GetDocumentFolderName();
                break;

            case "application":
                var application = await _dynamicsClient.GetApplicationById(entityId);

                folderName = application.GetDocumentFolderName();
                break;

            case "contact":
                var contact = await _dynamicsClient.GetContactById(entityId);

                folderName = contact.GetDocumentFolderName();
                break;

            case "worker":
                var worker = await _dynamicsClient.GetWorkerById(entityId);

                folderName = worker.GetDocumentFolderName();
                break;
            }

            if (folderName != null)
            {
                var folderContents = _fileManagerClient.GetFileDetailsListInFolder(_logger, entityName, entityId, folderName);

                // get any file form fields that are related to the form
                var formFileFields = _dynamicsClient.Formelementuploadfields.GetDocumentFieldsByForm(formId);

                result = new List <DocumentTypeStatus>();

                foreach (var formFileField in formFileFields)
                {
                    var documentTypePrefix = formFileField.AdoxioFileprefix;
                    var documentTypeName   = formFileField.AdoxioName;
                    var routerLink         = formFileField.AdoxioRouterlink;

                    var valid = false;

                    // determine if there are any files with this prefix.

                    var firstMatch = folderContents.FirstOrDefault(f => f.documenttype == documentTypePrefix);

                    if (firstMatch != null)
                    {
                        valid = true;
                    }

                    result.Add(new DocumentTypeStatus {
                        DocumentType = documentTypePrefix, Name = documentTypeName, Valid = valid, RouterLink = routerLink
                    });
                }
            }


            // ensure that the entity has files.
            if (result == null)
            {
                return(BadRequest());
            }
            return(new JsonResult(result));
        }
Beispiel #12
0
        public async static Task <AdoxioApplication> ToViewModel(this MicrosoftDynamicsCRMadoxioApplication dynamicsApplication, IDynamicsClient dynamicsClient)
        {
            AdoxioApplication adoxioApplicationVM = new ViewModels.AdoxioApplication();

            // id
            if (dynamicsApplication.AdoxioApplicationid != null)
            {
                adoxioApplicationVM.id = dynamicsApplication.AdoxioApplicationid.ToString();
            }

            //get name
            adoxioApplicationVM.name = dynamicsApplication.AdoxioName;

            //get applying person from Contact entity
            if (dynamicsApplication._adoxioApplyingpersonValue != null)
            {
                Guid applyingPersonId = Guid.Parse(dynamicsApplication._adoxioApplyingpersonValue);
                var  contact          = await dynamicsClient.GetContactById(applyingPersonId);

                adoxioApplicationVM.applyingPerson = contact.Fullname;
            }
            if (dynamicsApplication._adoxioApplicantValue != null)
            {
                var applicant = await dynamicsClient.GetAccountById(Guid.Parse(dynamicsApplication._adoxioApplicantValue));

                adoxioApplicationVM.applicant = applicant.ToViewModel();
            }

            //get job number
            adoxioApplicationVM.jobNumber = dynamicsApplication.AdoxioJobnumber;

            //get license type from Adoxio_licencetype entity
            if (dynamicsApplication._adoxioLicencetypeValue != null)
            {
                Guid adoxio_licencetypeId = Guid.Parse(dynamicsApplication._adoxioLicencetypeValue);
                var  adoxio_licencetype   = dynamicsClient.GetAdoxioLicencetypeById(adoxio_licencetypeId);
                adoxioApplicationVM.licenseType = adoxio_licencetype.AdoxioName;
            }

            //get establishment name and address
            adoxioApplicationVM.establishmentName              = dynamicsApplication.AdoxioEstablishmentpropsedname;
            adoxioApplicationVM.establishmentaddressstreet     = dynamicsApplication.AdoxioEstablishmentaddressstreet;
            adoxioApplicationVM.establishmentaddresscity       = dynamicsApplication.AdoxioEstablishmentaddresscity;
            adoxioApplicationVM.establishmentaddresspostalcode = dynamicsApplication.AdoxioEstablishmentaddresspostalcode;
            adoxioApplicationVM.establishmentAddress           = dynamicsApplication.AdoxioEstablishmentaddressstreet
                                                                 + ", " + dynamicsApplication.AdoxioEstablishmentaddresscity
                                                                 + " " + dynamicsApplication.AdoxioEstablishmentaddresspostalcode;

            //get application status
            adoxioApplicationVM.applicationStatus = (AdoxioApplicationStatusCodes)dynamicsApplication.Statuscode;

            // set a couple of read-only flags to indicate status
            adoxioApplicationVM.isPaid = (dynamicsApplication.AdoxioPaymentrecieved != null && (bool)dynamicsApplication.AdoxioPaymentrecieved);

            //get parcel id
            adoxioApplicationVM.establishmentparcelid = dynamicsApplication.AdoxioEstablishmentparcelid;

            //get additional property info
            adoxioApplicationVM.additionalpropertyinformation = dynamicsApplication.AdoxioAdditionalpropertyinformation;

            //get payment info
            if (dynamicsApplication.AdoxioInvoicetrigger == 1)
            {
                adoxioApplicationVM.adoxioInvoiceTrigger = GeneralYesNo.Yes;
                adoxioApplicationVM.isSubmitted          = true;
            }
            else
            {
                adoxioApplicationVM.adoxioInvoiceTrigger = GeneralYesNo.No;
                adoxioApplicationVM.isSubmitted          = false;
            }
            adoxioApplicationVM.adoxioInvoiceId = dynamicsApplication._adoxioInvoiceValue;
            //TODO set in autorest
            adoxioApplicationVM.paymentreceiveddate = dynamicsApplication.AdoxioPaymentreceiveddate; //DateTime.Now;
            adoxioApplicationVM.prevPaymentFailed   = (dynamicsApplication._adoxioInvoiceValue != null) && (!adoxioApplicationVM.isSubmitted);

            //get declarations
            adoxioApplicationVM.authorizedtosubmit = dynamicsApplication.AdoxioAuthorizedtosubmit;
            adoxioApplicationVM.signatureagreement = dynamicsApplication.AdoxioSignatureagreement;

            //get contact details
            adoxioApplicationVM.contactpersonfirstname = dynamicsApplication.AdoxioContactpersonfirstname;
            adoxioApplicationVM.contactpersonlastname  = dynamicsApplication.AdoxioContactpersonlastname;
            adoxioApplicationVM.contactpersonrole      = dynamicsApplication.AdoxioRole;
            adoxioApplicationVM.contactpersonemail     = dynamicsApplication.AdoxioEmail;
            adoxioApplicationVM.contactpersonphone     = dynamicsApplication.AdoxioContactpersonphone;

            adoxioApplicationVM.modifiedOn = dynamicsApplication.Modifiedon;

            //get record audit info
            adoxioApplicationVM.createdon  = dynamicsApplication.Createdon;
            adoxioApplicationVM.modifiedon = dynamicsApplication.Modifiedon;

            return(adoxioApplicationVM);
        }
        public async static Task <Application> ToViewModel(this MicrosoftDynamicsCRMadoxioApplication dynamicsApplication, IDynamicsClient dynamicsClient)
        {
            Application applicationVM = new ViewModels.Application()
            {
                Name      = dynamicsApplication.AdoxioName,
                JobNumber = dynamicsApplication.AdoxioJobnumber,
                //get establishment name and address
                EstablishmentName              = dynamicsApplication.AdoxioEstablishmentpropsedname,
                EstablishmentAddressStreet     = dynamicsApplication.AdoxioEstablishmentaddressstreet,
                EstablishmentAddressCity       = dynamicsApplication.AdoxioEstablishmentaddresscity,
                EstablishmentAddressPostalCode = dynamicsApplication.AdoxioEstablishmentaddresspostalcode,
                EstablishmentAddress           = dynamicsApplication.AdoxioEstablishmentaddressstreet
                                                 + ", " + dynamicsApplication.AdoxioEstablishmentaddresscity
                                                 + " " + dynamicsApplication.AdoxioEstablishmentaddresspostalcode,
                EstablishmentPhone = dynamicsApplication.AdoxioEstablishmentphone,
                EstablishmentEmail = dynamicsApplication.AdoxioEstablishmentemail,

                ServicehHoursStandardHours = dynamicsApplication.AdoxioServicehoursstandardhours,
                ServiceHoursSundayOpen     = (ServiceHours?)dynamicsApplication.AdoxioServicehourssundayopen,
                ServiceHoursSundayClose    = (ServiceHours?)dynamicsApplication.AdoxioServicehourssundayclose,
                ServiceHoursMondayOpen     = (ServiceHours?)dynamicsApplication.AdoxioServicehoursmondayopen,
                ServiceHoursMondayClose    = (ServiceHours?)dynamicsApplication.AdoxioServicehoursmondayclose,
                ServiceHoursTuesdayOpen    = (ServiceHours?)dynamicsApplication.AdoxioServicehourstuesdayopen,
                ServiceHoursTuesdayClose   = (ServiceHours?)dynamicsApplication.AdoxioServicehourstuesdayclose,
                ServiceHoursWednesdayOpen  = (ServiceHours?)dynamicsApplication.AdoxioServicehourswednesdayopen,
                ServiceHoursWednesdayClose = (ServiceHours?)dynamicsApplication.AdoxioServicehourswednesdayclose,
                ServiceHoursThursdayOpen   = (ServiceHours?)dynamicsApplication.AdoxioServicehoursthursdayopen,
                ServiceHoursThursdayClose  = (ServiceHours?)dynamicsApplication.AdoxioServicehoursthursdayclose,
                ServiceHoursFridayOpen     = (ServiceHours?)dynamicsApplication.AdoxioServicehoursfridayopen,
                ServiceHoursFridayClose    = (ServiceHours?)dynamicsApplication.AdoxioServicehoursfridayclose,
                ServiceHoursSaturdayOpen   = (ServiceHours?)dynamicsApplication.AdoxioServicehourssaturdayopen,
                ServiceHoursSaturdayClose  = (ServiceHours?)dynamicsApplication.AdoxioServicehourssaturdayclose,

                AuthorizedToSubmit = dynamicsApplication.AdoxioAuthorizedtosubmit,
                SignatureAgreement = dynamicsApplication.AdoxioSignatureagreement,

                LicenceFeeInvoicePaid = (dynamicsApplication.AdoxioLicencefeeinvoicepaid != null && dynamicsApplication.AdoxioLicencefeeinvoicepaid == true),



                // set a couple of read-only flags to indicate status
                IsPaid = (dynamicsApplication.AdoxioPaymentrecieved != null && (bool)dynamicsApplication.AdoxioPaymentrecieved),

                //get parcel id
                EstablishmentParcelId = dynamicsApplication.AdoxioEstablishmentparcelid,

                //get additional property info
                AdditionalPropertyInformation = dynamicsApplication.AdoxioAdditionalpropertyinformation,
                AdoxioInvoiceId = dynamicsApplication._adoxioInvoiceValue,

                PaymentReceivedDate = dynamicsApplication.AdoxioPaymentreceiveddate,

                //get contact details
                ContactPersonFirstName = dynamicsApplication.AdoxioContactpersonfirstname,
                ContactPersonLastName  = dynamicsApplication.AdoxioContactpersonlastname,
                ContactPersonRole      = dynamicsApplication.AdoxioRole,
                ContactPersonEmail     = dynamicsApplication.AdoxioEmail,
                ContactPersonPhone     = dynamicsApplication.AdoxioContactpersonphone,

                //get record audit info
                CreatedOn  = dynamicsApplication.Createdon,
                ModifiedOn = dynamicsApplication.Modifiedon
            };


            // id
            if (dynamicsApplication.AdoxioApplicationid != null)
            {
                applicationVM.Id = dynamicsApplication.AdoxioApplicationid.ToString();
            }

            if (dynamicsApplication.Statuscode != null)
            {
                applicationVM.ApplicationStatus = (AdoxioApplicationStatusCodes)dynamicsApplication.Statuscode;
            }

            if (dynamicsApplication.AdoxioApplicanttype != null)
            {
                applicationVM.ApplicantType = (AdoxioApplicantTypeCodes)dynamicsApplication.AdoxioApplicanttype;
            }

            //get applying person from Contact entity
            if (dynamicsApplication._adoxioApplyingpersonValue != null)
            {
                Guid applyingPersonId = Guid.Parse(dynamicsApplication._adoxioApplyingpersonValue);
                var  contact          = await dynamicsClient.GetContactById(applyingPersonId);

                applicationVM.ApplyingPerson = contact.Fullname;
            }
            if (dynamicsApplication._adoxioApplicantValue != null)
            {
                var applicant = await dynamicsClient.GetAccountById(Guid.Parse(dynamicsApplication._adoxioApplicantValue));

                applicationVM.Applicant = applicant.ToViewModel();
            }

            //get license type from Adoxio_licencetype entity
            if (dynamicsApplication._adoxioLicencetypeValue != null)
            {
                Guid adoxio_licencetypeId = Guid.Parse(dynamicsApplication._adoxioLicencetypeValue);
                var  adoxio_licencetype   = dynamicsClient.GetAdoxioLicencetypeById(adoxio_licencetypeId);
                applicationVM.LicenseType = adoxio_licencetype.AdoxioName;
            }

            if (dynamicsApplication.AdoxioAppchecklistfinaldecision != null)
            {
                applicationVM.AppChecklistFinalDecision = (AdoxioFinalDecisionCodes)dynamicsApplication.AdoxioAppchecklistfinaldecision;
            }

            //get payment info
            if (dynamicsApplication.AdoxioInvoicetrigger != null && dynamicsApplication.AdoxioInvoicetrigger == 1)
            {
                applicationVM.AdoxioInvoiceTrigger = GeneralYesNo.Yes;
                applicationVM.IsSubmitted          = true;
            }
            else
            {
                applicationVM.AdoxioInvoiceTrigger = GeneralYesNo.No;
                applicationVM.IsSubmitted          = false;
            }

            if (dynamicsApplication.AdoxioLicenceFeeInvoice != null)
            {
                applicationVM.LicenceFeeInvoice = dynamicsApplication.AdoxioLicenceFeeInvoice.ToViewModel();
            }

            if (dynamicsApplication.AdoxioAssignedLicence != null)
            {
                applicationVM.AssignedLicence = dynamicsApplication.AdoxioAssignedLicence.ToViewModel(dynamicsClient);
            }

            applicationVM.PrevPaymentFailed = (dynamicsApplication._adoxioInvoiceValue != null) && (!applicationVM.IsSubmitted);

            return(applicationVM);
        }
        public async static Task <Application> ToViewModel(this MicrosoftDynamicsCRMadoxioApplication dynamicsApplication, IDynamicsClient dynamicsClient)
        {
            Application applicationVM = new ViewModels.Application()
            {
                Name      = dynamicsApplication.AdoxioName,
                JobNumber = dynamicsApplication.AdoxioJobnumber,
                //get establishment name and address
                EstablishmentName              = dynamicsApplication.AdoxioEstablishmentpropsedname,
                EstablishmentAddressStreet     = dynamicsApplication.AdoxioEstablishmentaddressstreet,
                EstablishmentAddressCity       = dynamicsApplication.AdoxioEstablishmentaddresscity,
                EstablishmentAddressPostalCode = dynamicsApplication.AdoxioEstablishmentaddresspostalcode,
                EstablishmentAddress           = dynamicsApplication.AdoxioEstablishmentaddressstreet
                                                 + ", " + dynamicsApplication.AdoxioEstablishmentaddresscity
                                                 + " " + dynamicsApplication.AdoxioEstablishmentaddresspostalcode,
                EstablishmentPhone   = dynamicsApplication.AdoxioEstablishmentphone,
                EstablishmentEmail   = dynamicsApplication.AdoxioEstablishmentemail,
                FederalProducerNames = dynamicsApplication.AdoxioFederalproducernames,

                ServicehHoursStandardHours = dynamicsApplication.AdoxioServicehoursstandardhours,
                ServiceHoursSundayOpen     = (ServiceHours?)dynamicsApplication.AdoxioServicehourssundayopen,
                ServiceHoursSundayClose    = (ServiceHours?)dynamicsApplication.AdoxioServicehourssundayclose,
                ServiceHoursMondayOpen     = (ServiceHours?)dynamicsApplication.AdoxioServicehoursmondayopen,
                ServiceHoursMondayClose    = (ServiceHours?)dynamicsApplication.AdoxioServicehoursmondayclose,
                ServiceHoursTuesdayOpen    = (ServiceHours?)dynamicsApplication.AdoxioServicehourstuesdayopen,
                ServiceHoursTuesdayClose   = (ServiceHours?)dynamicsApplication.AdoxioServicehourstuesdayclose,
                ServiceHoursWednesdayOpen  = (ServiceHours?)dynamicsApplication.AdoxioServicehourswednesdayopen,
                ServiceHoursWednesdayClose = (ServiceHours?)dynamicsApplication.AdoxioServicehourswednesdayclose,
                ServiceHoursThursdayOpen   = (ServiceHours?)dynamicsApplication.AdoxioServicehoursthursdayopen,
                ServiceHoursThursdayClose  = (ServiceHours?)dynamicsApplication.AdoxioServicehoursthursdayclose,
                ServiceHoursFridayOpen     = (ServiceHours?)dynamicsApplication.AdoxioServicehoursfridayopen,
                ServiceHoursFridayClose    = (ServiceHours?)dynamicsApplication.AdoxioServicehoursfridayclose,
                ServiceHoursSaturdayOpen   = (ServiceHours?)dynamicsApplication.AdoxioServicehourssaturdayopen,
                ServiceHoursSaturdayClose  = (ServiceHours?)dynamicsApplication.AdoxioServicehourssaturdayclose,

                RenewalCriminalOffenceCheck     = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalcriminaloffencecheck,
                RenewalUnreportedSaleOfBusiness = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalunreportedsaleofbusiness,
                RenewalBusinessType             = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalbusinesstype,
                RenewalTiedhouse            = (ValueNotChanged?)dynamicsApplication.AdoxioRenewaltiedhouse,
                RenewalOrgLeadership        = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalorgleadership,
                Renewalkeypersonnel         = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalkeypersonnel,
                RenewalShareholders         = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalshareholders,
                RenewalOutstandingFines     = (ValueNotChanged?)dynamicsApplication.AdoxioRenewaloutstandingfines,
                RenewalBranding             = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalbranding,
                RenewalSignage              = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalsignage,
                RenewalEstablishmentAddress = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalestablishmentaddress,
                RenewalValidInterest        = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalvalidinterest,
                RenewalZoning            = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalzoning,
                RenewalFloorPlan         = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalfloorplan,
                RenewalSiteMap           = (ValueNotChanged?)dynamicsApplication.AdoxioRenewalsitemap,
                TiedhouseFederalInterest = (ValueNotChanged?)dynamicsApplication.AdoxioRenewaltiedhousefederalinterest,



                AuthorizedToSubmit = dynamicsApplication.AdoxioAuthorizedtosubmit,
                SignatureAgreement = dynamicsApplication.AdoxioSignatureagreement,

                LicenceFeeInvoicePaid = (dynamicsApplication.AdoxioLicencefeeinvoicepaid != null && dynamicsApplication.AdoxioLicencefeeinvoicepaid == true),

                // set a couple of read-only flags to indicate status
                IsPaid = (dynamicsApplication.AdoxioPaymentrecieved != null && (bool)dynamicsApplication.AdoxioPaymentrecieved),

                IndigenousNationId = dynamicsApplication._adoxioLocalgovindigenousnationidValue,

                //get parcel id
                EstablishmentParcelId = dynamicsApplication.AdoxioEstablishmentparcelid,

                //get additional property info
                AdditionalPropertyInformation = dynamicsApplication.AdoxioAdditionalpropertyinformation,
                AdoxioInvoiceId = dynamicsApplication._adoxioInvoiceValue,

                PaymentReceivedDate = dynamicsApplication.AdoxioPaymentreceiveddate,
                Description1        = dynamicsApplication.AdoxioDescription1,

                //get contact details
                ContactPersonFirstName = dynamicsApplication.AdoxioContactpersonfirstname,
                ContactPersonLastName  = dynamicsApplication.AdoxioContactpersonlastname,
                ContactPersonRole      = dynamicsApplication.AdoxioRole,
                ContactPersonEmail     = dynamicsApplication.AdoxioEmail,
                ContactPersonPhone     = dynamicsApplication.AdoxioContactpersonphone,

                //get record audit info
                CreatedOn  = dynamicsApplication.Createdon,
                ModifiedOn = dynamicsApplication.Modifiedon,

                //store opening
                IsReadyWorkers                  = dynamicsApplication.AdoxioIsreadyworkers,
                IsReadyNameBranding             = dynamicsApplication.AdoxioIsreadynamebranding,
                IsReadyDisplays                 = dynamicsApplication.AdoxioIsreadydisplays,
                IsReadyIntruderAlarm            = dynamicsApplication.AdoxioIsreadyintruderalarm,
                IsReadyFireAlarm                = dynamicsApplication.AdoxioIsreadyfirealarm,
                IsReadyLockedCases              = dynamicsApplication.AdoxioIsreadylockedcases,
                IsReadyLockedStorage            = dynamicsApplication.AdoxioIsreadylockedstorage,
                IsReadyPerimeter                = dynamicsApplication.AdoxioIsreadyperimeter,
                IsReadyRetailArea               = dynamicsApplication.AdoxioIsreadyretailarea,
                IsReadyStorage                  = dynamicsApplication.AdoxioIsreadystorage,
                IsReadyExtranceExit             = dynamicsApplication.AdoxioIsreadyentranceexit,
                IsReadySurveillanceNotice       = dynamicsApplication.AdoxioIsreadysurveillancenotice,
                IsReadyProductNotVisibleOutside = dynamicsApplication.AdoxioIsreadyproductnotvisibleoutside,
                Establishmentopeningdate        = dynamicsApplication.AdoxioEstablishmentopeningdate,
                IsReadyValidInterest            = dynamicsApplication.AdoxioIsreadyvalidinterest,
            };


            // id
            if (dynamicsApplication.AdoxioApplicationid != null)
            {
                applicationVM.Id = dynamicsApplication.AdoxioApplicationid.ToString();
            }

            if (dynamicsApplication.Statuscode != null)
            {
                applicationVM.ApplicationStatus = (AdoxioApplicationStatusCodes)dynamicsApplication.Statuscode;
            }

            if (dynamicsApplication.AdoxioApplicanttype != null)
            {
                applicationVM.ApplicantType = (AdoxioApplicantTypeCodes)dynamicsApplication.AdoxioApplicanttype;
            }

            //get applying person from Contact entity
            if (dynamicsApplication._adoxioApplyingpersonValue != null)
            {
                Guid applyingPersonId = Guid.Parse(dynamicsApplication._adoxioApplyingpersonValue);
                var  contact          = await dynamicsClient.GetContactById(applyingPersonId);

                applicationVM.ApplyingPerson = contact.Fullname;
            }
            if (dynamicsApplication._adoxioApplicantValue != null)
            {
                var applicant = await dynamicsClient.GetAccountById(Guid.Parse(dynamicsApplication._adoxioApplicantValue));

                applicationVM.Applicant = applicant.ToViewModel();
            }

            //get license type from Adoxio_licencetype entity
            if (dynamicsApplication._adoxioLicencetypeValue != null)
            {
                Guid adoxio_licencetypeId = Guid.Parse(dynamicsApplication._adoxioLicencetypeValue);
                var  adoxio_licencetype   = dynamicsClient.GetAdoxioLicencetypeById(adoxio_licencetypeId);
                applicationVM.LicenseType = adoxio_licencetype.AdoxioName;
            }

            if (dynamicsApplication.AdoxioAppchecklistfinaldecision != null)
            {
                applicationVM.AppChecklistFinalDecision = (AdoxioFinalDecisionCodes)dynamicsApplication.AdoxioAppchecklistfinaldecision;
            }

            //get payment info
            if (dynamicsApplication.AdoxioInvoicetrigger != null && dynamicsApplication.AdoxioInvoicetrigger == 1)
            {
                applicationVM.AdoxioInvoiceTrigger = GeneralYesNo.Yes;
                applicationVM.IsSubmitted          = true;
            }
            else
            {
                applicationVM.AdoxioInvoiceTrigger = GeneralYesNo.No;
                applicationVM.IsSubmitted          = false;
            }

            if (dynamicsApplication.AdoxioLicenceFeeInvoice != null)
            {
                applicationVM.LicenceFeeInvoice = dynamicsApplication.AdoxioLicenceFeeInvoice.ToViewModel();
            }

            if (dynamicsApplication.AdoxioAssignedLicence != null)
            {
                applicationVM.AssignedLicence = dynamicsApplication.AdoxioAssignedLicence.ToViewModel(dynamicsClient);
            }

            if (dynamicsApplication.AdoxioApplicationTypeId != null)
            {
                applicationVM.ApplicationType = dynamicsApplication.AdoxioApplicationTypeId.ToViewModel();
            }
            if (dynamicsApplication.AdoxioApplicationAdoxioTiedhouseconnectionApplication != null)
            {
                var tiedHouse = dynamicsApplication.AdoxioApplicationAdoxioTiedhouseconnectionApplication.FirstOrDefault();
                if (tiedHouse != null)
                {
                    applicationVM.TiedHouse = tiedHouse.ToViewModel();
                }
            }

            applicationVM.PrevPaymentFailed = (dynamicsApplication._adoxioInvoiceValue != null) && (!applicationVM.IsSubmitted);

            return(applicationVM);
        }
Beispiel #15
0
        /// <summary>
        /// Hangfire job to send Change Status message to One stop.
        /// </summary>
        public async Task SendChangeNameRest(PerformContext hangfireContext, string licenceGuidRaw, string queueItemId, bool isTransfer)
        {
            IDynamicsClient dynamicsClient = DynamicsSetupUtil.SetupDynamics(_configuration);

            if (hangfireContext != null)
            {
                hangfireContext.WriteLine("Starting OneStop REST ChangeName Job.");
            }

            string licenceGuid = Utils.ParseGuid(licenceGuidRaw);

            //prepare soap content
            var req     = new ChangeName();
            var licence = dynamicsClient.GetLicenceByIdWithChildren(licenceGuid);

            if (hangfireContext != null && licence != null)
            {
                hangfireContext.WriteLine($"Got Licence {licenceGuid}.");
            }

            if (licence == null || licence.AdoxioEstablishment == null)
            {
                if (hangfireContext != null)
                {
                    hangfireContext.WriteLine($"Unable to get licence {licenceGuid}.");
                }

                if (Log.Logger != null)
                {
                    Log.Logger.Error($"Unable to get licence {licenceGuid}.");
                }
            }
            else
            {
                string targetBusinessNumber = null;

                ChangeNameType changeNameType = ChangeNameType.ChangeName;
                if (isTransfer && !string.IsNullOrEmpty(licence._adoxioProposedownerValue))
                {
                    changeNameType = ChangeNameType.Transfer;
                    var targetOwner = dynamicsClient.GetAccountById(licence._adoxioProposedownerValue);
                    if (targetOwner != null)
                    {
                        targetBusinessNumber = targetOwner.Accountnumber;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(licence._adoxioThirdpartyoperatoridValue))
                    {
                        changeNameType = ChangeNameType.ThirdPartyOperator;
                    }
                }

                var innerXml = req.CreateXML(licence, changeNameType, targetBusinessNumber);

                innerXml = _onestopRestClient.CleanXML(innerXml);

                if (Log.Logger != null)
                {
                    Log.Logger.Information(innerXml);
                }

                if (hangfireContext != null)
                {
                    hangfireContext.WriteLine(innerXml);
                }

                //send message to Onestop hub
                var outputXML = await _onestopRestClient.ReceiveFromPartner(innerXml);

                UpdateQueueItemForSend(dynamicsClient, hangfireContext, queueItemId, innerXml, outputXML);

                if (hangfireContext != null)
                {
                    hangfireContext.WriteLine(outputXML);
                    hangfireContext.WriteLine("End of OneStop REST ChangeName  Job.");
                }
            }
        }