public async Task <ContactPayload> ContactRawPayload(string id)
        {
            var payload = new ContactPayload();

            var request = new ContactPayloadRequest();

            request.Id = id;

            var response = await grpcClient.ContactPayloadAsync(request);

            if (response != null)
            {
                payload = new ContactPayload()
                {
                    Address   = response.Address,
                    Alias     = response.Alias,
                    Avatar    = response.Avatar,
                    City      = response.City,
                    Friend    = response.Friend,
                    Gender    = (PuppetModel.ContactGender)response.Gender,
                    Id        = response.Id,
                    Name      = response.Name,
                    Province  = response.Province,
                    Signature = response.Signature,
                    Star      = response.Star,
                    Type      = (PuppetModel.ContactType)response.Type,
                    Weixin    = response.Weixin,
                };
            }
            return(payload);
        }
        protected override async Task <ContactPayload> ContactRawPayload(string contactId)
        {
            var request = new ContactPayloadRequest()
            {
                Id = contactId
            };
            var response = await grpcClient.ContactPayloadAsync(request);

            var payload = new ContactPayload()
            {
                Id        = response.Id,
                Name      = response.Name,
                Address   = response.Address,
                Alias     = response.Alias,
                Avatar    = response.Avatar,
                City      = response.City,
                Friend    = response.Friend,
                Gender    = (Schemas.ContactGender)response.Gender,
                Province  = response.Province,
                Signature = response.Signature,
                Star      = response.Star,
                Type      = (Schemas.ContactType)response.Type,
                Weixin    = response.Weixin,
            };

            return(payload);
        }
Exemplo n.º 3
0
        public async Task <IContactAppService> LoadInfo(string id)
        {
            ContactPayload = await _cacheContactPayload.GetOrAddAsync(id,
                                                                      async() => await _puppetService.ContactRawPayload(id),
                                                                      () => new DistributedCacheEntryOptions
            {
                AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(CacheConst.CacheGlobalExpirationTime)
            });

            return(this);
        }
Exemplo n.º 4
0
        public async Task PostEmptyFieldReturns204Result()
        {
            var payload = new ContactPayload()
            {
                email     = "*****@*****.**",
                name      = "",//This space intentionally left blank.
                message   = "We are running unit tests!",
                recaptcha = "NotGoingToWork"
            };

            var result = await _controller.Post(payload);

            Assert.IsAssignableFrom <BadRequestResult>(result);
        }
Exemplo n.º 5
0
        public async Task PostReturns204Result()
        {
            var payload = new ContactPayload()
            {
                email     = "*****@*****.**",
                name      = "Unit Tester",
                message   = "We are running unit tests!",
                recaptcha = "NotGoingToWork"
            };

            var result = await _controller.Post(payload);

            Assert.IsAssignableFrom <ActionResult>(result);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Post([FromForm] ContactPayload payload)
        {
            if (
                !String.IsNullOrWhiteSpace(payload.name) &&
                !String.IsNullOrWhiteSpace(payload.email) &&
                !String.IsNullOrWhiteSpace(payload.message) &&
                !String.IsNullOrWhiteSpace(payload.recaptcha)
                )
            {
                await _emailService.SendContactMessage(payload.name, payload.email, payload.message, payload.recaptcha);

                return(NoContent());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 7
0
        public async Task Ready(string contactId, bool forceSync = false)
        {
            if (!forceSync && IsReady)
            {
                Logger.LogInformation("ready() isReady() true");
                return;
            }
            try
            {
                await ContactPayloadDirty(contactId);

                ContactPayload = await LoadContactPayload(contactId);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "contact ready() failed");
            }
        }
 protected override async Task <ContactPayload> ContactRawPayloadParser(ContactPayload rawPayload)
 {
     return(rawPayload);
 }
Exemplo n.º 9
0
        public AccountDocument GetTransformedDocument(TradingAccountPayload payload, List <SyncFeedEntryLink> links)
        {
            AccountDocument    document       = new AccountDocument();
            tradingAccounttype tradingAccount = payload.TradingAccount;

            document.addresses = new AddressDocumentCollection();
            if (tradingAccount.postalAddresses != null && tradingAccount.postalAddresses != null)
            {
                foreach (postalAddresstype postalAddress in tradingAccount.postalAddresses)
                {
                    PostalAddressPayload postalAdressPayload = new PostalAddressPayload();
                    postalAdressPayload.PostalAddresstype = postalAddress;
                    postalAdressPayload.SyncUuid          = StringToGuid(postalAddress.uuid);
                    AddressDocument address = _postalAdressTransformation.GetTransformedDocument(postalAdressPayload, Helper.ReducePayloadPath(links));
                    document.addresses.Add(address);
                }
            }
            bool hasMainAdress = false;

            for (int index = 0; index < document.addresses.documents.Count; index++)
            {
                AddressDocument address = document.addresses.documents[index] as AddressDocument;
                if ((address.primaryaddress.Value != null) && (address.primaryaddress.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainAdress = true;
                }
            }
            if ((!hasMainAdress) && (document.addresses.documents.Count > 0))
            {
                AddressDocument address = document.addresses.documents[0] as AddressDocument;
                address.primaryaddress.Value = "true";
            }
            if (String.IsNullOrEmpty(payload.LocalID))
            {
                document.CrmId = payload.SyncUuid.ToString();//
                document.Id    = GetLocalId(payload.SyncUuid);
            }
            else
            {
                document.Id = payload.LocalID;
            }
            document.currencyid.Value = tradingAccount.currency;
            document.emails           = new EmailsDocumentCollection();
            if (tradingAccount.emails != null && tradingAccount.emails != null)
            {
                foreach (emailtype email in tradingAccount.emails)
                {
                    EmailPayload emailPayload = new EmailPayload();
                    emailPayload.Emailtype = email;
                    emailPayload.SyncUuid  = StringToGuid(email.uuid);
                    EmailDocument emailDocument = _emailAdressTransformation.GetTransformedDocument(emailPayload, Helper.ReducePayloadPath(links));
                    document.emails.Add(emailDocument);
                }
            }
            document.name.Value = tradingAccount.name;
            // ????? document.onhold
            document.people = new PeopleDocumentCollection();
            if (tradingAccount.contacts != null && tradingAccount.contacts != null)
            {
                foreach (contacttype contact in tradingAccount.contacts)
                {
                    ContactPayload contactPayload = new ContactPayload();
                    contactPayload.Contacttype = contact;
                    contactPayload.SyncUuid    = StringToGuid(contact.uuid);
                    PersonDocument person = _contactTransformation.GetTransformedDocument(contactPayload, Helper.ReducePayloadPath(links));
                    document.people.Add(person);
                }
            }
            bool hasMainPerson = false;

            for (int index = 0; index < document.people.documents.Count; index++)
            {
                PersonDocument person = document.people.documents[index] as PersonDocument;
                if ((person.primaryperson.Value != null) && (person.primaryperson.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainPerson = true;
                }
            }
            if ((!hasMainPerson) && (document.people.documents.Count > 0))
            {
                PersonDocument person = document.people.documents[0] as PersonDocument;
                person.primaryperson.Value = "true";
            }

            document.phones = new PhonesDocumentCollection();
            if (tradingAccount.phones != null && tradingAccount.phones != null)
            {
                foreach (phoneNumbertype phoneNumber in tradingAccount.phones)
                {
                    PhoneNumberPayload phoneNumberPayload = new PhoneNumberPayload();
                    phoneNumberPayload.PhoneNumbertype = phoneNumber;
                    //phoneNumberPayload.SyncUuid = GetUuid(phoneNumber.applicationID);
                    PhoneDocument phone = _phoneNumberTransformation.GetTransformedDocument(phoneNumberPayload, Helper.ReducePayloadPath(links));
                    document.phones.Add(phone);
                }
            }
            document.customerSupplierFlag.Value = tradingAccount.customerSupplierFlag;
            return(document);
        }
Exemplo n.º 10
0
 protected abstract Task <ContactPayload> ContactRawPayloadParser(ContactPayload rawPayload);
 public ContactPayload ContactRawPayloadParser(ContactPayload payload)
 {
     return(payload);
 }
Exemplo n.º 12
0
        public override SdataTransactionResult Add(PayloadBase payload, List <SyncFeedEntryLink> links)
        {
            string accountUuid = "";
            SdataTransactionResult sdTrResult;
            ContactPayload         contactPayload = payload as ContactPayload;

            if ((contactPayload.Contacttype.primacyIndicatorSpecified) &&
                contactPayload.Contacttype.primacyIndicator)
            {
                // is primary
            }
            else
            {
                sdTrResult              = new SdataTransactionResult();
                sdTrResult.HttpMessage  = "Only primary contacts suported";
                sdTrResult.HttpMethod   = "POST";
                sdTrResult.HttpStatus   = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = SupportedResourceKinds.contacts;
                sdTrResult.Uuid         = StringToGuid(contactPayload.Contacttype.uuid);
                return(sdTrResult);
            }
            foreach (SyncFeedEntryLink link in links)
            {
                if ((!String.IsNullOrEmpty(link.PayloadPath)) &&
                    link.PayloadPath.Equals(_tradingAccountUuidPayloadPath,
                                            StringComparison.InvariantCultureIgnoreCase))
                {
                    accountUuid = link.Uuid;
                    break;
                }
            }



            if (String.IsNullOrEmpty(accountUuid))
            {
                sdTrResult              = new SdataTransactionResult();
                sdTrResult.HttpMessage  = "Trading Account UUID was missing";
                sdTrResult.HttpMethod   = "POST";
                sdTrResult.HttpStatus   = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid         = StringToGuid(contactPayload.Contacttype.uuid);
                return(sdTrResult);
            }


            string accountId = GetTradingAccountLocalId(accountUuid);

            if (String.IsNullOrEmpty(accountId))
            {
                sdTrResult              = new SdataTransactionResult();
                sdTrResult.HttpMessage  = String.Format("Trading Account UUID {0} was not linked", accountUuid);
                sdTrResult.HttpMethod   = "POST";
                sdTrResult.HttpStatus   = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid         = StringToGuid(contactPayload.Contacttype.uuid);
                return(sdTrResult);
            }


            Account         account         = new Account();
            Identity        accIdentity     = new Identity(account.EntityName, accountId);
            AccountDocument accountDocument = account.GetDocument(
                accIdentity, _emptyToken, _context.Config) as AccountDocument;

            Document document = null;
            bool     doAdd    = false;

            if (accountDocument.people.documents.Count == 0)
            {
                document = GetTransformedDocument(payload, links);
                accountDocument.CrmId = GetTradingAccountUuid(document.Id);
                accountDocument.addresses.documents.Add(document);
                doAdd = true;
            }
            else
            {
                PersonDocument personDocument = accountDocument.people.documents[0] as PersonDocument;
                if (personDocument.firstname.IsNull &&
                    personDocument.lastname.IsNull)
                {
                    document = GetTransformedDocument(payload, links);
                    accountDocument.CrmId = GetTradingAccountUuid(document.Id);
                    accountDocument.addresses.documents[0] = document;
                    doAdd = true;
                }
            }
            if (!doAdd)
            {
                sdTrResult              = new SdataTransactionResult();
                sdTrResult.HttpMessage  = "Trading Account has already a primary contact";
                sdTrResult.HttpMethod   = "POST";
                sdTrResult.HttpStatus   = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid         = StringToGuid(contactPayload.Contacttype.uuid);
                return(sdTrResult);
            }

            List <TransactionResult> transactionResults = new List <TransactionResult>();

            account.Update(accountDocument, _context.Config, ref transactionResults);
            sdTrResult = Helper.GetSdataTransactionResult(transactionResults,
                                                          _context.OriginEndPoint, SupportedResourceKinds.tradingAccounts);
            if (sdTrResult != null)
            {
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.HttpMessage  = "POST";
            }
            return(sdTrResult);
        }