public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
        {
            UserMedal currentMedal = new ReservationMedal();
            currentMedal.CreatedAt = new DateTime(0);
            if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
            {
                //if (IfAlreadyHave(statistic)) return null;
                currentMedal = getLastMedal(statistic);
            }

            //Check if current activity is meets requirement
            string activityName = activity.GetType().Name;
            int activityCount = 0;
            if (activity is MedalViewActivity)
            {
                activityCount = statistic.GetActivityCount(activityName, ((MedalViewActivity)activity).MedalType, currentMedal.CreatedAt);
            }
            else
            {
                activityCount = statistic.GetActivityCount(activityName, currentMedal.CreatedAt);
            }

            //Check if current activity is in requirement list
            if (RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName) != null)
            {
                if (activityCount >= RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName).Count)
                {
                    //Current activity is meets requirement
                    //Check if meets other requirements necessary for the medal
                    foreach (var requirement in RequirementsList)
                    {
                        activityName = requirement.Activity.GetType().Name;
                        //avtivityCount = statistic.GetActivityCount(activityName);
                        if (requirement.Activity is MedalViewActivity)
                        {
                            activityCount = statistic.GetActivityCount(activityName, "ReservationMedal", currentMedal.CreatedAt);
                        }
                        else
                        {
                            activityCount = statistic.GetActivityCount(activityName, currentMedal.CreatedAt);
                        }
                        if (!(activityCount >= RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName).Count))
                        {
                            log.InfoFormat("[ReservationMedalChecker]: CheckIfFullfiledRequirement] Still not win ReservationMedal Medal. avtivityCount={0}", activityCount);
                            return null;
                        }
                    }
                    UserMedal medal = new ReservationMedal();
                    log.InfoFormat("[ReservationMedalChecker]: CheckIfFullfiledRequirement] Win ReservationMedal Medal. avtivityCount={0}", activityCount);
                    return medal;
                }
            }
            else
            {
                log.InfoFormat("[ReservationMedalChecker]: CheckIfFullfiledRequirement] Still not win ReservationMedal Medal. avtivityCount={0}", activityCount);
            }
            return null;
        }
 public UserMedal getLastMedal(SpontaneousUserModel statistic)
 {
     UserMedal returnValue = new ReservationMedal();
     returnValue.CreatedAt = new DateTime(0);
     if (statistic != null && statistic.UserMedalsList != null && IfAlreadyHave(statistic))
     {
         var adviserMedalList = statistic.UserMedalsList.Where(c => c is ReservationMedal);
         if (adviserMedalList != null)
         {
             returnValue = adviserMedalList.OrderBy(o => o.CreatedAt).ToList().LastOrDefault();
         }
     }
     log.DebugFormat("[ReservationMedalChecker]: getLastMedal, CreatedAt={0}", returnValue.CreatedAt);
     return returnValue;
 }
        public override MedalProgress GetProgress(SpontaneousUserModel statistic)
        {
            //if (!IfAlreadyHave(statistic))
            //{
            UserMedal currentMedal = new ReservationMedal();
            currentMedal.CreatedAt = new DateTime(0);
            if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
            {
                currentMedal = getLastMedal(statistic);
            }

            MedalProgress returnValue = new MedalProgress()
            {
                MedalType = MedalType,
            };
            //Calculate total points required for the medal
            foreach (var requirement in RequirementsList)
            {
                returnValue.totalPointsRequired += requirement.Activity.Points * requirement.Count;
            }

            returnValue.pointsRequired = returnValue.totalPointsRequired;

            if (statistic != null && statistic.UserActivityList != null)
            {
                //Calculate points still required for the medal
                bool reservePlaceActivityFlag = false;
                foreach (UserActivity userActivity in statistic.UserActivityList)
                {
                    if (userActivity.Date > currentMedal.CreatedAt)
                    {
                        if (userActivity is ReservePlaceActivity)
                        {
                            if (!reservePlaceActivityFlag)
                            {
                                returnValue.pointsRequired -= userActivity.Points;
                                reservePlaceActivityFlag = true;
                            }
                        }
                        //if (userActivity is MedalViewActivity)
                        //{
                        //    if (((MedalViewActivity)userActivity).MedalType == "ReservationMedal") returnValue.viewFlag = true;
                        //}
                    }//if (userActivity.Date > currentMedal.CreatedAt)
                }
                if (returnValue.pointsRequired < 0) returnValue.pointsRequired = 0;
            }
            return returnValue;
            //}
            //return null;
        }