public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
        {
            UserMedal currentMedal = new RestaurantAdviserMedal();
            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, "RestaurantAdviserMedal", currentMedal.CreatedAt);
                        }
                        else
                        {
                            activityCount = statistic.GetActivityCount(activityName, currentMedal.CreatedAt);
                        }
                        if (!(activityCount >= RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName).Count))
                        {
                            log.InfoFormat("[RestaurantAdviserChecker]: CheckIfFullfiledRequirement] Still not win RestaurantAdviser Medal. avtivityCount={0}", activityCount);
                            return null;
                        }
                    }
                    UserMedal medal = new RestaurantAdviserMedal();
                    log.InfoFormat("[RestaurantAdviserChecker]: CheckIfFullfiledRequirement] Win RestaurantAdviser Medal. avtivityCount={0}", activityCount);
                    return medal;
                }
            }
            else
            {
                log.InfoFormat("[RestaurantAdviserChecker]: CheckIfFullfiledRequirement] Still not win RestaurantAdviser Medal. avtivityCount={0}", activityCount);
            }
            return null;
        }
 /// <summary>
 ///     
 /// </summary>
 /// <param name="userStatistic"></param>
 /// <param name="producedActivity"></param>
 /// <returns>
 /// In case requirements was fullfiled return medal for giving to user.
 /// This should be save outside of method
 /// </returns>
 public List<UserMedal> ObtainMedalBecauseOfActivity(SpontaneousUserModel userStatistic, UserActivity producedActivity)
 {
     List<UserMedal> returnValue = new List<UserMedal>();
     String activityClassName = producedActivity.GetType().Name;
     if (m_activityMedalMap.ContainsKey(activityClassName))
     {
         UserMedal medal = m_activityMedalMap[activityClassName].CheckIfFullfiledRequirement(userStatistic, producedActivity);
         if (medal != null) returnValue.Add(medal);
     }
     return returnValue;
 }
 public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
 {
     if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
     {
         //1 Still not acquired check
         foreach (UserMedal medal in statistic.UserMedalsList)
         {
             if (medal is WelcomeUserMedal) return null;
         }
     }
     //2 20 views
     int avtivityCount = statistic.GetActivityCount(activity.GetType().Name);
     if (avtivityCount >= 20)
     {
         // need to check if medal created with CreatedAt propertie
         UserMedal medal = new AdultUserMedal();
         return medal;
     }
     return null;
 }
        public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
        {
            if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
            {
                if (IfAlreadyHave(statistic)) return null;
            }

            //int avtivityCount = statistic.GetActivityCount(activity.GetType().Name);
            //if (avtivityCount >= RequirementsList[0].Count)
            //{
            //    UserMedal medal = new WelcomeUserMedal();
            //    log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Win WelcomeUser Medal. avtivityCount={0}", avtivityCount);
            //    return medal;
            //}
            string activityName = activity.GetType().Name;
            int activityCount = 0;
            if (activity is MedalViewActivity)
            {
                activityCount = statistic.GetActivityCount(activityName, ((MedalViewActivity)activity).MedalType);
            }
            else
            {
                activityCount = statistic.GetActivityCount(activityName);
            }

            //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, "WelcomeUserMedal");
                        }
                        else
                        {
                            activityCount = statistic.GetActivityCount(activityName);
                        }
                        if (!(activityCount >= RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName).Count))
                        {
                            log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Still not win WelcomeUser Medal. avtivityCount={0}", activityCount);
                            return null;
                        }
                    }
                    UserMedal medal = new WelcomeUserMedal();
                    log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Win WelcomeUser Medal. avtivityCount={0}", activityCount);
                    return medal;
                }
            }
            else
            {
                log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Still not win WelcomeUser Medal. avtivityCount={0}", activityCount);
            }
            return null;
        }
 public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
 {
     if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
     {
         //1 Still not acquired check
         foreach (UserMedal medal in statistic.UserMedalsList)
         {
             if (medal is WelcomeUserMedal) return null;
         }
     }
     //2 10 views
     int avtivityCount = statistic.GetActivityCount(activity.GetType().Name);
     if (avtivityCount >= 1)
     {
         // need to check if medal created with CreatedAt propertie
         UserMedal medal = new WelcomeUserMedal();
         log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Win WelcomeUser Medal. avtivityCount={0}", avtivityCount);
         return medal;
     }
     else
     {
         log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Still not win WelcomeUser Medal. avtivityCount={0}", avtivityCount);
     }
     return null;
 }
        internal void SaveUserActivity(UserActivity userActivity)
        {
            var userProfile = GetUserProfile();
            var userData = userProfile.GetUserData();
            string userActivityType = userActivity.GetType().Name;

            if (userActivity == null)
            {
                log.WarnFormat("[SaveUserActivity] User={0} tried to save user activity, but received NULL parameter.", userProfile.UserName);
                return;
            };

            if (userData.UserActivityList == null)
            {
                userData.UserActivityList = new List<UserActivity>();
            }

            userActivity.Date = DateTime.UtcNow;
            userData.TotalPoints += userActivity.Points;

            userData.UserActivityList.Add(userActivity);

            //Check if reached Medal
            MedalRequirementsChecker medalChecker = new MedalRequirementsChecker();
            List<UserMedal> medalList = medalChecker.ObtainMedalBecauseOfActivity(userData, userActivity);
            if(medalList.Count > 0)
            {
                if (userData.UserMedalsList == null) userData.UserMedalsList = new List<UserMedal>();
                foreach (var medal in medalList)
                {
                    userData.UserMedalsList.Add(medal);
                }

                userData.MedalNotificationFlag = true;
            }

            userProfile.SetUserData(userData);
            userProfile.Save();
            log.InfoFormat("[SaveUserActivity] user={0}, userActivity={1}.", userProfile.UserName, userActivity.ToString());
        }
        internal void SaveUserActivity(UserActivity userActivity, List<CouponType> allCoupons)
        {
            if (userActivity == null)
            {
                log.Warn("[SaveUserActivity] tried to save user activity, but received NULL parameter.");
                return;
            };

            try
            {
                var userProfile = GetUserProfile();
                var userData = userProfile.GetUserData();
                string userActivityType = userActivity.GetType().Name;

                if (userData.UserActivityList == null)
                {
                    userData.UserActivityList = new List<UserActivity>();
                }

                userActivity.Date = DateTime.UtcNow;
                userData.TotalPoints += userActivity.Points;

                userData.UserActivityList.Add(userActivity);

                //Check if reached Medal
                MedalRequirementsChecker medalChecker = medalChecker = factoryMedalChecker(); ;

                if(medalChecker == null)
                    return;

                log.InfoFormat("[SaveUserActivity] Spontaneous : user={0}, userActivity={1}.", userProfile.UserName, userActivity.ToString());
                List<UserMedal> medalList = medalChecker.ObtainMedalBecauseOfActivity(userData, userActivity);

                if (medalList.Count > 0)
                {
                    if (userData.UserMedalsList == null) userData.UserMedalsList = new List<UserMedal>();
                    foreach (var medal in medalList)
                    {
                        CouponType tempCoupon = GetCoupon(userData, allCoupons, userActivity);
                        if (tempCoupon != null) // get coupon for new medal
                        {
                            medal.Coupon = tempCoupon;
                        }
                        else // if already have all coupons get last one
                        {
                            if (allCoupons != null && allCoupons.Count > 0)
                            {
                                medal.Coupon = allCoupons.LastOrDefault();
                            }
                        }

                        userData.UserMedalsList.Add(medal);
                    }
                    userData.MedalNotificationFlag = true;
                }

                userProfile.SetUserData(userData);
                userProfile.Save();
            }
            catch (Exception ex)
            {
                log.ErrorFormat("[SaveUserActivity] error: Exception={0}.", ex.ToString());
            }
        }