Esempio n. 1
0
 public AvailabilityResult CanUserTakeQuiz(
     User u,
     DateTime date,
     IList <QuizResult> results)
 {
     if (MaxTaken.HasValue && results.Count >= MaxTaken)
     {
         return(AvailabilityResult.No(
                    "This quiz has already been taken the maximum number of times.",
                    "This quiz can only be taken " + MaxTaken.Value + " times."));
     }
     if (MaxAwarded.HasValue && results.Count(x => !String.IsNullOrEmpty(x.Transaction)) >= MaxAwarded)
     {
         return(AvailabilityResult.No(
                    "This quiz has already awarded you points the maximum number of times.",
                    "You can only be awarded points by this quiz " + MaxAwarded + " times."));
     }
     if (Cooldown.HasValue &&
         results.Count > 0 &&
         (results.Max(x => x.Taken) + Cooldown.Value < date))
     {
         return(AvailabilityResult.No(
                    "This quiz cannot be taken again until " + (results.Max(x => x.Taken) + Cooldown.Value).ToShortDateString() + ".",
                    "You must wait at least " + Cooldown.Value.TotalDays.ToString("n0") + " days between attempts."));
     }
     return(AvailabilityResult.Ok);
 }
Esempio n. 2
0
        /// <summary>
        /// Determine if a user is allowed access to this resource, at a given point in time.
        /// </summary>
        /// <param name="u">User</param>
        /// <param name="date">Date</param>
        /// <returns>
        /// False, unless either the given user is in the Users list, the user's current group is
        /// in the Groups list, or the AvailableToPublic or AvailableToAllUsers flags are set,  and
        /// the supplied date is within the From and To properties of the Availability and the
        /// Resource is Enabled.
        /// </returns>
        public AvailabilityResult IsAllowedAccess(User u, DateTime date)
        {
            // disallow access based on date range settings
            if (From.HasValue && date < From.Value)
            {
                return(AvailabilityResult.No(
                           "This resource is not yet available.",
                           "This resource will become available on " + From.Value.ToShortDateString() + ". Please check back then."));
            }
            if (To.HasValue && date > To.Value)
            {
                return(AvailabilityResult.No(
                           "This resource is no longer available.",
                           "This resource was made unavaible on " + To.Value.ToShortDateString() + ". Please ask your adminstrator to remove any links to this resource."));
            }

            // allow access based on the group membership & mode
            var isInUsers  = null != u && null != Users && Users.Contains(u.Document.Id);
            var isInGroups = null != u && null != Groups && null != u.Group && Groups.Contains(u.Group);

            switch (Mode)
            {
            case AvailabilityMode.AvailableToPublic: return(AvailabilityResult.Ok);

            case AvailabilityMode.AvailableToAllUsers:
                if (null != u)
                {
                    return(AvailabilityResult.Ok);
                }
                break;

            case AvailabilityMode.AvailableOnlyTo:
                if (isInUsers || isInGroups)
                {
                    return(AvailabilityResult.Ok);
                }
                break;

            case AvailabilityMode.AvailableToEveryoneBut:
                if (!isInUsers && !isInGroups)
                {
                    return(AvailabilityResult.Ok);
                }
                break;
            }

            return(AvailabilityResult.No(
                       "You do not have access to this resource.",
                       "Please ask your adminstrator to grant access to this resource."));
        }
Esempio n. 3
0
        public AvailabilityResult IsAllowedAccess(User u, DateTime date)
        {
            // disallow access based on enabled & date range settings
            if (!Enabled)
            {
                return(AvailabilityResult.No(
                           "This resource is not enabled.",
                           "This resource is currently disabled. Please ask an administrator to enabled this resource or to remove any links referencing it."));
            }

            // if the availability is left blank, allow access by default
            return(null == Availability
                ? AvailabilityResult.Ok
                : Availability.IsAllowedAccess(u, date));
        }