Exemple #1
0
        public async Task <GetPersonByIdResponse> GetPersonById(GetPersonByIdRequest request)
        {
            const string userMessage = "Unable to get Person";
            var          response    = new GetPersonByIdResponse();

            try
            {
                var p = await _dbContext.People.FindAsync(request.Id);

                if (p == null)
                {
                    response.Success            = false;
                    response.FailureInformation = "Unable to find requested person";
                }
                else
                {
                    response.Success = true;
                    response.Person  = new PersonInformation
                    {
                        Id        = p.Id,
                        FirstName = p.FirstName,
                        LastName  = p.LastName,
                        Email     = p.Email,
                        Photo     = p.Photo
                    };
                }
                return(response);
            }
            catch (Exception ex)
            {
                //log the exception..
                //In production we wouldn't return the exception detail
                return(new GetPersonByIdResponse
                {
                    Success = false,
                    FailureInformation = userMessage + " | " + ex.Message
                });
            }
        }
 //api/data/GetPersonById?Id=5FC99CFB-52E6-4ECF-B77A-FE927F325C18
 public async Task <GetPersonByIdResponse> GetPersonById([FromQuery] GetPersonByIdRequest request)
 {
     return(await _repository.GetPersonById(request));
 }