Hi,
Here are the two methods I'm having in my code:
protected void SaveNotes()
{
Transaction TransactionManager = new Transaction(IsolationLevel.ReadCommitted, "SaveNotes");
try
{
ApplicantNoteEntity Note = new ApplicantNoteEntity();
Note.ApplicantId = ApplicantID;
Note.Note = NotesTextBox.Text;
Note.NoteAddedDate = DateTime.Now;
Note.NoteAddedAuthor = "amahendrakar";
TransactionManager.Add(Note);
Note.Save();
TransactionManager.Commit();
LoadNotes();
CurrentNotesPanel.Visible = true;
}
catch(Exception ex)
{
JobApplicationAdmin.Site.Log.Error(ex);
MessageLabel.Text = "An error has occurred. Please inform the Admin.";
MessageLabel.Visible = true;
TransactionManager.Rollback();
MessageLabel.CssClass = "errorMessage";
}
finally
{
TransactionManager.Dispose();
}
}
private void LoadNotes()
{
IPredicateExpression Filter = new PredicateExpression(ApplicantNoteFields.ApplicantId == ApplicantID);
ApplicantNoteCollection Note = new ApplicantNoteCollection();
Note.GetMulti(Filter);
if (Note.Count > 0)
{
StringBuilder Notes = new StringBuilder();
for (int i = 0; i < Note.Count; i++)
{
Notes.AppendFormat("Author: {0}{1}", Note[i].NoteAddedAuthor, Environment.NewLine);
Notes.AppendFormat("Date: {0}{1}", Note[i].NoteAddedDate.ToString("MM/dd/yyyy"), Environment.NewLine);
Notes.AppendFormat("Note: {0}{1}", Note[i].Note, Environment.NewLine);
Notes.AppendFormat("-------------------------------{0}", Environment.NewLine);
}
CurrentNotesTextBox.Text = Notes.ToString();
}
else
{
CurrentNotesTextBox.Text = "No notes added";
}
}
All I'm trying to do is, if there is an error while saving the Note entity, I need to rollback the transaction, if not the transaction gets committed. My question is what happens if the transaction gets committed and an exception occurs in the LoadNotes method? It goes to the catch block of the SaveNotes method and what happens when it tries to do a rollback?
How else could this be coded?
Thanks in advance,
Arun