private CallButlerDataset.VoicemailsDataTable MergeVoicemailDataRows(DataRow[] rows)
 {
     CallButlerDataset.VoicemailsDataTable vmTable = new CallButlerDataset.VoicemailsDataTable();
     foreach (DataRow row in rows)
     {
         vmTable.LoadDataRow(row.ItemArray, true);
     }
     return vmTable;
 }
 public CallButlerDataset.VoicemailsDataTable GetNewEmployeeVoicemails(CallButlerAuthInfo authInfo, Guid extensionId)
 {
     if (Authenticate(authInfo))
     {
         CallButlerDataset.VoicemailsDataTable vmTable = GetVoicemails(authInfo, extensionId);
         CallButlerDataset.VoicemailsDataTable newVmTable = new CallButlerDataset.VoicemailsDataTable();
         DataRow[] rows = vmTable.Select("IsNew=true");
         return MergeVoicemailDataRows(rows);
     }
     else
     {
         return null;
     }
 }
        public void PersistVoicemailSound(CallButlerAuthInfo authInfo, Guid extensionID, CallButlerDataset.ExtensionsDataTable extensions, byte[] soundBytes)
        {
            if (Authenticate(authInfo))
            {
                CallButlerDataset.ExtensionsDataTable extensionTable = GetExtension(authInfo, extensionID);

                if (extensionTable.Rows.Count > 0)
                {
                    CallButlerDataset.ExtensionsRow extensionRow = (CallButlerDataset.ExtensionsRow)extensionTable.Rows[0];
                    string username = extensionRow.FirstName + " " + extensionRow.LastName;
                    string vmDirectory = WOSI.Utilities.FileUtils.GetApplicationRelativePath(Properties.Settings.Default.VoicemailRootDirectory);

                    if (!Directory.Exists(vmDirectory))
                        Directory.CreateDirectory(vmDirectory);

                    string fmt = "{0}\\{1}\\{2}.snd";

                    CallButlerDataset.VoicemailsDataTable voicemailTable = new CallButlerDataset.VoicemailsDataTable();

                    foreach (CallButlerDataset.ExtensionsRow extRow in extensions.Rows)
                    {
                        Guid voicemailID = Guid.NewGuid();
                        string vmFileName = String.Format(fmt, vmDirectory, extRow.ExtensionID, voicemailID);
                        WOSI.Utilities.FileUtils.SaveBytesToFile(vmFileName, soundBytes);

                        CallButlerDataset.VoicemailsRow row = voicemailTable.NewVoicemailsRow();

                        row.CallerDisplayName = username;
                        row.CallerHost = Services.PrivateLabelService.ReplaceProductName("CallButler");
                        row.CallerUsername = extensionRow.ExtensionNumber.ToString();
                        row.ExtensionID = extRow.ExtensionID;
                        row.IsNew = true;
                        row.Timestamp = System.DateTime.Now;
                        row.VoicemailID = voicemailID;

                        voicemailTable.Rows.Add(row);
                    }

                    PersistVoicemail(authInfo, voicemailTable);
                }
            }
        }