public void DownloadPaymentRecords() { ConvictsContext db = new ConvictsContext(); var found = (from payments in db.Payments orderby payments.CreateDate descending select payments).ToList<PaymentRecord>(); paymentsHelper.PaymentRecordCSVExporter.WriteToCSV(found); }
public static ConvictReturnObject registerConvict(string email, string name) { ConvictsContext db = new ConvictsContext(); string returnStatus = "false"; string errorMessage = ""; Convict convict = new Convict(); try { Convict found = db.Convicts.Find(email); if (found == null) { convict = new Convict(); convict.Email = email; convict.Name = name; convict.ModifiedDate = DateTime.Now; convict.Total = "0"; convict.CreateDate = DateTime.Now; convict.ConvictCode = Helper.GenerateConvictCode(); db.Convicts.Add(convict); db.SaveChanges(); } else { convict = found; convict.ModifiedDate = DateTime.Now; db.Entry(found).CurrentValues.SetValues(convict); db.SaveChanges(); } returnStatus = "true"; } catch (Exception ex) { returnStatus = "false"; errorMessage = ex.Message; } ConvictReturnObject returnobj = new ConvictReturnObject(); returnobj.status = returnStatus; returnobj.errorMessage = errorMessage; returnobj.convict = convict; return returnobj; }
public static Convict getConvictDetails(string convictCode) { string[] searchTeamCode = new string[] { convictCode }; // check if team code already exists ConvictsContext db = new ConvictsContext(); var found = from convicts in db.Convicts where searchTeamCode.Contains(convicts.ConvictCode) select convicts; if (found.Count() == 0) { return null; } else { return found.FirstOrDefault(); //Recursive function to find teamcode that is not already taken } }
public static bool doesAccountExist(string email) { ConvictsContext db = new ConvictsContext(); bool doesAccountExist = false; string errorMessage = ""; Convict convict = new Convict(); try { Convict found = db.Convicts.Find(email); if (found != null) { doesAccountExist = true; } } catch (Exception ex) { doesAccountExist = false; errorMessage = ex.Message; } return doesAccountExist; }
/// <summary> /// Generates a unique 4 digit team code. /// /// First 4 characters are random numbers /// </summary> /// <returns></returns> public static string GenerateTeamCode() { StringBuilder builder = new StringBuilder(); builder.Append(RandomNumber(1000, 9999)); string[] searchValue = new string[]{builder.ToString()}; // check if team code already exists ConvictsContext db = new ConvictsContext(); var found = from convicts in db.Convicts where searchValue.Contains(convicts.TeamCode) select convicts; if (found.Count() == 0) { return builder.ToString(); } else { return GenerateTeamCode(); //Recursive function to find teamcode that is not already taken } }
public static PaymentDTO AddPayment(string PaymentEmail, string DonorName, string ReceipientEmail, Double amount, string message, string paymentType, Boolean anonymous, DateTime paymentDate, int transactionID, int invoiceID) { ConvictsContext db = new ConvictsContext(); PaymentRecord payment = new PaymentRecord(); payment.PayerEmail = PaymentEmail; payment.DonorName = DonorName; payment.amount = amount; payment.TeamCode = Helper.getTeamCode(ReceipientEmail); payment.ConvictEmail = ReceipientEmail; payment.PaymentType = paymentType; payment.Message = message; payment.CreateDate = paymentDate; payment.Anonymous = anonymous; payment.TransactionID = transactionID; payment.InvoiceID = invoiceID; string returnStatus = "false"; string errorMessage = ""; try { db.Payments.Add(payment); db.SaveChanges(); returnStatus = "true"; } catch (Exception ex) { returnStatus = "false"; errorMessage = ex.Message; } PaymentDTO returnobj = new PaymentDTO(); returnobj.status = returnStatus; returnobj.errorMessage = errorMessage; return returnobj; }
public static bool doesAccountExist(string email) { ConvictsContext db = new ConvictsContext(); bool doesAccountExist = false; string errorMessage = ""; Convict convict = new Convict(); try { Convict found = db.Convicts.Find(email); if (found != null) { doesAccountExist = true; } } catch (Exception ex) { doesAccountExist = false; errorMessage = ex.Message; } return(doesAccountExist); }
public void addTeamCodeToPaymentRecords() { // check if team code already exists ConvictsContext db = new ConvictsContext(); List <Convict> found = (from convicts in db.Convicts where convicts.TeamCode != null select convicts).ToList(); foreach (var convict in found) { ConvictsContext db1 = new ConvictsContext(); var payment = (from payments in db1.Payments where payments.ConvictEmail == convict.Email select payments).ToList(); foreach (var p in payment) { p.TeamCode = convict.TeamCode; db1.Entry(p).CurrentValues.SetValues(p); } db1.SaveChanges(); } }
public static string getTeamTotal(string teamCode) { string returnValue = "0"; //string teamCode = Helper.getTeamCode(email); string[] searchTeamCode = new string[] { teamCode }; ConvictsContext db = new ConvictsContext(); var found = from payments in db.Payments where searchTeamCode.Contains(payments.TeamCode) select payments; if (found.Count() == 0) { returnValue = "0"; } else { returnValue = found.Sum(P => P.amount).ToString(); } return(returnValue); }
public static string getTeamLeaderboard(string teamType) { string returnStr = "{'status':'true'"; returnStr += ", 'teams': [ "; ConvictsContext db = new ConvictsContext(); var found = (from teams in db.Teams.ToList() where teams.TeamType == teamType orderby Double.Parse(teams.Total) descending select teams).ToList(); { if (found.Count() == 0) { returnStr = "{'status':'false'}"; return returnStr; } else { foreach (var team in found) { returnStr += "{'url': '" + team.TeamURL + "','message': '" + team.TeamName + "','total': '" + team.Total + "'},"; } } } returnStr += "]"; returnStr += "}"; return returnStr; }
public static string getTeamDonations(string teamCode) { string returnStr = "{'status':'true'"; returnStr += ", 'messages': [ "; ConvictsContext db = new ConvictsContext(); var found = from payments in db.Payments where teamCode.Contains(payments.TeamCode) orderby payments.CreateDate descending select payments; if (found.Count() == 0) { returnStr = "{'status':'false'}"; return returnStr; } else { foreach (var p in found) { if (string.IsNullOrEmpty(p.DonorName)) continue; if (p.Anonymous) p.DonorName = "Anonymous"; DonationMessage d = new DonationMessage(); d.date = "" + p.CreateDate.ToShortDateString() + " " + p.CreateDate.ToShortTimeString(); if (p.PaymentType == "convict donation" || p.PaymentType == "cash donation") { Convict foundConvict = Helper.getConvictDetailsByEmail(p.ConvictEmail); d.message = p.DonorName + " posted a $" + p.amount + " bail: " + p.Message; returnStr += "{'date': '" + d.date + "','message': '" + d.message + "'},"; } else if (p.PaymentType == "team donation") { Convict foundConvict = Helper.getConvictDetailsByEmail(p.ConvictEmail); d.message = p.DonorName + " posted a $" + p.amount + " bail: " + p.Message; returnStr += "{'date': '" + d.date + "','message': '" + d.message + "'},"; } else if (p.PaymentType == "team registration" || p.PaymentType == "convict registration" || p.PaymentType == "team member registration") { Convict foundConvict = Helper.getConvictDetailsByEmail(p.ConvictEmail); d.message = foundConvict.Name + " has been jailed and fined $" + p.amount; returnStr += "{'date': '" + d.date + "','message': '" + d.message + "'},"; } else if (p.PaymentType == "general donation") { d.message = p.DonorName + " posted a $" + p.amount + " bail."; returnStr += "{'date': '" + d.date + "','message': '" + d.message + "'},"; } } returnStr += "]"; returnStr += "}"; return returnStr; } //return "{'status':'false'}"; }
public static PaymentRecord getLastPayment() { PaymentRecord returnValue = null; // check if team code already exists ConvictsContext db = new ConvictsContext(); var found = (from payments in db.Payments orderby payments.CreateDate descending select payments); if (found == null ) { returnValue = null; } else { returnValue = found.First<PaymentRecord>(); } return returnValue; }
public static string getEventTotal() { string returnValue = "0"; ConvictsContext db = new ConvictsContext(); var found = from payments in db.Payments select payments; if (found.Count() == 0) { returnValue = "0"; } else { returnValue = Math.Round(found.Sum(P => P.amount)).ToString(); } return returnValue; }
public static string getConvictTotal(string email) { string returnValue = "0"; string[] searchEmail = new string[] { email }; // check if team code already exists ConvictsContext db = new ConvictsContext(); var found = from payments in db.Payments where searchEmail.Contains(payments.ConvictEmail) select payments; if (found.Count() == 0) { returnValue = "0"; } else { returnValue = found.Sum(P => P.amount).ToString(); } return returnValue; }
public void SanitiseDatabaseQuotes() { // check if team code already exists ConvictsContext db = new ConvictsContext(); string sqlCommand = "update paymentrecords set message=replace(message,'''','"'), DonorName=replace(DonorName,'''','"')"; db.Database.ExecuteSqlCommand(sqlCommand); }
public static string getTopTeamLeaders(string teamType) { string returnStr = "{'status':'true'"; returnStr += ", 'teams': [ "; ConvictsContext db = new ConvictsContext(); var found = (from teams in db.Teams.ToList() where teams.TeamType == teamType orderby Double.Parse(teams.Total) descending select teams).ToList(); { if (found.Count() == 0) { returnStr = "{'status':'false'}"; return returnStr; } else for (int i = 0; i <= 4 && i != found.Count(); i++) { returnStr += "{'url': '" + found[i].TeamURL + "','message': '" + found[i].TeamName + " - $" + found[i].Total + "'},"; } } returnStr += "]"; returnStr += "}"; return returnStr; }
public void addTeamCodeToPaymentRecords() { // check if team code already exists ConvictsContext db = new ConvictsContext(); List<Convict> found = (from convicts in db.Convicts where convicts.TeamCode != null select convicts).ToList(); foreach (var convict in found) { ConvictsContext db1 = new ConvictsContext(); var payment = (from payments in db1.Payments where payments.ConvictEmail == convict.Email select payments).ToList(); foreach (var p in payment) { p.TeamCode = convict.TeamCode; db1.Entry(p).CurrentValues.SetValues(p); } db1.SaveChanges(); } }
public void CalculateConvictTotals() { // check if team code already exists ConvictsContext db = new ConvictsContext(); List<Convict> found = (from convicts in db.Convicts select convicts).ToList(); foreach (var convict in found) { try { ConvictsContext db1 = new ConvictsContext(); var total = (from payments in db1.Payments where payments.ConvictEmail == convict.Email select payments.amount).Sum(); convict.Total = total.ToString(); db.Entry(convict).CurrentValues.SetValues(convict); } catch (Exception ex) { Console.Write(ex.Message.ToString()); } } db.SaveChanges(); }
public void CalculateTeamTotals() { // check if team code already exists ConvictsContext db = new ConvictsContext(); List<Team> found = (from teams in db.Teams select teams).ToList(); foreach (var team in found) { try { ConvictsContext db1 = new ConvictsContext(); var total = (from payments in db1.Payments where payments.TeamCode == team.TeamCode select payments.amount).Sum(); team.Total = total.ToString(); db.Entry(team).CurrentValues.SetValues(team); } catch (Exception ex) { } } db.SaveChanges(); }
/// <summary> /// Parses the convict page to get the convict's URL /// </summary> public void getConvictURLS() { HtmlWeb webLoad = new HtmlWeb(); HtmlDocument doc = webLoad.Load("http://www.convictsforacause.org.au/support/convict.html"); var meh = from link in doc.DocumentNode.DescendantNodes() where link.Name == "a" && link.Attributes["email"] != null select new { URL = link.Attributes["href"].Value, email = link.Attributes["email"].Value }; // check if team code already exists ConvictsContext db = new ConvictsContext(); List<Convict> found = (from convicts in db.Convicts where convicts.ProfileURL == null select convicts).ToList(); foreach (var convict in found) { foreach(var link in meh ) { if (convict.Email == link.email) { convict.ProfileURL = link.URL; } } db.Entry(convict).CurrentValues.SetValues(convict); } db.SaveChanges(); }
/// <summary> /// Checks for null entries and puts /// </summary> public void getDonorNames() { // populates donor names ConvictsContext db = new ConvictsContext(); List<PaymentRecord> found = (from payments in db.Payments where payments.DonorName == null select payments).ToList(); foreach (var payment in found) { try { convictsforacauseWS.CatalystCRMWebservice CFACWS = new convictsforacauseWS.CatalystCRMWebservice(); convictsforacauseWS.ContactRecord CR = CFACWS.Contact_RetrieveByEmailAddress("*****@*****.**", "convicts2011", 223280, payment.PayerEmail); payment.DonorName = CR.fullName; db.Entry(payment).CurrentValues.SetValues(payment); } catch (Exception) { } } try { db.SaveChanges(); } catch (Exception) { } }
public static string getTeamTotal(string teamCode) { string returnValue = "0"; //string teamCode = Helper.getTeamCode(email); string[] searchTeamCode = new string[] { teamCode }; ConvictsContext db = new ConvictsContext(); var found = from payments in db.Payments where searchTeamCode.Contains(payments.TeamCode) select payments; if (found.Count() == 0) { returnValue = "0"; } else { returnValue = found.Sum(P => P.amount).ToString(); } return returnValue; }
public static string getTopConvictLeaders() { string returnStr = "{'status':'true'"; returnStr += ", 'convicts': [ "; ConvictsContext db = new ConvictsContext(); var found = (from convicts in db.Convicts.ToList() where convicts.TeamType == null orderby Double.Parse( convicts.Total) descending select convicts).ToList(); { if (found.Count() == 0) { returnStr = "{'status':'false'}"; return returnStr; } else for (int i = 0; i <= 4 && i != found.Count(); i++) { returnStr += "{'url': '" +found[i].ProfileURL + "','message': '" + found[i].Name + " - $" + found[i].Total + "'},"; } } returnStr += "]"; returnStr += "}"; return returnStr; }
public static string getTeamCode(string email) { string[] searchEmail = new string[] { email }; // check if team code already exists ConvictsContext db = new ConvictsContext(); var found = from convicts in db.Convicts where searchEmail.Contains(convicts.Email) select convicts; if (found.Count() == 0) { return null; } else { return found.FirstOrDefault().TeamCode; //Recursive function to find teamcode that is not already taken } }
public static TeamDTO registerTeam(string teamCode, string name, string registrationType) { ConvictsContext db = new ConvictsContext(); Team team = new Team(); string returnStatus = "false"; string errorMessage = ""; try { Team found = db.Teams.Find(teamCode); if (found == null) { team.TeamCode = teamCode; team.TeamName = name; team.TeamType = registrationType; team.ModifiedDate = DateTime.Now; team.Total = "0"; team.CreateDate = DateTime.Now; db.Teams.Add(team); db.SaveChanges(); } else { team = found; team.ModifiedDate = DateTime.Now; db.Entry(found).CurrentValues.SetValues(team); db.SaveChanges(); } returnStatus = "true"; } catch (Exception ex) { returnStatus = "false"; errorMessage = ex.Message; } TeamDTO returnobj = new TeamDTO(); returnobj.status = returnStatus; returnobj.errorMessage = errorMessage; returnobj.team = team ; return returnobj; }
public void getTeamURLs() { HtmlWeb webLoad = new HtmlWeb(); HtmlDocument doc = webLoad.Load("http://www.convictsforacause.org.au/support/team.html"); var meh = from link in doc.DocumentNode.DescendantNodes() where link.Name == "a" && link.Attributes["teamcode"] != null select new { URL = link.Attributes["href"].Value, teamcode = link.Attributes["teamcode"].Value }; // check if team code already exists ConvictsContext db = new ConvictsContext(); List<Team> found = (from teams in db.Teams where teams.TeamURL == null select teams).ToList(); foreach (var team in found) { foreach (var link in meh) { if (team.TeamCode == link.teamcode) { team.TeamURL = link.URL; } } db.Entry(team).CurrentValues.SetValues(team); } db.SaveChanges(); }
public static string getAllDonations() { string returnStr = "{'status':'true'"; returnStr += ", 'messages': [ "; ConvictsContext db = new ConvictsContext(); var found = from payments in db.Payments join convicts in db.Convicts on payments.ConvictEmail equals convicts.Email orderby payments.CreateDate descending select new { Payments = payments, Convicts = convicts }; if (found.Count() == 0) { returnStr = "{'status':'false'}"; } else { int i = 0; foreach (var p in found) { if (string.IsNullOrEmpty(p.Payments.DonorName)) continue; if (p.Payments.Anonymous) p.Payments.DonorName = "Anonymous"; i++; DonationMessage d = new DonationMessage(); d.date = "" + p.Payments.CreateDate.ToShortDateString() + " " + p.Payments.CreateDate.ToShortTimeString(); if (p.Payments.PaymentType == "convict donation" || p.Payments.PaymentType == "cash donation") { d.message = p.Payments.DonorName + " posted $" + p.Payments.amount + " bail to " + p.Convicts.Name + ""; returnStr += "{'date': '" + d.date + "','url': '" + p.Convicts.ProfileURL + "','message': '" + d.message + "'},"; } if (p.Payments.PaymentType == "team donation") { Team t = Helper.getTeamDetails(p.Convicts.TeamCode); if (t != null) { d.message = p.Payments.DonorName + " posted a $" + p.Payments.amount + " bail to team " + t.TeamName; returnStr += "{'date': '" + d.date + "','url': '" + t.TeamURL + "','message': '" + d.message + "'},"; } } else if (p.Payments.PaymentType == "team member registration" || p.Payments.PaymentType == "convict registration" || p.Payments.PaymentType == "team registration") { d.message = p.Convicts.Name + " has been jailed and fined $" + p.Payments.amount; returnStr += "{'date': '" + d.date + "','url': '" + p.Convicts.ProfileURL + "','message': '" + d.message + "'},"; } else if (p.Payments.PaymentType == "general donation") { d.message = p.Payments.DonorName + " posted $" + p.Payments.amount + " towards " + p.Convicts.Name + " bail."; returnStr += "{'date': '" + d.date + "','url': '" + p.Convicts.ProfileURL + "','message': '" + d.message + "'},"; } if (i == 10) { break; } } returnStr += "]"; returnStr += "}"; return returnStr; } return "{'status':'false'}"; }
public static List<PaymentRecord> getAllPayments() { ConvictsContext db = new ConvictsContext(); List<PaymentRecord> found = (from payments in db.Payments orderby payments.CreateDate descending select payments).ToList(); return found; }
public static string getTeamDonations(string teamCode) { string returnStr = "{'status':'true'"; returnStr += ", 'messages': [ "; ConvictsContext db = new ConvictsContext(); var found = from payments in db.Payments where teamCode.Contains(payments.TeamCode) orderby payments.CreateDate descending select payments; if (found.Count() == 0) { returnStr = "{'status':'false'}"; return(returnStr); } else { foreach (var p in found) { if (string.IsNullOrEmpty(p.DonorName)) { continue; } if (p.Anonymous) { p.DonorName = "Anonymous"; } DonationMessage d = new DonationMessage(); d.date = "" + p.CreateDate.ToShortDateString() + " " + p.CreateDate.ToShortTimeString(); if (p.PaymentType == "convict donation" || p.PaymentType == "cash donation") { Convict foundConvict = Helper.getConvictDetailsByEmail(p.ConvictEmail); d.message = p.DonorName + " posted a $" + p.amount + " bail: " + p.Message; returnStr += "{'date': '" + d.date + "','message': '" + d.message + "'},"; } else if (p.PaymentType == "team donation") { Convict foundConvict = Helper.getConvictDetailsByEmail(p.ConvictEmail); d.message = p.DonorName + " posted a $" + p.amount + " bail: " + p.Message; returnStr += "{'date': '" + d.date + "','message': '" + d.message + "'},"; } else if (p.PaymentType == "team registration" || p.PaymentType == "convict registration" || p.PaymentType == "team member registration") { Convict foundConvict = Helper.getConvictDetailsByEmail(p.ConvictEmail); d.message = foundConvict.Name + " has been jailed and fined $" + p.amount; returnStr += "{'date': '" + d.date + "','message': '" + d.message + "'},"; } else if (p.PaymentType == "general donation") { d.message = p.DonorName + " posted a $" + p.amount + " bail."; returnStr += "{'date': '" + d.date + "','message': '" + d.message + "'},"; } } returnStr += "]"; returnStr += "}"; return(returnStr); } //return "{'status':'false'}"; }
public static string getConvictLeaderboard() { string returnStr = "{'status':'true'"; returnStr += ", 'convicts': [ "; ConvictsContext db = new ConvictsContext(); var found = (from convicts in db.Convicts.ToList() where convicts.TeamType == null orderby Double.Parse(convicts.Total) descending select convicts).ToList(); { if (found.Count() == 0) { returnStr = "{'status':'false'}"; return returnStr; } else foreach (var convict in found) { returnStr += "{'url': '" + convict.ProfileURL + "','name': '" + convict.Name + "','total': '" + convict.Total + "'},"; } } returnStr += "]"; returnStr += "}"; return returnStr; }
public static string getAllDonations() { string returnStr = "{'status':'true'"; returnStr += ", 'messages': [ "; ConvictsContext db = new ConvictsContext(); var found = from payments in db.Payments join convicts in db.Convicts on payments.ConvictEmail equals convicts.Email orderby payments.CreateDate descending select new { Payments = payments, Convicts = convicts }; if (found.Count() == 0) { returnStr = "{'status':'false'}"; } else { int i = 0; foreach (var p in found) { if (string.IsNullOrEmpty(p.Payments.DonorName)) { continue; } if (p.Payments.Anonymous) { p.Payments.DonorName = "Anonymous"; } i++; DonationMessage d = new DonationMessage(); d.date = "" + p.Payments.CreateDate.ToShortDateString() + " " + p.Payments.CreateDate.ToShortTimeString(); if (p.Payments.PaymentType == "convict donation" || p.Payments.PaymentType == "cash donation") { d.message = p.Payments.DonorName + " posted $" + p.Payments.amount + " bail to " + p.Convicts.Name + ""; returnStr += "{'date': '" + d.date + "','url': '" + p.Convicts.ProfileURL + "','message': '" + d.message + "'},"; } if (p.Payments.PaymentType == "team donation") { Team t = Helper.getTeamDetails(p.Convicts.TeamCode); if (t != null) { d.message = p.Payments.DonorName + " posted a $" + p.Payments.amount + " bail to team " + t.TeamName; returnStr += "{'date': '" + d.date + "','url': '" + t.TeamURL + "','message': '" + d.message + "'},"; } } else if (p.Payments.PaymentType == "team member registration" || p.Payments.PaymentType == "convict registration" || p.Payments.PaymentType == "team registration") { d.message = p.Convicts.Name + " has been jailed and fined $" + p.Payments.amount; returnStr += "{'date': '" + d.date + "','url': '" + p.Convicts.ProfileURL + "','message': '" + d.message + "'},"; } else if (p.Payments.PaymentType == "general donation") { d.message = p.Payments.DonorName + " posted $" + p.Payments.amount + " towards " + p.Convicts.Name + " bail."; returnStr += "{'date': '" + d.date + "','url': '" + p.Convicts.ProfileURL + "','message': '" + d.message + "'},"; } if (i == 10) { break; } } returnStr += "]"; returnStr += "}"; return(returnStr); } return("{'status':'false'}"); }
public string getTeamMembers(string teamCode) { JavaScriptSerializer js = new JavaScriptSerializer(); string strJSON = ""; string results = ""; string[] searchTeamCode = new string[] { teamCode }; ConvictsContext db = new ConvictsContext(); var found = (from Convicts in db.Convicts where searchTeamCode.Contains(Convicts.TeamCode) select Convicts).ToList(); results = "{'convicts': ["; if (found.Count() == 0) { strJSON = js.Serialize("{'teamcode':'0', 'name': ''}"); } else { foreach (Convict c in found) { results += "{'teamcode':'" + c.TeamCode + "', 'url': '" + c.ProfileURL +"', 'name': '" + c.Name + "'},"; } results = results.Remove(results.Length - 1, 1); // remove the last comma from the string } results += "]}"; strJSON = js.Serialize(results); return strJSON; }