public void Insert(VotingEventSetupInfo votingEventSetupInfo)
    {
        db.Open();
        transaction = db.BeginTransaction();
        try
        {
            String query = "INSERT INTO VotingEventSetup "
                           + "([ClientID] "
                           + ",[EventID] "
                           + ",[EventDescription] "
                           + ",[EventDate] "
                           + ",[EffectDateFrom] "
                           + ",[EffectDateTo] "
                           + ",[CreateUser] "
                           + ",[CreateDate] "
                           + ",[LastModifiedUser] "
                           + ",[LastModifiedDate] ) "
                           + "VALUES "
                           + "(@ClientID "
                           + ",@EventID "
                           + ",@EventDescription "
                           + ",@EventDate "
                           + ",@EffectDateFrom "
                           + ",@EffectDateTo "
                           + ",@CreateUser "
                           + ",@CreateDate "
                           + ",@LastModifiedUser "
                           + ",@LastModifiedDate ) ";
            db.Execute(query, votingEventSetupInfo, transaction);

            if (votingEventSetupInfo.VotingQuestionList != null)
            {
                for (int i = 0; i < votingEventSetupInfo.VotingQuestionList.Count; i++)
                {
                    VotingQuestionInfo votingQuestionInfo = votingEventSetupInfo.VotingQuestionList[i];
                    votingQuestionInfo.CreateUser       = votingEventSetupInfo.LastModifiedUser;
                    votingQuestionInfo.CreateDate       = DateTime.Now;
                    votingQuestionInfo.LastModifiedUser = votingEventSetupInfo.LastModifiedUser;
                    votingQuestionInfo.LastModifiedDate = DateTime.Now;
                    votingQuestionInfo.ClientID         = votingEventSetupInfo.ClientID;
                    votingQuestionInfo.EventID          = votingEventSetupInfo.EventID;
                    votingQuestionInfo.QuestionID       = i + 1;
                    this.InsertVotingQuestion(votingQuestionInfo);
                }
            }

            transaction.Commit();
        }
        catch
        {
            transaction.Rollback();
            throw;
        }
        finally
        {
            transaction.Dispose();
            transaction = null;
            db.Close();
        }
    }
 public void Save(VotingEventSetupInfo votingEventSetupInfo)
 {
     if (this.IsExisted(votingEventSetupInfo.ClientID, votingEventSetupInfo.EventID))
     {
         this.Update(votingEventSetupInfo);
     }
     else
     {
         this.Insert(votingEventSetupInfo);
     }
 }
    public void Update(VotingEventSetupInfo votingEventSetupInfo)
    {
        db.Open();
        transaction = db.BeginTransaction();
        try
        {
            String query = "UPDATE [dbo].[VotingEventSetup] "
                           + "SET "
                           + "[EventDescription] = @EventDescription "
                           + ",[EventDate] = @EventDate "
                           + ",[EffectDateFrom] = @EffectDateFrom "
                           + ",[EffectDateTo] = @EffectDateTo "
                           + ",[LastModifiedUser] = @LastModifiedUser "
                           + ",[LastModifiedDate] = @LastModifiedDate "
                           + "WHERE ClientID = @ClientID AND EventID = @EventID ";
            db.Execute(query, votingEventSetupInfo, transaction);

            this.DeleteVotingQuestion(votingEventSetupInfo.ClientID, votingEventSetupInfo.EventID);

            if (votingEventSetupInfo.VotingQuestionList != null)
            {
                for (int i = 0; i < votingEventSetupInfo.VotingQuestionList.Count; i++)
                {
                    VotingQuestionInfo votingQuestionInfo = votingEventSetupInfo.VotingQuestionList[i];
                    votingQuestionInfo.CreateUser       = votingEventSetupInfo.LastModifiedUser;
                    votingQuestionInfo.CreateDate       = DateTime.Now;
                    votingQuestionInfo.LastModifiedUser = votingEventSetupInfo.LastModifiedUser;
                    votingQuestionInfo.LastModifiedDate = DateTime.Now;
                    votingQuestionInfo.ClientID         = votingEventSetupInfo.ClientID;
                    votingQuestionInfo.EventID          = votingEventSetupInfo.EventID;
                    votingQuestionInfo.QuestionID       = i + 1;
                    this.InsertVotingQuestion(votingQuestionInfo);
                }
            }

            transaction.Commit();
        }
        catch
        {
            transaction.Rollback();
            throw;
        }
        finally {
            transaction.Dispose();
            transaction = null;
            db.Close();
        }
    }