Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list of gratuities earned by the specified user
        /// </summary>
        /// <param name="szUser">Username - pass an empty string or null for all users</param>
        /// <param name="gt">Type of gratuity - pass Unknown for all</param>
        /// <returns>The gratuityties earned for the userc</returns>
        public static List <EarnedGrauity> GratuitiesForUser(string szUser, Gratuity.GratuityTypes gt)
        {
            List <string> lstRestrictions = new List <string>();

            if (!String.IsNullOrEmpty(szUser))
            {
                lstRestrictions.Add(" eg.username=?user ");
            }
            if (gt != Gratuity.GratuityTypes.Unknown)
            {
                lstRestrictions.Add(" eg.idGratuityType=?gt ");
                string szUserRestriction = Gratuity.GratuityFromType(gt).UserRestriction;
                if (!String.IsNullOrEmpty(szUserRestriction))
                {
                    lstRestrictions.Add(String.Format(" ({0}) ", szUserRestriction));
                }
            }
            string szWhereClause = String.Join(" AND ", lstRestrictions.ToArray()).Trim();

            string               szQ = @"SELECT *, uir.Rolename AS Role 
                        FROM earnedgratuities eg 
INNER JOIN users ON eg.username=users.username
LEFT JOIN usersinroles uir ON users.username=uir.username
{0} 
ORDER BY dateEarned ASC ";
            DBHelper             dbh = new DBHelper(String.Format(szQ, String.IsNullOrEmpty(szWhereClause) ? string.Empty : String.Format("WHERE {0}", szWhereClause)));
            List <EarnedGrauity> lst = new List <EarnedGrauity>();

            dbh.ReadRows((comm) =>
            {
                comm.Parameters.AddWithValue("user", szUser);
                comm.Parameters.AddWithValue("gt", (int)gt);
            },
                         (dr) => { lst.Add(new EarnedGrauity(dr)); });
            return(lst);
        }
Esempio n. 3
0
 protected static string SessionKeyForUser(string szUser, Gratuity.GratuityTypes gt)
 {
     return(String.Format(CultureInfo.InvariantCulture, "{0}-Gratuity-{1}", szUser, gt.ToString()));
 }