Example #1
0
        public override async Task <SearchCustomersByKeywordResponse> Handle(SearchCustomersByKeywordRequest request, CancellationToken cancellationToken)
        {
            var characters = _characterHashService.GetCharacters(request.Keyword).Distinct();

            var characterHashes = _characterHashService.GetHashes(_hashes, characters);

            var customers = await _customerHashService
                            .GetCustomersByHash(characterHashes, cancellationToken,
                                                configure => { configure.PageNumber         = request.PageNumber;
                                                               configure.MaximumRowsPerPage = request.MaximumRowsPerPage;
                                                               configure.UseAsync           = true; });

            var decryptedCustomers = await Encryption.Decrypt <Customer, CustomerDto>(customers);

            return(Response.Success <SearchCustomersByKeywordResponse>(decryptedCustomers));
        }
Example #2
0
        public override async Task <SaveCustomerHashesResponse> Handle(SaveCustomerHashesRequest request, CancellationToken cancellationToken)
        {
            async Task <IEnumerable <CustomerHash> > GetCustomerHashes() =>
            await _customerHashService.GetCustomerHashes(request.CustomerId, cancellationToken);

            var customerHashes = await GetCustomerHashes();

            var savedHashes = new List <CustomerHash>();

            var characterHashes = _characterHashService.GetHashes(_hashes, request.Characters);

            foreach (var characterHash in characterHashes)
            {
                var customerHash = _customerHashService.GetCustomerHash(customerHashes, characterHash.Hash.Value, characterHash.Index);

                if (customerHash != null)
                {
                    continue;
                }

                customerHash = await _customerHashService.SaveCustomerHash(new CustomerHash
                {
                    CustomerId = request.CustomerId,
                    Index      = characterHash.Index,
                    Hash       = characterHash.Hash.Value.ToArray()
                }, false, cancellationToken);

                savedHashes.Add(customerHash);

                customerHashes = customerHashes.Append(customerHash);
            }

            if (savedHashes.Any())
            {
                await _customerHashService.CommitChanges(cancellationToken);
            }

            return(Response.Success <SaveCustomerHashesResponse>(savedHashes.ToArray()));
        }