Ejemplo n.º 1
0
 /// <summary>
 /// Check if allowance can be reset, and do so if it's been a day.
 /// </summary>
 /// <param name="ctx">Database context</param>
 /// <param name="su">Server user to check</param>
 /// <returns>Current allowance after check</returns>
 private static int ResetAllowance(MoetronDBContext ctx, ServerUser su)
 {
     //If a day has passed since last allowance, reset it
     if ((DateTime.UtcNow - su.LastAllowance).TotalDays > 1)
     {
         su.Allowance = DEFAULT_ALLOWANCE;
         su.LastAllowance = DateTime.UtcNow;
         ctx.SaveChanges();
     }
     return su.Allowance;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if a user has enough allowance left to give or remove a number of points.
        /// </summary>
        /// <param name="ctx">Database context</param>
        /// <param name="su">Server user to check against</param>
        /// <param name="num">Number of points</param>
        /// <param name="isGiving">True if giving, false if removing</param>
        /// <returns>True if enough allowance left, false otherwise</returns>
        private bool CheckAllowanceAmount(MoetronDBContext ctx, ServerUser su, long num, bool isGiving)
        {
            if (su == null)
                return false;
            if (num < 1)
                return false;

            ResetAllowance(ctx, su);

            if (isGiving)
            {
                if (num > su.Allowance)
                    return false;
            }
            else
            {
                if (num * REMOVE_ALLOWANCE_COST > su.Allowance)
                    return false;
            }
            return true;
        }