Пример #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;
 }
Пример #2
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;
 }