コード例 #1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            var googleAnalytics = new GoogleAnalytics();

            KatushaUser = (User.Identity.IsAuthenticated) ? UserService.GetUser(User.Identity.Name) : null;
            if (KatushaUser != null)
            {
                KatushaProfile = (KatushaUser.Gender > 0) ? UserService.GetProfile(KatushaUser.Guid) : null;
            }
            var isPing = (filterContext.ActionDescriptor.ActionName == "Ping");

            if (!isPing)
            {
                if (KatushaUser != null)
                {
                    googleAnalytics.AddVisitorLevelVariable(GoogleAnalyticsVisitorLevelVariableType.Gender, Enum.GetName(typeof(Sex), KatushaUser.Gender));
                    googleAnalytics.AddVisitorLevelVariable(GoogleAnalyticsVisitorLevelVariableType.CategoryType, KatushaUser.Guid.ToString());
                }
                googleAnalytics.AddSessionLevelVariable(GoogleAnalyticsSessionLevelVariableType.Login, (KatushaUser != null) ? "true" : "false");
                if (KatushaProfile != null)
                {
                    int total;
                    var oppositeGender = (byte)((KatushaProfile.Gender == (byte)Sex.Female) ? Sex.Male : Sex.Female);
                    var newProfiles    = ProfileService.GetNewProfiles(p => p.Gender == oppositeGender, out total, 1, ProfileCount);
                    ViewBag.KatushaNewProfiles = Mapper.Map <IEnumerable <ProfileModel> >(newProfiles);
                    var onlineProfiles = new List <Profile>();
                    var onlineStates   = StateService.OnlineProfiles(oppositeGender, out total, 1, ProfileCount).ToList();
                    onlineProfiles.AddRange(onlineStates.Select(state => ProfileService.GetProfile(state.ProfileId)));
                    if (onlineProfiles.Count > 0)
                    {
                        ViewBag.KatushaOnlineProfiles = Mapper.Map <IEnumerable <ProfileModel> >(onlineProfiles);
                    }
                    KatushaState = StateService.GetState(KatushaProfile);
                }
            }
            ViewBag.KatushaState   = KatushaState;
            ViewBag.KatushaUser    = KatushaUser;
            ViewBag.KatushaProfile = KatushaProfile;
            //ViewBag.AvailableVideoRooms = StateService.GetVideoRooms(KatushaProfile);
            ViewBag.GoogleAnalytics = googleAnalytics;
            filterContext.HttpContext.Items["ViewBag"] = ViewBag;
        }