예제 #1
0
        public static int UpdatePoll(int tid, string selitemidlist, string username)
        {
            if (username.IsNullOrEmpty())
            {
                return(-1);
            }
            string[] array  = Utils.SplitString(selitemidlist, ",");
            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string expression = array2[i];
                if (expression.ToInt(-1) == -1)
                {
                    return(-1);
                }
            }
            var pollInfo = FindByTid(tid);

            if (pollInfo.ID < 1)
            {
                return(-3);
            }
            if (pollInfo.Voternames.IsNullOrEmpty())
            {
                pollInfo.Voternames = username;
            }
            else
            {
                pollInfo.Voternames = pollInfo.Voternames + "\r\n" + username;
            }
            pollInfo.Update();
            //List<PollOption > pollOptionInfoCollection = BBX.Data.Polls.GetPollOptionInfoCollection(pollInfo.Tid);
            List <PollOption> pollOptionInfoCollection = PollOption.FindAll(PollOption._.Tid, pollInfo.Tid);

            string[] array3 = array;
            for (int j = 0; j < array3.Length; j++)
            {
                string a = array3[j];
                foreach (PollOption current in pollOptionInfoCollection)
                {
                    if (a == current.ID.ToString())
                    {
                        if (current.VoterNames.IsNullOrEmpty())
                        {
                            current.VoterNames = username;
                        }
                        else
                        {
                            current.VoterNames = current.VoterNames + "\r\n" + username;
                        }
                        current.Votes++;
                        current.Update();
                    }
                }
            }
            return(0);
        }
예제 #2
0
        public static bool UpdatePoll(int tid, int multiple, int itemcount, string polloptionidlist, string itemnamelist, string itemdisplayorderlist, DateTime enddatetime, int maxchoices, int visible, bool allowview)
        {
            string[] array  = Utils.SplitString(itemnamelist, "\r\n");
            string[] array2 = Utils.SplitString(itemdisplayorderlist, "\r\n");
            string[] array3 = Utils.SplitString(polloptionidlist, "\r\n");
            if (array.Length != itemcount || array2.Length != itemcount)
            {
                return(false);
            }

            var pollInfo = FindByTid(tid);

            pollInfo.Expiration = enddatetime;
            pollInfo.MaxChoices = (Int16)maxchoices;
            pollInfo.Multiple   = multiple;
            pollInfo.Tid        = tid;
            pollInfo.Visible    = visible;
            pollInfo.AllowView  = allowview;
            bool flag = false;

            if (pollInfo.ID > 0)
            {
                flag = pollInfo.Update() > 1 ? true : false;
            }
            if (flag)
            {
                List <PollOption> pollOptionInfoCollection = PollOption.FindAll(PollOption._.Tid, pollInfo.Tid);
                int      num    = 0;
                string[] array4 = array3;
                for (int i = 0; i < array4.Length; i++)
                {
                    string a     = array4[i];
                    bool   flag2 = false;
                    foreach (PollOption current in pollOptionInfoCollection)
                    {
                        if (a == current.ID.ToString())
                        {
                            current.PollID       = pollInfo.ID;
                            current.Name         = Utils.GetSubString(array[num], 80, "");
                            current.DisplayOrder = (Utils.StrIsNullOrEmpty(array2[num]) ? (num + 1) : array2[num].ToInt(0));
                            //BBX.Data.Polls.UpdatePollOption(current);
                            current.Update();
                            flag2 = true;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        new PollOption()
                        {
                            DisplayOrder = Utils.StrIsNullOrEmpty(array2[num]) ? (num + 1) : array2[num].ToInt(0),
                            PollID       = pollInfo.ID,
                            Name         = Utils.GetSubString(array[num], 80, ""),
                            Tid          = tid,
                            VoterNames   = "",
                            Votes        = 0
                        }.Insert();
                    }
                    num++;
                }
                foreach (PollOption current2 in pollOptionInfoCollection)
                {
                    if (("\r\n" + polloptionidlist + "\r\n").IndexOf("\r\n" + current2.ID + "\r\n") < 0)
                    {
                        current2.Delete();
                    }
                }
                return(true);
            }
            return(false);
        }