Is there a better way of writing the following method? Using LINQ maybe?
Instead of declaring a new list and then using a foreach to populate the list, is there a better way of doing this maybe in one line using LINQ?
public IEnumerable<RoleAreasModel> GetRolesWithRoleAreasModelByUserGUID(Guid guid)
{
IList<RoleAreasModel> rolesWithRoleAreas = new List<RoleAreasModel>();
foreach (AspnetRolesRecord role in GetByUserGUID(guid))
{
RoleAreasRecord roleAreaRecord = RoleAreasService.Instance.GetRecord(RoleAreasRecord.Fields.ID, role.ID);
rolesWithRoleAreas.Add(new RoleAreasModel(roleAreaRecord.Area, new RolesMapper().MapToModel(role), getAreaControllersData(roleAreaRecord.ID)));
}
return rolesWithRoleAreas;
}
1 Answer