示例#1
0
        public IHttpActionResult SearchGroups([FromUri] int[] groupTypeIds,
                                              [FromUri(Name = "s")] string keywords   = null,
                                              [FromUri(Name = "loc")] string location = null,
                                              [FromUri(Name = "id")] int?groupId      = null)
        {
            try
            {
                var result = _groupToolService.SearchGroups(groupTypeIds, keywords, location, groupId);
                if (result == null || !result.Any())
                {
                    return(RestHttpActionResult <List <GroupDTO> > .WithStatus(HttpStatusCode.NotFound, new List <GroupDTO>()));
                }

                return(Ok(result));
            }
            catch (Exception ex)
            {
                var apiError = new ApiErrorDto("Error searching for group", ex);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }
        }
示例#2
0
        public IHttpActionResult GetPledges()
        {
            return(Authorized(token =>
            {
                try
                {
                    var pledges = _donorService.GetCapitalCampaignPledgesForAuthenticatedUser(token);

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

                    return (Ok(pledges));
                }
                catch (UserImpersonationException e)
                {
                    return (e.GetRestHttpActionResult());
                }
            }));
        }
示例#3
0
        public IHttpActionResult CreateDonor([FromBody] CheckScannerCheck checkDetails)
        {
            return(Authorized(token =>
            {
                var authResult = CheckToken(token);
                if (authResult != null)
                {
                    return (authResult);
                }

                try
                {
                    var result = _checkScannerService.CreateDonor(checkDetails);
                    return (Ok(result));
                }
                catch (PaymentProcessorException e)
                {
                    return (RestHttpActionResult <ApiErrorDto> .WithStatus(HttpStatusCode.MethodNotAllowed, new ApiErrorDto("Could not create checking account at payment processor", e)));
                }
            }));
        }
示例#4
0
        public IHttpActionResult GetDonations(string donationYear = null,
                                              int?limit           = null,
                                              [FromUri(Name = "softCredit")] bool?softCredit = null,
                                              [FromUri(Name = "impersonateDonorId")] int?impersonateDonorId = null,
                                              bool?includeRecurring = true)
        {
            return(Authorized(token =>
            {
                var impersonateUserId = impersonateDonorId == null ? string.Empty : _mpDonorService.GetEmailViaDonorId(impersonateDonorId.Value).Email;
                try
                {
                    var donations = (impersonateDonorId != null)
                        ? _impersonationService.WithImpersonation(token,
                                                                  impersonateUserId,
                                                                  () =>
                                                                  _gatewayDonationService.GetDonationsForAuthenticatedUser(token, donationYear, limit, softCredit, includeRecurring))
                        : _gatewayDonationService.GetDonationsForAuthenticatedUser(token, donationYear, limit, softCredit, includeRecurring);

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

                    return (Ok(donations));
                }
                catch (UserImpersonationException e)
                {
                    return (e.GetRestHttpActionResult());
                }
                catch (Exception e)
                {
                    var msg = "DonationController: GetDonations " + donationYear + ", " + impersonateDonorId;
                    _logger.Error(msg, e);
                    return (RestHttpActionResult <ApiErrorDto> .WithStatus(HttpStatusCode.InternalServerError, new ApiErrorDto("Unexpected exception happens at server side")));
                }
            }));
        }
        public IHttpActionResult GetDonationYears([FromUri(Name = "impersonateDonorId")] int?impersonateDonorId = null)
        {
            return(Authorized(token =>
            {
                var impersonateUserId = impersonateDonorId == null ? string.Empty : _mpDonorService.GetEmailViaDonorId(impersonateDonorId.Value).Email;
                try
                {
                    var donationYears = (impersonateDonorId != null)
                        ? _impersonationService.WithImpersonation(token, impersonateUserId, () => _gatewayDonationService.GetDonationYearsForAuthenticatedUser(token))
                        : _gatewayDonationService.GetDonationYearsForAuthenticatedUser(token);

                    if (donationYears == null || !donationYears.HasYears)
                    {
                        return (RestHttpActionResult <ApiErrorDto> .WithStatus(HttpStatusCode.NotFound, new ApiErrorDto("No donation years found")));
                    }

                    return (Ok(donationYears));
                }
                catch (UserImpersonationException e)
                {
                    return (e.GetRestHttpActionResult());
                }
            }));
        }
示例#6
0
 public RestHttpActionResult <ApiErrorDto> GetRestHttpActionResult()
 {
     return(RestHttpActionResult <ApiErrorDto> .WithStatus(_httpStatusCode, new ApiErrorDto(Message)));
 }