Beispiel #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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }