public string ConfirmAccount(string emailAddress, string confirmationCode) { SQLLogger.LogInfo(string.Format("Confirming account for emailAddress '{0}' with code '{1}'.", emailAddress, confirmationCode)); if (string.IsNullOrEmpty(emailAddress)) return "<xml><IsValid>0</IsValid><FailureReason>InvalidEmailAddress</FailureReason></xml>"; // perform the operation and get the return code SQL sql = new SQL(); ConfirmAccountResult result = sql.ConfirmAccount(emailAddress, confirmationCode); if (result == ConfirmAccountResult.Success) return "<xml><IsValid>1</IsValid></xml>"; else return string.Format("<xml><IsValid>0</IsValid><FailureReason>{0}</FailureReason></xml>", result.ToString()); }
public string AddFriend(string emailAddress, string friendEmailAddress) { SQLLogger.LogInfo(string.Format("Adding friend '{0}' to '{1}'.", friendEmailAddress, emailAddress)); if (string.IsNullOrEmpty(emailAddress)) return "<xml><IsValid>0</IsValid><FailureReason>InvalidEmailAddress</FailureReason></xml>"; else if (string.IsNullOrEmpty(friendEmailAddress)) return "<xml><IsValid>0</IsValid><FailureReason>InvalidFriendEmailAddress</FailureReason></xml>"; // perform the operation and get the return code SQL sql = new SQL(); string friendNickname, friendMintChipId; AddFriendResult result = sql.AddFriend(emailAddress, friendEmailAddress, out friendNickname, out friendMintChipId); if (result == AddFriendResult.Success) return string.Format("<xml><IsValid>1</IsValid><Nickname>{0}</Nickname><MintChipId>{1}</MintChipId></xml>", SecurityElement.Escape(friendNickname), SecurityElement.Escape(friendMintChipId)); else return string.Format("<xml><IsValid>0</IsValid><FailureReason>{0}</FailureReason></xml>", result.ToString()); }
public string ConfirmFriend(string emailAddress, string friendEmailAddress) { // to save time, for now the only thing that is returned is the MintChipId if things succeed, empty string if it fails for whatever reason SQLLogger.LogInfo(string.Format("ConfirmFriend request for '{0}' and '{1}'.", emailAddress, friendEmailAddress)); SQL sql = new SQL(); return sql.ConfirmFriend(emailAddress, friendEmailAddress); }
public string GetPendingPayments(string emailAddress) { SQLLogger.LogInfo(string.Format("GetPendingPayments({0})", emailAddress)); SQL sql = new SQL(); DataSet ds = sql.GetPendingPayments(emailAddress); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) return ""; // cheat for now and only return the first row DataRow row = ds.Tables[0].Rows[0]; return string.Format("<Payment><BillParticipantId>{0}</BillParticipantId><TransactionId>{1}</TransactionId><BillParticipantEmail>{2}</BillParticipantEmail></Payment>", row["BillParticipantId"], SecurityElement.Escape((string)row["TransactionId"]), SecurityElement.Escape((string)row["BillParticipantEmail"])); }
public string GetUnpaidBills(string emailAddress) { SQLLogger.LogInfo(string.Format("GetUnpaidBills({0})", emailAddress)); #region Sleep // if this was called less than 5 seconds ago, sleep... (this is test code until I do event notification...) DateTime now = DateTime.Now; bool sleep = false; lock (lockObj) { if (getUnpaidBillsCallTable.ContainsKey(emailAddress)) { if (getUnpaidBillsCallTable[emailAddress].AddSeconds(5) > now) { sleep = true; } } } if (sleep) { Thread.Sleep(10000); } #endregion try { SQL sql = new SQL(); DataSet ds = sql.GetUnpaidBills(emailAddress); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) return ""; // cheat for now and only return the first row DataRow row = ds.Tables[0].Rows[0]; return string.Format("<Bill><BillParticipantId>{0}</BillParticipantId><BillId>{1}</BillId><Payment>{2}</Payment><BillOwner>{3}</BillOwner><BillOwnerMintChipId>{4}</BillOwnerMintChipId></Bill>", row["BillParticipantId"], row["BillId"], row["Payment"], SecurityElement.Escape((string)row["UserEmail"]), SecurityElement.Escape((string)row["UserMintChipId"])); } finally { #region Update Call Table now = DateTime.Now; lock (lockObj) { if (getUnpaidBillsCallTable.ContainsKey(emailAddress)) { if (now > getUnpaidBillsCallTable[emailAddress]) getUnpaidBillsCallTable[emailAddress] = now; } else { getUnpaidBillsCallTable[emailAddress] = now; } } #endregion } }
public string GetPendingFriendRequests(string emailAddress) { SQLLogger.LogInfo(string.Format("GetPendingFriendRequests for '{0}'.", emailAddress)); SQL sql = new SQL(); DataSet ds = sql.GetPendingFriendRequests(emailAddress); string requests = string.Empty; if (ds.Tables.Count > 0) { foreach (DataRow row in ds.Tables[0].Rows) { requests += string.Format("<Request>{0}</Request>", SecurityElement.Escape((string)row["Email"])); } } return string.Format("<PendingFriendRequests>{0}</PendingFriendRequests>", requests); }
public string FinalizeReceivedPayment(int billParticipantId) { SQLLogger.LogInfo(string.Format("FinalizeReceivedPayment({0})", billParticipantId)); SQL sql = new SQL(); int result = sql.FinalizeReceivedPayment(billParticipantId); return result.ToString(); }
public string FinalizePayment(int billParticipantId, string transactionId) { SQLLogger.LogInfo(string.Format("Finalize payment {0}, '{1}'.", billParticipantId, transactionId)); SQL sql = new SQL(); sql.FinalizePayment(billParticipantId, transactionId); return ""; }
public string CreateBill(string emailAddress, string friendEmailAddresses, double totalBill, int tipType, double tip, double paymentTotal, double portion) { SQLLogger.LogInfo(string.Format("Creating Bill by '{0}' for '{1}'. Billed amount {2}, tip type {3}, tip {4}, total of {5} paying {6} each.", emailAddress, friendEmailAddresses, totalBill, tipType, tip, paymentTotal, portion)); SQL sql = new SQL(); return sql.CreateBill(emailAddress, friendEmailAddresses, totalBill, tipType, tip, paymentTotal, portion); }
public string CreateAccount(string userName, string nickname, string emailAddress, string mintChipId) { SQLLogger.LogInfo(string.Format("Creating account for user '{0}', nickname '{1}', emailAddress '{2}' and mintChipId '{3}'.", userName, nickname, emailAddress, mintChipId)); if (string.IsNullOrEmpty(userName)) return "<xml><IsValid>0</IsValid><FailureReason>InvalidUserName</FailureReason></xml>"; else if (string.IsNullOrEmpty(userName)) return "<xml><IsValid>0</IsValid><FailureReason>InvalidEmailAddress</FailureReason></xml>"; // check if the user exists already SQL sql = new SQL(); if (sql.IsDuplicateUser(emailAddress)) return "<xml><IsValid>0</IsValid><FailureReason>DuplicateEmailAddress</FailureReason></xml>"; string code = CreateRandomConfirmationCode(); sql.CreateAccount(userName, nickname, emailAddress, code, mintChipId); #region Create Email bool createHTML = false; bool emailCreation = false; string body; if (createHTML) { // tried html and it didn't work, probably just needs more investigation #region HTML body = @"<html><body>Thanks for something Here is your code: 223489 <a href='www.yahoo.com?test=abc>Confirm email</a> Enjoy the app.</body></html>"; #endregion } else { body = string.Format(@"Thanks for creating an account with {0}. To confirm your email address, please enter this code in the application on your device: {1} Enjoy the app.", APP_NAME, code); // Create the web request HttpWebRequest request = WebRequest.Create(string.Format("http://sendgrid.com/api/mail.send.json?to={0}&toname={1}&from=donotreply%40apphb.com&fromname={2}&subject={3}&text={4}&[email protected]&api_key=yg5wbbu6", HttpUtility.UrlEncode(emailAddress), HttpUtility.UrlEncode(userName), HttpUtility.UrlEncode(APP_NAME), HttpUtility.UrlEncode(string.Format("Confirmation code for {0}", APP_NAME)), body)) as HttpWebRequest; // Get response using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { // Get the response stream using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string responseText = reader.ReadToEnd(); if (responseText == "{\"message\":\"success\"}") emailCreation = true; } } // this looks more correct, however the linebreaks don't work //System.Net.HttpWebRequest request = System.Net.WebRequest.Create(string.Format("http://sendgrid.com/api/mail.send.json?to=wolfendaled%40yahoo.com&toname=Dave&from=donotreplywolfendaled%40yahoo.com&fromname=David&subject=Testing123&html={0}&[email protected]&api_key=yg5wbbu6", System.Web.HttpUtility.UrlEncode(body))) as System.Net.HttpWebRequest; } #endregion return string.Format("<xml><IsValid>1</IsValid><EmailCreated>{0}</EmailCreated></xml>", emailCreation ? "1" : "0"); }