예제 #1
0
        public ActionResult Email(string guid)
        {
            var indulgence = _indulgeMeService.GetIndulgenceByGuid(guid);

            try
            {
                _indulgenceEmailer.Send(indulgence, string.Format("{0}/indulgence/pdf/{1}",
                                                                  ConfigurationManager.AppSettings["WebsiteHostName"], indulgence.Guid));
            }
            catch (Exception ex)
            {
                _log.Error("Failed to send email", ex);
                throw;
            }

            return(new ContentResult()
            {
                Content = "sent",
                ContentType = "text/plain",
                ContentEncoding = Encoding.UTF8
            });
        }
예제 #2
0
        // GET: Sdi
        public async Task <ActionResult> Return(string guid, int?donationId)
        {
            try
            {
                if (!donationId.HasValue)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                var config = new ClientConfiguration(
                    ConfigurationManager.AppSettings["JgApiBaseUrl"],
                    ConfigurationManager.AppSettings["JGApiKey"],
                    1);

                var client = new JustGivingClient(config);

                DonationStatus donationStatus = null;
                try
                {
                    donationStatus = client.Donation.RetrieveStatus(donationId.Value);
                }
                catch
                {
                }

                if ((donationStatus != null && donationStatus.Status == "Accepted") ||
                    ConfigurationManager.AppSettings["SkipDonationReferenceCheck"] == "true")
                {
                    if (donationStatus != null)
                    {
                        _indulgeMeService.Absolve(guid, donationStatus.DonationId, donationStatus.DonationRef,
                                                  donationStatus.Amount,
                                                  donationStatus.Reference);
                    }
                    else if (ConfigurationManager.AppSettings["SkipDonationReferenceCheck"] == "true")
                    {
                        _indulgeMeService.Absolve(guid, 1, "1", 10, "not-a-real-donation");
                    }

                    var indulgence = _indulgeMeService.GetIndulgenceByGuid(guid);
                    _indulgeMeService.GenerateIndulgence(indulgence,
                                                         System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "fonts"),
                                                         System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Content"));

                    await _indulgenceEmailer.Send(indulgence, ConfigurationManager.AppSettings["IndulgencePdfRelativePath"]);

                    _indulgeMeService.Tweet(indulgence);

                    TempData["absolved"] = guid;

                    ControllerContext.RequestContext.HttpContext.Cache.Remove("siteInfo");
                    ControllerContext.RequestContext.HttpContext.Response.RemoveOutputCacheItem(Url.Action("GetLatest",
                                                                                                           "Api"));

                    ViewData["ShowBlessing"] = true;
                    return(RedirectToAction("Index", "Indulgence", new { guid = guid }));
                }

                return(HttpNotFound());
            }
            catch (Exception ex)
            {
                _log.Error("unhandled error returning from SDI", ex);
                return(new ContentResult()
                {
                    Content = ex.Message + "\r\n" + ex.StackTrace,
                    ContentEncoding = Encoding.UTF8,
                    ContentType = "text/plain"
                });
            }
        }
예제 #3
0
        public ActionResult Absolve(int id, int?donationId)
        {
            var config = new ClientConfiguration(
                "https://api.staging.justgiving.com/",
                ConfigurationManager.AppSettings["JGApiKey"],
                1);
            var client = new JustGivingClient(config);

            DonationStatus donation = null;

            if (donationId.HasValue)
            {
                donation = client.Donation.RetrieveStatus(donationId.Value);
            }
            else
            {
                donationId = 1;
                donation   = new DonationStatus()
                {
                    Amount = new decimal(r.NextDouble() * 100), DonationId = 1, Reference = "1"
                };
            }

            var indulgence = MvcApplication.CurrentSession.Load <Indulgence>(id.ToRavenDbId("indulgences"));

            if (indulgence == null)
            {
                return(new HttpNotFoundResult());
            }

            indulgence.IsBlessed = true;
            if (donation != null)
            {
                indulgence.AmountDonated        = donation.Amount;
                indulgence.JustGivingDonationId = donationId.Value;
                indulgence.DonationReference    = donation.Reference;
            }

            var sin = MvcApplication.CurrentSession.Load <Sin>(indulgence.SinId);

            sin.TotalDonationCount++;
            if (donation != null)
            {
                sin.TotalDonated += donation.Amount;
            }

            MvcApplication.CurrentSession.SaveChanges();

            MvcApplication.TotalDonated = MvcApplication.CurrentSession
                                          .Query <Indulgence>("BlessedIndulgences").ToList().Sum(a => a.AmountDonated);

            string storagePath   = HostingEnvironment.MapPath("~/content/indulgences");
            string pdfFilename   = string.Format("{0}/indulgence.pdf", indulgence.Id.IdValue());
            string imageFilename = string.Format("{0}/indulgence.png", indulgence.Id.IdValue());

            pdfFilename   = Path.Combine(storagePath, pdfFilename);
            imageFilename = Path.Combine(storagePath, imageFilename);

            _indulgeMeService.GenerateIndulgence(pdfFilename, imageFilename, indulgence,
                                                 HostingEnvironment.MapPath("~/content"), HostingEnvironment.MapPath("~/content"));

            // if the user supplied an email address send the pdf to them
            if (!string.IsNullOrWhiteSpace(indulgence.DonorEmailAddress))
            {
                string donorEmailAddress = indulgence.DonorEmailAddress;
                string donorName         = string.IsNullOrWhiteSpace(indulgence.Name) ? "" : indulgence.Name;
                indulgenceEmailer.Send(indulgence, pdfFilename);
            }

            try
            {
                // add the indulgence to the queue to tweet
                _tweetOutbox.Add(indulgence);
            }
            catch (Exception e)
            {
                log.Error("Could not tweet!", e);
            }

            TempData["absolutionId"] = id;

            // invalidate cache
            ControllerContext.RequestContext.HttpContext.Cache.Remove("siteInfo");
            ControllerContext.RequestContext.HttpContext.Response.RemoveOutputCacheItem(Url.Action("GetLatest", "Api"));

            return(RedirectToAction("Index", "Indulgence", new { id = indulgence.Id.IdValue() }));
        }