Example #1
0
 public static SocialVM GetSocialVMForCharity(Charity C,  HttpRequestBase Request, UrlHelper Url)
 {
     return new SocialVM()
     {
         Type = SocialVM.SocialType.Charity,
         LinkID = C.ID.ToString(),
         ShareURL = Url.Action("Details", "Charities", new { charityname = C.Name.Replace(" ", "") },protocol: Request.Url.Scheme),
         Blurb = ""
     };
 }
Example #2
0
 public static OpenGraphVM GetOpenGraphVMForCharity(Charity C, HttpRequestBase Request, UrlHelper Url)
 {
     return new OpenGraphVM()
     {
         type = "article",
         title = $"{C.Name} on ChariFit",
         description = C.Description,
         image = C.JustGivingCharityImageURL
     };
 }
Example #3
0
        private static bool ReloadCharityData(Charity _Charity,ApplicationDbContext db)
        {

        if (_Charity==null) throw new ArgumentNullException(nameof(_Charity));
        if (db == null) throw new ArgumentNullException(nameof(db));


        var reloadedData = GetCharityDetailsByJustGivingID(_Charity.JustGivingCharityID);
        var relatedDataJSON = Json.Decode(reloadedData);

        _Charity.JustGivingCharityBlob = reloadedData;
        _Charity.JustGivingCharityImageURL = relatedDataJSON.logoAbsoluteUrl;
        _Charity.JustGivingRegistrationNumber = relatedDataJSON.registrationNumber;
        _Charity.Name = relatedDataJSON.name;
        _Charity.CharityURL = relatedDataJSON.websiteUrl;
        _Charity.Description = relatedDataJSON.description;

        db.SaveChanges();
            return true;

        }
Example #4
0
        public static Charity getOrCreateCharityRecordFromJustGivingCharityID(string JustGivingID)
        {

            JustGivingID = JustGivingID.Replace(" ", "");

            var db = new ApplicationDbContext();

            var charity = db.Charities.FirstOrDefault(c => c.JustGivingCharityID == JustGivingID);

            if (string.IsNullOrEmpty(charity?.JustGivingCharityImageURL))
                    ReloadCharityData(charity, db);
            
            if (charity != null)
                return charity;

            var result = GetCharityDetailsByJustGivingID(JustGivingID);
            if (string.IsNullOrEmpty(result))
                return null;

            var resultJSON = Json.Decode(result);

            var newCharity = new Charity
            {
                JustGivingCharityBlob = result,
                JustGivingCharityID = JustGivingID,
                JustGivingCharityImageURL = resultJSON.logoAbsoluteUrl,
                JustGivingRegistrationNumber = resultJSON.registrationNumber,
                Name = resultJSON.name,
                CharityURL = resultJSON.websiteUrl,
                Description = resultJSON.description
            };

            db.Charities.Add(newCharity);
            db.SaveChanges();
            return newCharity;
        }