Hi,
I have to following problem. I am programming in C#, I am using SelfServicing and I am using some Stored Procedures (SP's) to insert or update my projects / project tasks, since in the SP's there is some complicated stuff going on, so I don't use Project.Save() at this point.
So, the following is going on: I have a ProjectEntity Project. This Project has a collection of project tasks, called ProjectTask. A ProjectEntity can have 0 to N project tasks.
If the Project is not saved yet, it has a ProjectNo equal to 0, so I can check this or use the Project.IsNew property to check if the Project is new.
If so, I have to insert the project using a SP and in an output parameter I get the ProjectNo.
So after the SP has run, I set the ProjectNo value of the ProjectEntity to this new value and set the IsNew property to false.
This ProjectEntity is kept on the Session in my webapplication. In my ASPX page I create a ProjectManager instance which has a function:
public ProjectEntity SaveProject(ProjectEntity Project, bool LLBLGen)
In this function I call InsertProject task function and InsertProject function if it is a new Project
So after calling the InsertProject function I call this:
foreach (ProjectTaskEntity ProjectTask in Project.ProjectTask)
{
ProjectTask = InsertProjectTask(ProjectTask, t);
}
//Function:
private ProjectTaskEntity InsertProjectTask(ProjectTaskEntity ProjectTask, ITransaction t)
Now I have three questions:
1: How should I pass the transaction so in my SaveProject function I can put a try catch around everything and do a correct rollback of everything if something fails? Is this correct already, should I pass it as ref?
2: It complains that I can't set the ProjectTask Entity, because it is ReadOnly. How can I save the ProjectTaskObjNo and ProjectTaskNo then into my ProjectTask Entity? I also tried to use ref, but that the compiler complains again that it's readonly...
3: How should I pass the entities so that I can save them on the session after the functioncall?
So just to make clear, what I am doing is:
SaveProject(ProjectEntity)
{
Declare Transaction t
TRY
InsertProject(ProjectEntity, t)
Foreach ProjectTask
InsertProjectTask(ProjectTaskEntity, t)
t.Commit();
CATCH
t.RollBack();
and what I want after the SaveProject function in my ASPX page is saving the ProjectEntity with the new data to the session again. (so including new data also in all project tasks)