/// <summary> /// Determines if the specified user is eligible for this gratuity. Cached for a session. /// </summary> /// <param name="szUser">The username</param> /// <param name="gt">The type of gratuity</param> /// <returns>True if they have spent (net of refunds) the required amount within the required window</returns> public static bool UserQualifies(string szUser, Gratuity.GratuityTypes gt) { Boolean f = false; string szSessionKey = SessionKeyForUser(szUser, gt); System.Web.SessionState.HttpSessionState sess = ((HttpContext.Current != null) ? HttpContext.Current.Session : null); if (sess != null) { object o = sess[szSessionKey]; if (o != null) { return(Convert.ToBoolean(o, CultureInfo.InvariantCulture)); } } List <EarnedGrauity> lst = EarnedGrauity.GratuitiesForUser(szUser, gt); if (lst.Count == 0) { f = false; } else { f = lst[0].ExpirationDate.CompareTo(DateTime.Now) > 0; } if (sess != null) { sess[szSessionKey] = f.ToString(); } return(f); }
public override string ReminderSubject(EarnedGrauity eg) { if (eg == null) { throw new ArgumentNullException("eg"); } switch (eg.CurrentStatus) { default: case EarnedGrauity.EarnedGratuityStatus.OK: // shouldn't even be called in this case return(string.Empty); case EarnedGrauity.EarnedGratuityStatus.ExpiringSoon: if (eg.ReminderCount == 0) { return(Branding.ReBrand(Resources.LocalizedText.gratuityCloudStorageExpiring)); } else { return(string.Empty); } case EarnedGrauity.EarnedGratuityStatus.Expired: if (eg.ReminderCount <= 1) { return(Branding.ReBrand(Resources.LocalizedText.gratuityCloudStorageExpired)); } else { return(string.Empty); } } }
/// <summary> /// If you earn a club-creation activity and you have promotional or inactive clubs, we will re-activate the clubs /// </summary> /// <param name="eg">The earned gratuity</param> public override void GratuityWasEarned(EarnedGrauity eg) { if (eg == null) { throw new ArgumentNullException("eg"); } base.GratuityWasEarned(eg); foreach (Clubs.Club c in Clubs.Club.ClubsCreatedByUser(eg.Username)) { if (c.Status == Clubs.Club.ClubStatus.Promotional || c.Status == Clubs.Club.ClubStatus.Expired) { c.ChangeStatus(Clubs.Club.ClubStatus.OK); } } }
public override string ReminderBody(EarnedGrauity eg) { if (eg == null) { throw new ArgumentNullException("eg"); } Profile pf = eg.UserProfile ?? Profile.GetUser(eg.Username); switch (eg.CurrentStatus) { default: case EarnedGrauity.EarnedGratuityStatus.OK: return(string.Empty); case EarnedGrauity.EarnedGratuityStatus.ExpiringSoon: if (eg.ReminderCount == 0) { return(String.Format(CultureInfo.CurrentCulture, Branding.ReBrand(Resources.EmailTemplates.DropboxExpiring), pf.UserFullName)); } else { return(string.Empty); } case EarnedGrauity.EarnedGratuityStatus.Expired: if (eg.ReminderCount <= 1) { return(String.Format(CultureInfo.CurrentCulture, Branding.ReBrand(Resources.EmailTemplates.DropboxExpired), pf.UserFullName)); } else { return(string.Empty); } } }
/// <summary> /// Notification when this gratuity has been earned, in case there is any action to take at the point of earning it /// </summary> /// <param name="dt"></param> public virtual void GratuityWasEarned(EarnedGrauity eg) { }
/// <summary> /// Get the body for a reminder email /// </summary> public virtual string ReminderBody(EarnedGrauity eg) { return(string.Empty); }
/// <summary> /// Get the subject line for a reminder email /// </summary> public virtual string ReminderSubject(EarnedGrauity eg) { return(string.Empty); }
/// <summary> /// Update earned gratuities for users to ensure that the expiration dates, etc., are correct. /// </summary> /// <param name="szUser">The user for whom gratuities should be updated; null or empty for all users</param> /// <param name="fResetReminders">True to reset reminders to 0 (i.e., no reminders sent)</param> public static void UpdateEarnedGratuities(string szUser, bool fResetReminders) { if (String.IsNullOrEmpty(szUser)) { return; } Dictionary <string, Collection <Payment> > dictPayments = PaymentListsForUser(szUser); ReadOnlyCollection <Gratuity> lstKnownGratuities = Gratuity.KnownGratuities; List <EarnedGrauity> lstUpdatedGratuityList = new List <EarnedGrauity>(); ResetSessionForGratuities(szUser); // Go through each user's payment history (could be just the one user) and determine their gratuities. foreach (string szKey in dictPayments.Keys) { List <Payment> lstPayments = new List <Payment>(dictPayments[szKey]); CompressPaymentsForUser(lstPayments); // OK, payments should be compacted - go through them and apply the gratuities foreach (Payment p in lstPayments) { // Now process the payment: // Enumerate each known gratuity and, if this qualifies for the gratuity, create/extend the gratuity. foreach (Gratuity g in lstKnownGratuities) { // see if this payment + priors qualifies if (Payment.PaymentsInDateRange(p.Timestamp.Subtract(g.Window).Date, p.Timestamp.Date, lstPayments) >= g.Threshold) { // Find the existing gratuity, if any, for the user // Add it to the list to update if we either have a new one, or if we have extended the epxiration EarnedGrauity eg = lstUpdatedGratuityList.Find(eg2 => (eg2.GratuityType == g.GratuityType && eg2.Username == p.Username)); if (eg == null) { eg = new EarnedGrauity(g, p); lstUpdatedGratuityList.Add(eg); } else { eg.ExtendExpiration(p, fResetReminders); // don't extend expiration for new earned gratuities; correct date is already set above. } eg.EarnedDate = p.Timestamp.LaterDate(eg.EarnedDate); g.GratuityWasEarned(eg); // take any action that is appropriate for the gratuity now that it is earned. } } } } // We now have a list of gratuities that should be correct List <EarnedGrauity> lstExistingEarnedGratuities = EarnedGrauity.GratuitiesForUser(szUser, Gratuity.GratuityTypes.Unknown); foreach (EarnedGrauity eg in lstUpdatedGratuityList) { // if this exists as an existing earned gratuity, update the expiration date on that one and save it OR if reseting EarnedGrauity egExisting = lstExistingEarnedGratuities.Find(eg2 => (eg2.GratuityType == eg.GratuityType && eg2.Username == eg.Username)); if (egExisting == null) // not found - this one is new { eg.Commit(); } else { int prevReminderCount = egExisting.ReminderCount; if (fResetReminders) { egExisting.ReminderCount = 0; } egExisting.ExpirationDate = eg.ExpirationDate; // Only save to database if expiration date or reminders changed if (eg.ReminderCount != egExisting.ReminderCount || egExisting.ReminderCount != prevReminderCount || eg.ExpirationDate.CompareTo(egExisting.ExpirationDate) != 0 || eg.EarnedDate.CompareTo(egExisting.EarnedDate) != 0) { egExisting.Commit(); } lstExistingEarnedGratuities.Remove(egExisting); } } // Anything that is left is no longer found (e.g., if a payment was deleted) // Shouldn't happen, but clean up just in case foreach (EarnedGrauity eg in lstExistingEarnedGratuities) { eg.Delete(); } }