Exemplo n.º 1
0
        private async Task CreateNewOnlineForm(string refId, ExternalOnlineForm externalFrom, ExternalStakeholder notifier, ExternalAddress notifierAddress, List <ExternalProduct> allProducts, List <ExternalCompany> contacts)
        {
            logger.LogDebug("Creating new online form.");
            var            countries              = this.host.Lookups.Countries.ToList();
            var            newForm                = ToOnlineForm(externalFrom, refId);
            var            stakeHolder            = ToOnlineStakeHolder(notifier);
            var            stakeholderAddressNote = NotifierAddress(notifierAddress, countries);
            var            products               = allProducts.Select(p => ToOnlineProduct(p));
            SimsOnlineForm addedForm              = null;

            try
            {
                logger.LogDebug("Adding onlineform - base");
                addedForm = await this.host.OnlineForms.Add(newForm);
            }
            catch (Exception ex)
            {
                logger.LogCritical("Failed to add basic form", ex);
                throw ex;
            }
            try
            {
                logger.LogDebug("Adding onlineform - stakeholders");
                //  var stakeholders = await this.host.OnlineForms.Stakeholders.Add(addedForm.CommonId, stakeHolder);
                await this.host.OnlineForms.Notes.Add(addedForm.CommonId, $"Stakeholder Address\n{stakeHolder.Name}\n{stakeHolder.Role}\n{stakeHolder.Phone}\n{stakeholderAddressNote.Note}", 5);
            }
            catch (Exception ex)
            {
                logger.LogCritical("Failed to add stakeholders", ex);
                throw ex;
            }
            try
            {
                logger.LogDebug($"Adding onlineform - products {products.Count()}");
                await this.host.OnlineForms.Products.BulkAdd(addedForm.CommonId, products);
            }
            catch (Exception ex)
            {
                logger.LogCritical("Failed to add products", ex);
                throw ex;
            }

            // unfurl the FBO Types
            var contactNotes = new List <(string text, int tags)>();

            foreach (var contact in contacts)
            {
                var contactAddressNote = NotifierAddress(contact.Addresses, countries);
                var FboTypes           = String.Join("\n", host.OnlineForms.Products.Fbos.GetNamesFromId(contact.FbosTypes.ToList()));
                var updatedNoteText    = $"Product Address\nProduct : {contact.ProductName}\nFBOTypes : {FboTypes}\nAddress : {contactAddressNote.Note}";
                contactNotes.Add((updatedNoteText, 0));
            }

            try
            {
                logger.LogDebug($"Adding onlineform - notes");
                await this.host.OnlineForms.Notes.BulkAdd(addedForm.CommonId, contactNotes);
            }
            catch (Exception ex)
            {
                logger.LogCritical("Failed to add notes", ex);
                throw ex;
            }
        }
Exemplo n.º 2
0
 public SimsNote NotifierAddress(ExternalAddress externalAddress, List <Country> countries) => new SimsNote
 {
     Note = $"{externalAddress.AddressLine1}\n{externalAddress.AddressLine2}\n{externalAddress.County}\n{externalAddress.TownCity}\n{externalAddress.Postcode}\n{countries.FirstOrDefault(cnt => cnt.Id == externalAddress.CountryId)?.Title}"
 };