コード例 #1
0
 public ActionResult AddVote(AddvoteVM vote)
 {
     try
     {
         VoteBL v = new VoteBL();
         v.ID      = int.Parse(vote.id);
         v.Title   = vote.title;
         v.Context = vote.context;
         v.vtype   = vote.vtype;
         v.Options = new List <VoteOption>();
         VoteOption opt;
         for (int i = 0; i < vote.options.Count; i++)
         {
             opt              = new VoteOption();
             opt.OptionTitle  = vote.options[i].OptionTitle;
             opt.OptinContext = vote.options[i].OptinContext;
             opt.ID           = int.Parse(vote.options[i].id);
             opt.ActionType   = vote.options[i].ActionType;
             opt.CreateBy     = "1";
             v.Options.Add(opt);
         }
         if (v.AddVote())
         {
             return(Json(new { rescode = 200, msg = "" }));
         }
         else
         {
             return(Json(new { rescode = 500, msg = "操作失敗" }));
         }
     }
     catch (Exception e)
     {
         return(Json(new { rescode = 500, msg = "操作失敗" }));
     }
 }
コード例 #2
0
        public ActionResult UpdateVote(AddvoteVM vote)
        {
            VoteBL v = VoteBL.GetVote(vote.id);

            v.Title    = vote.title;
            v.UpdateBy = "1";
            v.vtype    = vote.vtype;
            v.Context  = vote.context;

            for (int i = 0; i < v.Options.Count; i++)
            {
                if (!vote.options.Exists(p => p.id == v.Options[i].ID.ToString()))
                {
                    v.Options[i].ActionType = "2";
                }
            }

            VoteOption vop;

            for (int i = 0; i < vote.options.Count; i++)
            {
                if (v.Options.Exists(p => p.ID.ToString() == vote.options[i].id))
                {
                    vop = v.Options.Find(p => p.ID.ToString() == vote.options[i].id);
                    vop.OptinContext = vote.options[i].OptinContext;
                    vop.OptionTitle  = vote.options[i].OptionTitle;
                    vop.UpdateBy     = "1";
                    vop.ActionType   = null;
                }
                else
                {
                    vop = new VoteOption();
                    vop.OptinContext = vote.options[i].OptinContext;
                    vop.OptionTitle  = vote.options[i].OptionTitle;
                    vop.UpdateBy     = "1";
                    vop.ActionType   = "1";
                    v.Options.Add(vop);
                }
            }
            if (v.UpdateVote())
            {
                return(Json(new { rescode = 200, msg = "" }));
            }
            else
            {
                return(Json(new { rescode = 500, msg = "操作失敗" }));
            }
        }
コード例 #3
0
        public ActionResult GetVote(string id)
        {
            VoteBL    v   = VoteBL.GetVote(id);
            AddvoteVM avm = new AddvoteVM();

            avm.id      = v.ID.ToString();
            avm.title   = v.Title;
            avm.context = v.Context;
            avm.vtype   = v.vtype;
            avm.options = new List <VoteOptionsVM>();
            for (int i = 0; i < v.Options.Count; i++)
            {
                avm.options.Add(new VoteOptionsVM()
                {
                    id           = v.Options[i].ID.ToString(), ActionType = null,
                    OptinContext = v.Options[i].OptinContext, OptionTitle = v.Options[i].OptionTitle
                });
            }


            return(Json(avm));
        }