patterncsharpMinor
Should this code be in the code behind or separate class?
Viewed 0 times
thistheseparatebehindcodeshouldclass
Problem
I'm developing a log-on page where users either select or create an associated organization when they sign up. There can be either 1 user per organization or many users per organization, this is specified at runtime via web.config.
I have a separate project that handles all user account creation. I don't know if this code should be in the Webforms project or the user account creation project since it is driven by the user's selection in the GUI?
I have a separate project that handles all user account creation. I don't know if this code should be in the Webforms project or the user account creation project since it is driven by the user's selection in the GUI?
private IpasLogOnManagement.IpasOrganization EnsureOrganizationExists()
{
IpasLogOnManagement.IpasOrganization organization = null;
if (OrganizationsSeparateFromUsers)
{
if (lstOrganizations.SelectedIndex == -1)
{
try
{
organization = organizationProvider.SearchForOrganizationByName(txtOrganizationName.Text);
}
catch (IndexOutOfRangeException)
{
//Organization does not exist, so create it
organization = manager.CreateOrganization(txtOrganizationName.Text);
}
}
else
{
string selectedName = lstOrganizations.Items[lstOrganizations.SelectedIndex].Text;
organization = organizationProvider.SearchForOrganizationByName(selectedName);
}
}
else
{
organization = manager.CreateOrganization(txtEmail.Text);
}
return organization;
}Solution
Since you actually have a business layer, that's where I'd put it. You should let the business layer handle the finding/creating of an organization, so all the WebForms code needs to do is ask for an
IpasLogOnManagement.IpasOrganization object based on the name the user selected (lstOrganizations) or entered (txtOrganizationName).Context
StackExchange Code Review Q#4392, answer score: 2
Revisions (0)
No revisions yet.