Beispiel #1
0
        public async Task <IEnumerable <Person> > GetPersonsAsync()
        {
            var request = new GetPersonsRequest();
            var result  = await clientProxy.Execute(client => client.GetPersonsAsync(request));

            return(result.GetPersonsResult.AsEnumerable().Select(MapPersonDtoToPerson));
        }
Beispiel #2
0
        public IEnumerable <Person> GetPersons()
        {
            var request = new GetPersonsRequest();
            var result  = clientProxy.Execute(client => client.GetPersons(request));

            return(result.GetPersonsResult.AsEnumerable().Select(MapPersonDtoToPerson));
        }
Beispiel #3
0
        public async Task <IActionResult> GetAll([FromQuery] GetPersonsRequest request)
        {
            try
            {
                var persons = await personService.GetAllAsync();

                var response = new GetPersonsResponse
                {
                    Items = mapper.Map <List <PersonDto> >(persons),
                    Total = persons.Count
                };

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(ExceptionResult(e));
            }
        }
        public Task <IEnumerable <Person> > Handle(GetPersonsRequest request, CancellationToken cancellationToken)
        {
            var persons = _personRepository.GetAll().Where(p => request.Ids.Contains(p.Id));

            if (persons.Count() == request.Ids.Count())
            {
                return(Task.FromResult(persons));
            }

            var missingPersons = GetMissingPersonsId(persons, request.Ids);

            if (missingPersons.Count() == 1)
            {
                throw new DomainObjectNotFoundException($"Person with id '{missingPersons.Single()}' not found");
            }
            else
            {
                throw new DomainObjectNotFoundException($"Persons with id '{string.Join(',',missingPersons)}' not found");
            }
        }