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)); }