Example #1
0
        public static int CreateVote(VoteInfo vote)
        {
            int     num  = 0;
            VoteDao dao  = new VoteDao();
            long    num2 = dao.CreateVote(vote);

            if (num2 > 0L)
            {
                ReplyInfo reply = new TextReplyInfo {
                    Keys       = vote.Keys,
                    MatchType  = MatchType.Equal,
                    ReplyType  = ReplyType.Vote,
                    ActivityId = Convert.ToInt32(num2)
                };
                new ReplyDao().SaveReply(reply);
                num = 1;
                if (vote.VoteItems == null)
                {
                    return(num);
                }
                foreach (VoteItemInfo info2 in vote.VoteItems)
                {
                    info2.VoteId    = num2;
                    info2.ItemCount = 0;
                    num            += dao.CreateVoteItem(info2, null);
                }
            }
            return(num);
        }
Example #2
0
        public ActionResult Vote(VoteModel model)
        {
            if (!ModelState.IsValid)
            {
                model = initVoteModel(model.questionID);
                return(View(model));
            }
            VoteDao votedao = new VoteDao();
            //检查用户是否已经投过票了 否则在原来的基础上更改
            User     u = new UserDao().getById(model.userID);
            Question q = new QuestionDao().getById(model.questionID);

            Vote v = votedao.getByUserAndQuestion(u, q);

            if (v == null)
            {
                v = new Models.Vote();
            }
            v.queID       = new QuestionDao().getById(model.questionID);
            v.userID      = u;
            v.voteComment = model.voteComment;
            v.voteTime    = DateTime.Now;
            v.voteRecord  = model.voteRecord;
            if (v.ID != 0)
            {
                votedao.update(v);
            }
            else
            {
                votedao.add(v);
            }
            return(RedirectToAction("Index"));
        }
Example #3
0
        public static bool UpdateVote(VoteInfo vote)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                VoteDao voteDao = new VoteDao();
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    if (!voteDao.UpdateVote(vote, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!voteDao.DeleteVoteItem(vote.VoteId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            int num = 0;
                            if (vote.VoteItems != null)
                            {
                                foreach (VoteItemInfo current in vote.VoteItems)
                                {
                                    current.VoteId    = vote.VoteId;
                                    current.ItemCount = 0;
                                    num += voteDao.CreateVoteItem(current, dbTransaction);
                                }
                                if (num < vote.VoteItems.Count)
                                {
                                    dbTransaction.Rollback();
                                    result = false;
                                    return(result);
                                }
                            }
                            dbTransaction.Commit();
                            result = true;
                        }
                    }
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Example #4
0
        public static bool UpdateVote(VoteInfo vote)
        {
            bool    flag;
            VoteDao dao = new VoteDao();

            using (DbConnection connection = DatabaseFactory.CreateDatabase().CreateConnection())
            {
                connection.Open();
                DbTransaction dbTran = connection.BeginTransaction();
                try
                {
                    if (!dao.UpdateVote(vote, dbTran))
                    {
                        dbTran.Rollback();
                        return(false);
                    }
                    if (!dao.DeleteVoteItem(vote.VoteId, dbTran))
                    {
                        dbTran.Rollback();
                        return(false);
                    }
                    int num = 0;
                    if (vote.VoteItems != null)
                    {
                        foreach (VoteItemInfo info in vote.VoteItems)
                        {
                            info.VoteId    = vote.VoteId;
                            info.ItemCount = 0;
                            num           += dao.CreateVoteItem(info, dbTran);
                        }
                        if (num < vote.VoteItems.Count)
                        {
                            dbTran.Rollback();
                            return(false);
                        }
                    }
                    dbTran.Commit();
                    flag = true;
                }
                catch
                {
                    dbTran.Rollback();
                    flag = false;
                }
                finally
                {
                    connection.Close();
                }
            }
            return(flag);
        }
Example #5
0
        public static bool UpdateVote(VoteInfo vote)
        {
            Database database = DatabaseFactory.CreateDatabase();

            using (DbConnection dbConnection = database.CreateConnection())
            {
                VoteDao voteDao = new VoteDao();
                dbConnection.Open();
                DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    if (!voteDao.Update(vote, null))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    if (!voteDao.DeleteVoteItem(vote.VoteId, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    int num = 0;
                    if (vote.VoteItems != null)
                    {
                        foreach (VoteItemInfo voteItem in vote.VoteItems)
                        {
                            voteItem.VoteId    = vote.VoteId;
                            voteItem.ItemCount = 0;
                            num += (int)voteDao.Add(voteItem, null);
                        }
                        if (num < vote.VoteItems.Count)
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                    }
                    dbTransaction.Commit();
                    return(true);
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    return(false);
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }
Example #6
0
        public static int CreateVote(VoteInfo vote)
        {
            int     num     = 0;
            VoteDao voteDao = new VoteDao();
            long    num3    = vote.VoteId = voteDao.Add(vote, null);

            if (num3 > 0)
            {
                num = 1;
                if (vote.VoteItems != null)
                {
                    foreach (VoteItemInfo voteItem in vote.VoteItems)
                    {
                        voteItem.VoteId    = num3;
                        voteItem.ItemCount = 0;
                        num += (int)voteDao.Add(voteItem, null);
                    }
                }
            }
            return(num);
        }
Example #7
0
        public static int CreateVote(VoteInfo vote)
        {
            int     num     = 0;
            VoteDao voteDao = new VoteDao();
            long    num2    = voteDao.CreateVote(vote);

            if (num2 > 0L)
            {
                num = 1;
                if (vote.VoteItems != null)
                {
                    foreach (VoteItemInfo current in vote.VoteItems)
                    {
                        current.VoteId    = num2;
                        current.ItemCount = 0;
                        num += voteDao.CreateVoteItem(current, null);
                    }
                }
            }
            return(num);
        }
Example #8
0
        public static int CreateVote(VoteInfo vote)
        {
            int     num     = 0;
            VoteDao voteDao = new VoteDao();
            long    num1    = voteDao.CreateVote(vote);

            if (num1 > (long)0)
            {
                num = 1;
                if (vote.VoteItems != null)
                {
                    foreach (VoteItemInfo voteItem in vote.VoteItems)
                    {
                        voteItem.VoteId    = num1;
                        voteItem.ItemCount = 0;
                        num = num + voteDao.CreateVoteItem(voteItem, null);
                    }
                }
            }
            return(num);
        }
Example #9
0
        //查看已投票的问题
        public ActionResult MyVote()
        {
            MyVoteModel model = new MyVoteModel();

            UserDao     userdao     = new UserDao();
            User        user        = userdao.getById(int.Parse(Request.Cookies["Menber"].Values["ID"]));
            VoteDao     votedao     = new VoteDao();
            List <Vote> votes       = votedao.getByUser(user);
            QuestionDao questiondao = new Dao.QuestionDao();

            model.questions = new List <Question>();
            foreach (Vote v in votes)
            {
                Question q = v.queID;
                model.questions.Add(q);
            }
            TypeDao typedao = new TypeDao();

            model.types = typedao.getTypeList();

            return(View(model));
        }
Example #10
0
        public static int CreateVote(VoteInfo vote)
        {
            int     num  = 0;
            VoteDao dao  = new VoteDao();
            long    num2 = dao.CreateVote(vote);

            if (num2 > 0L)
            {
                num = 1;
                if (vote.VoteItems == null)
                {
                    return(num);
                }
                foreach (VoteItemInfo info in vote.VoteItems)
                {
                    info.VoteId    = num2;
                    info.ItemCount = 0;
                    num           += dao.CreateVoteItem(info, null);
                }
            }
            return(num);
        }
Example #11
0
 static VoteHelper()
 {
     VoteHelper._vote = new VoteDao();
 }
Example #12
0
        public static bool UpdateVote(VoteInfo vote)
        {
            bool         flag;
            VoteDao      voteDao      = new VoteDao();
            DbConnection dbConnection = DatabaseFactory.CreateDatabase().CreateConnection();

            try
            {
                dbConnection.Open();
                DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    try
                    {
                        if (!voteDao.UpdateVote(vote, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            flag = false;
                        }
                        else if (voteDao.DeleteVoteItem(vote.VoteId, dbTransaction))
                        {
                            int num = 0;
                            if (vote.VoteItems != null)
                            {
                                foreach (VoteItemInfo voteItem in vote.VoteItems)
                                {
                                    voteItem.VoteId    = vote.VoteId;
                                    voteItem.ItemCount = 0;
                                    num = num + voteDao.CreateVoteItem(voteItem, dbTransaction);
                                }
                                if (num < vote.VoteItems.Count)
                                {
                                    dbTransaction.Rollback();
                                    flag = false;
                                    return(flag);
                                }
                            }
                            dbTransaction.Commit();
                            flag = true;
                        }
                        else
                        {
                            dbTransaction.Rollback();
                            flag = false;
                        }
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        flag = false;
                    }
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            finally
            {
                if (dbConnection != null)
                {
                    ((IDisposable)dbConnection).Dispose();
                }
            }
            return(flag);
        }