예제 #1
0
        public object AddVoteToTags(TaggedVoteData data)
        {
            string user_name = UserCenter.Act(data.session_key);

            if (user_name == null)
            {
                return new { code = ResultCode.InvalidSession }
            }
            ;

            foreach (string tag in data.tags)
            {
                TagScrollStore.AddVote(data.vote_id, tag, data.title, user_name);
            }

            var data2 = new
            {
                vote_id = data.vote_id,
                title   = data.title,
                time    = DateTimeOffset.UtcNow,
                who     = user_name,
                tags    = data.tags
            };

            VoteBroadcaster.HubContext.Clients.All.onNewTaggedVote(data2);

            return(new
            {
                code = ResultCode.Success,
            });
        }
예제 #2
0
        public object AddTallies(AddTallyData data)
        {
            string user_name = UserCenter.Act(data.session_key);

            if (user_name == null)
            {
                return new { code = ResultCode.InvalidSession }
            }
            ;

            string client_ip = Util.ClientIp();

            if (RecordStore.CheckUser(data.vote_id, data.sbjt_mat, user_name))
            {
                return new { err_msg = "您(" + user_name + ")已經投過票了。" }
            }
            ;
#if !DEBUG
            if (RecordStore.CheckIp(data.vote_id, data.sbjt_mat, client_ip))
            {
                return new { err_msg = "您的IP已經投過票了。" }
            }
            ;
            // return new { err_msg = "您的IP位址(" + client_ip + ")已經投過票了。" };
#endif
            TallyStore.AddTallies(data.vote_id, user_name, data.sbjt_mat, data.tallies);
            RecordStore.AddRecord(data.vote_id, data.sbjt_mat, user_name, client_ip);

            return(new
            {
                code = ResultCode.Success,
            });
        }
예제 #3
0
        public object Test(TestData data)
        {
            if (UserCenter.Act(data.session_key) == null)
            {
                return new { code = ResultCode.InvalidSession }
            }
            ;

            return(new { code = ResultCode.Success });
        }
예제 #4
0
        public ActionResult GetTallies(string session_key, string vote_id)
        {
            string user_name = UserCenter.Act(session_key);

            if (user_name == null)
            {
                return(Json(new { code = ResultCode.InvalidSession }, JsonRequestBehavior.AllowGet));
            }

            IEnumerable <TallyInfo> tallies = TallyStore.GetTallies(vote_id, user_name);

            return(Json(new
            {
                code = ResultCode.Success,
                tallies = tallies,
            }, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        public object ResetTallies(AddTallyData data)
        {
            string user_name = UserCenter.Act(data.session_key);

            if (user_name == null)
            {
                return new { code = ResultCode.InvalidSession }
            }
            ;

            RecordStore.ResetRecord(data.vote_id, data.sbjt_mat, user_name);
            TallyStore.ResetTallies(data.vote_id, user_name, data.sbjt_mat);

            return(new
            {
                code = ResultCode.Success,
            });
        }
예제 #6
0
        public object CreateVote(CreateVoteData data)
        {
            string user_name = UserCenter.Act(data.session_key);

            if (user_name == null)
            {
                return new { code = ResultCode.InvalidSession }
            }
            ;

            string vote_id = PaperStore.CreatePaper(user_name);

            return(new
            {
                code = ResultCode.Success,
                vote_id = vote_id
            });
        }
예제 #7
0
        public object AddActions(AddActionData data)
        {
            string user_name = UserCenter.Act(data.session_key);

            if (user_name == null)
            {
                return new { code = ResultCode.InvalidSession }
            }
            ;

            // Prevent XSS attack.
            //for (int i = 0; i < data.actions.Length; i++)
            //	data.actions[i].value = HttpContext.Current.Server.HtmlEncode(data.actions[i].value);
            // Encode at output instead of input.

            string[] hps = PaperStore.AddActions(data.vote_id, user_name, data.actions);

            VoteBroadcaster.HubContext.Clients.Group(data.vote_id).onNewActions(hps);

            return(new
            {
                code = ResultCode.Success,
            });
        }