コード例 #1
0
        public IHttpActionResult GetRecurringGifts([FromUri(Name = "impersonateDonorId")] int?impersonateDonorId = null)
        {
            return(Authorized(token =>
            {
                var impersonateUserId = impersonateDonorId == null ? string.Empty : _mpDonorService.GetEmailViaDonorId(impersonateDonorId.Value).Email;

                try
                {
                    var recurringGifts = (impersonateDonorId != null)
                        ? _impersonationService.WithImpersonation(token,
                                                                  impersonateUserId,
                                                                  () =>
                                                                  _donorService.GetRecurringGiftsForAuthenticatedUser(token))
                        : _donorService.GetRecurringGiftsForAuthenticatedUser(token);

                    if (recurringGifts == null || !recurringGifts.Any())
                    {
                        return (RestHttpActionResult <ApiErrorDto> .WithStatus(HttpStatusCode.NotFound, new ApiErrorDto("No matching donations found")));
                    }

                    return (Ok(recurringGifts));
                }
                catch (UserImpersonationException e)
                {
                    return (e.GetRestHttpActionResult());
                }
            }));
        }