public override DataSet Clone()
        {
            InvitationLogData data = (InvitationLogData)base.Clone();

            data.InitVars();
            return(data);
        }
        /// <summary>
        /// Returns all the invitation logs
        /// </summary>
        public InvitationLogData GetInvitationLogs(int surveyId, int pageNumber, int pageSize, out int totalRecords)
        {
            InvitationLogData dataSet = new InvitationLogData();

            //SqlParameter[] commandParameters = new SqlParameter[] 
            //{ new SqlParameter("@SurveyID", surveyId), 
            //    new SqlParameter("@CurrentPage", pageNumber), 
            //    new SqlParameter("@PageSize", pageSize), 
            //    new SqlParameter("@TotalRecords", SqlDbType.Int) };
            //commandParameters[3].Direction = ParameterDirection.Output;

            ArrayList commandParameters = new ArrayList();
            {
                commandParameters.Add(new SqlParameter("@SurveyId", surveyId).SqlValue);
                commandParameters.Add(new SqlParameter("@CurrentPage", pageNumber).SqlValue);
                commandParameters.Add(new SqlParameter("@PageSize", pageSize).SqlValue);
                commandParameters.Add(new SqlParameter("@TotalRecords", SqlDbType.Int) { Direction = ParameterDirection.Output }.SqlValue);
            }


            DbConnection.db.LoadDataSet("vts_spInvitationLogGetAll", dataSet, new string[] { "InvitationLogs" }, commandParameters.ToArray());

            //totalRecords = int.Parse(commandParameters[3].ToString());

            totalRecords = dataSet.InvitationLogs.Rows.Count;

            return dataSet;
        }
        /// <summary>
        /// logs the exception that occured for the invitation in the db
        /// </summary>
        public void LogInvitationError(InvitationLogData invitationLog)
        {
            SqlConnection connection = new SqlConnection(DbConnection.NewDbConnectionString);
            SqlCommand insertCommand = new SqlCommand("vts_spInvitationLogAddNew", connection);

            insertCommand.CommandType = CommandType.StoredProcedure;

            insertCommand.Parameters.Add(new SqlParameter("@SurveyID", SqlDbType.Int, 4, "SurveyID"));
            insertCommand.Parameters.Add(new SqlParameter("@Email", SqlDbType.NVarChar, 0x9b, "Email"));
            insertCommand.Parameters.Add(new SqlParameter("@ExceptionMessage", SqlDbType.NVarChar, 0x400, "ExceptionMessage"));
            insertCommand.Parameters.Add(new SqlParameter("@ExceptionType", SqlDbType.NVarChar, 0xff, "ExceptionType"));
            insertCommand.Parameters.Add(new SqlParameter("@ErrorDate", SqlDbType.DateTime, 8, "ErrorDate"));
            insertCommand.Parameters.Add(new SqlParameter("@InvitationLogId", SqlDbType.Int, 4, "InvitationLogId"));
            insertCommand.Parameters["@InvitationLogId"].Direction = ParameterDirection.Output;
            insertCommand.Parameters.Add(new SqlParameter("@EmailId", SqlDbType.Int, 4, "EmailId"));
            insertCommand.Parameters["@EmailId"].Direction = ParameterDirection.Output;

            DbConnection.db.UpdateDataSet(invitationLog, "InvitationLogs", insertCommand, new SqlCommand(), new SqlCommand(), UpdateBehavior.Transactional);
        }
 /// <summary>
 /// logs the exception that occured for the invitation in the db
 /// </summary>
 public void LogInvitationError(InvitationLogData invitationLog)
 {
     VoterFactory.Create().LogInvitationError(invitationLog);
 }
 public InvitationLogsRowChangeEvent(InvitationLogData.InvitationLogsRow row, DataRowAction action)
 {
     this.eventRow = row;
     this.eventAction = action;
 }
 public void RemoveInvitationLogsRow(InvitationLogData.InvitationLogsRow row)
 {
     base.Rows.Remove(row);
 }
 public void AddInvitationLogsRow(InvitationLogData.InvitationLogsRow row)
 {
     base.Rows.Add(row);
 }
  /// <summary>
  /// description: ......
  /// </summary>
  /// <param name="sessionId">description .....</param>
  /// <param name="surveyId">description ....</param>
  /// <param name="anonymousEntries">description ..</param>
  /// <param name="mailingEmails">description .......</param>
  /// <param name="message">description ......</param>
  public void MailIt(string sessionId, int surveyId, bool anonymousEntries, string mailingEmails, EmailingMessage message)
  {
   IEmailing mailService = EmailingFactory.Create();
   string guid = null,
     taggedMessage = message.Body,
     email;
   string[] mailingList = mailingEmails.Split(',');

   SyncDataStore.SetRecords(sessionId + ":" + "Progress", 0);
   SyncDataStore.SetRecords(sessionId + ":" + "FailedEmails", 0);

   int failedEmails = 0;
    
   // Send the invitation email to the list
   for (int i = 0; i < mailingList.Length; i++)
   {
    email = mailingList[i].Trim();
    guid = null;
    try
    {
     guid = new Voter().GenerateVoterInvitationUId(surveyId, email, anonymousEntries);
     message.Body = message.Body.Replace("[--invitationid-]", guid);
     message.ToEmail = email;
     mailService.SendEmail(message);
     message.Body = taggedMessage;
    }
    catch (Exception ex)
    {
     try
     {
      if (guid != null)
      {
       // rollback db state if an email has been saved
       new Voter().DeleteVoterInvitation(surveyId, email);
      }

      InvitationLogData invitationLogs = new InvitationLogData();
      InvitationLogData.InvitationLogsRow invitationLog = invitationLogs.InvitationLogs.NewInvitationLogsRow();
      invitationLog.ExceptionMessage = (ex.InnerException != null && ex.InnerException.InnerException != null) ? 
       ex.InnerException.InnerException.Message : ex.Message.ToString();
      invitationLog.ExceptionType = (ex.InnerException != null && ex.InnerException.InnerException != null) ? 
       ex.InnerException.InnerException.GetType().ToString() : ex.GetType().ToString();
      invitationLog.SurveyId = surveyId;
      invitationLog.Email = email;
      invitationLog.ErrorDate = DateTime.Now;
      invitationLogs.InvitationLogs.AddInvitationLogsRow(invitationLog);
     
      // Log error in the database
      new Voter().LogInvitationError(invitationLogs);
      failedEmails++;
     }
     catch (Exception e)
     { 
      SyncDataStore.SetRecords(sessionId + ":" + "Error", e);
     }
    }

    SyncDataStore.UpdateRecords(sessionId + ":" + "Progress", (i * 100) / mailingList.Length);
    SyncDataStore.UpdateRecords(sessionId + ":" + "FailedEmails", failedEmails);
   }
  }