public override async Task <SaveCustomerAttributeResponse> Handle(SaveCustomerAttributeRequest request, CancellationToken cancellationToken) { bool isNewAttribute = false; var attribute = _attributeService.GetAttribute( await _cacheProvider.GetAttributes(cancellationToken), request.Property); CustomerAttribute foundCustomerAttribute; if (attribute == null) { attribute = await _attributeService .SaveAttribute(new Attribute { Key = request.Property }, false, cancellationToken); isNewAttribute = true; } CustomerAttributeDto customerAttribute = new CustomerAttributeDto { CustomerId = request.CustomerId, Value = request.Value }; foundCustomerAttribute = await _customerAttributeService .GetCustomerAttribute(attribute.Id, request.CustomerId, cancellationToken); if (foundCustomerAttribute != null) { customerAttribute.Id = foundCustomerAttribute.Id; customerAttribute.Created = foundCustomerAttribute.Created; } var encryptedCustomerAttribute = await Encryption .Encrypt <CustomerAttributeDto, CustomerAttribute>(customerAttribute); if (isNewAttribute) { encryptedCustomerAttribute.Attribute = attribute; } else { encryptedCustomerAttribute.AttributeId = attribute.Id; } var result = await _customerAttributeService .SaveCustomerAttribute(encryptedCustomerAttribute, cancellationToken); customerAttribute = await Encryption .Decrypt <CustomerAttribute, CustomerAttributeDto>(result); return(Response.Success <SaveCustomerAttributeResponse>(customerAttribute, config => { config.IsNewAttribute = isNewAttribute; config.AttributeId = attribute.Id; })); }
public override async Task <GetCustomerAttributesResponse> Handle(GetCustomerAttributeRequest request, CancellationToken cancellationToken) { var attributes = await _cacheProvider.GetAttributes(cancellationToken); var customerAttributes = await _customerAttributeService.GetCustomerAttributes(request.CustomerId, cancellationToken); customerAttributes.ForEach(customerAttribute => customerAttribute.Attribute = _attributeService .GetAttribute(attributes, customerAttribute.Id)); var decryptedCustomAttributes = await Encryption.Decrypt <CustomerAttribute, CustomerAttributeDto>(customerAttributes); return(Response.Success <GetCustomerAttributesResponse>(decryptedCustomAttributes)); }
public IChatMessage GetResponse(long interactionId, IChatMessage message) { using (_trace.scope()) { try { /* FAIR WARNING * This bot is a fairly bad idea to actually expose to users. It's meant as a testing * bot to test the get/set attribute functionality. Set system attributes at your own risk. */ Console.WriteLine("[{0}] - GetResponse ({1})", BotName, interactionId); var textMessage = message as TextChatMessage; if (textMessage == null) { return(null); } var pieces = textMessage.Text.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (pieces.Length == 0) { return(null); } // Check for set if (pieces.Length == 1) { var setData = pieces[0].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (setData.Length == 2) { _attributeService.SetAttribute(interactionId, setData[0], setData[1]); return(new TextChatMessage { Text = "Attribute set!" }); } // Get attribute var attr = _attributeService.GetAttribute(interactionId, pieces[0]); return(new TextChatMessage { Text = pieces[0] + "=" + attr }); } // Get attributes var attrs = _attributeService.GetAttributes(interactionId, pieces); return(new TextChatMessage { Text = attrs.Select(a => a.Key + "=" + a.Value) .Aggregate((a, b) => a + Environment.NewLine + b) }); } catch (Exception ex) { _trace.exception(ex); return(new TextChatMessage { Text = "I'm sorry. I failed. Will you give me another chance?" }); } } }
public Type GetViewModelTypeForPage <T>() where T : Page { return(attributeService.GetAttribute <ViewModelAttribute, T>()?.ViewModelType); }