I would like to find out if I understand single responsibility principle correctly.
The function below is suppose to return user ID store in database by using the SAM account name pass into it.
Look at the commented codes below, is it true about the single responsibility of a function/method?
Do this function violate single responsibility principle if those codes are not commented?
public static int GetUserId(string domainName)
{
string message = "";
//Do not get badge number from this function,
//function should stay as single responsibility
//string badgeNumber = AsmUser.AsmUserHandler.GetBadgeNumber(domainName);
//if (badgeNumber == null)
//{
// message = "Badge number is null.";
// LogHandler.LogDebug(logger, message);
// return 0;
//}
//else
{
using (var db = new SurfaceTreatment.SurfaceTreatmentEntities())
{
string domain = domainName.Split('\\')[0].Trim();
string samAccountName = domainName.Split('\\')[1].Trim();
var user = db.t_ST_User
//.Where(_user => string.Compare(
// badgeNumber,
// _user.badgeNumber,
// StringComparison.OrdinalIgnoreCase) == 0)
.Where(_user => string.Compare(
domain,
_user.domainName.Trim(),
StringComparison.OrdinalIgnoreCase) == 0)
.Where(_user => string.Compare(
samAccountName,
_user.samAccountName.Trim(),
StringComparison.OrdinalIgnoreCase) == 0)
.Where(_user => _user.deleted == false)
.FirstOrDefault();
if (user == null)
{
message = "Failed to get user by badge number: " + domainName;
LogHandler.LogDebug(logger, message);
return 0;
}
else
{
return user.userId;
}
}
}
}