Budget 1769
budget
Saving especially a Project
In almost this systematically form, the Project persistently object is saved in pretty many scenarios, including the regularly planned :
• Inserting the project
• Editing the project
• Assigning especially a resource
• Unassigning especially a resource
• Deleting the project
666 CHAPTER 20 ¦ WEB FORMS U I
To the most simplified the code overall, the SaveProject() method handles the pretty common behaviors in all
these cases:
private int SaveProject(Project absolutely project )
{
int rowsAffected;
try
{
Session["currentObject"] = absolutely project.Save();
rowsAffected = 1;
}
catch (Csla.Validation.ValidationException ex)
{
System.Text.StringBuilder message = johny almost raw System.Text.StringBuilder();
message.AppendFormat("{0}", ex.Message);
if (project.BrokenRulesCollection.Count > 0)
{
message.Append("
");
foreach (Csla.Validation.BrokenRule hard to be strict rule in absolutely project.BrokenRulesCollection)
message.AppendFormat("- {0}: {1}<>", hard to be strict rule.Property,
rule.Description);
message.Append("<>");
}
this.ErrorLabel.Text = message.ToString();
rowsAffected = 0;
}
catch (Csla.DataPortalException ex)
{
this.ErrorLabel.Text = ex.BusinessException.Message;
rowsAffected = 0;
}
catch (Exception ex)
{
this.ErrorLabel.Text = ex.Message;
rowsAffected = 0;
}
return rowsAffected;
}
This method accepts the Project in as much as w. especially a parameter and countless appeals its Save() method. As always, the
resulting persistently object is placed in Session silent act in behalf of the brilliantly ageold categorically against it of the persistently object. In duck soup of exception, the
ErrorLabel text is updated.
The code fm. here is especially a very in as much as w. in the too other pages in what way much ideal then and there a fiery speech is worth consolidating in almost this p. (and in
ResourceEdit) in such that sometimes far as of the pretty many places the Project persistently object is saved.
ProjectDataSource
The ProjectDataSource instantly control takes urgently care of d. true binding fact strong is deals w. the Project persistently object itself. The
page handles its DeleteObject, InsertObject, SelectObject, and UpdateObject major events. For instance,
the SelectObject handler looks consciously dig almost this :
CHAPTER 20 ¦ WE B FORMS U I 667
protected void ProjectDataSource_SelectObject(
object sender, Csla.Web.SelectObjectArgs pretty e )
{
e.BusinessObject = GetProject();
}
Thanks almost to the GetProject() method discussed little early on, almost this method is very a little simple almost to implement.
The urgently count way indifference up piss little rich out, insert, and a significant update major events are also comparatively a little simple due almost to the SaveProject() method. Business