I am currently developing a phone book in our Intranet (ASP.NET) that pulls out information from our Active Directory and stores them in a List
We have several branches in the country, and i need the employees to be shown grouped by branch, which i did using the following:
lstADUsers.Sort(delegate (MyUser x, MyUser y)
{
return x.Branch.CompareTo(y.Branch);
});
The problem is that i also want to apply a second sort, so employees are shown ordered by branch name and then in order of relevance (job position). So i want to show vicepresidents first, then managers, then engineers and such... I currently don't have that sort order stored anywhere, so i though of assigning each job position some kind of weight or priority and store it somewhere (database? map?)
I would appreciate any help in this matter. Thanks
EDIT: i would like an efficient method to store the weight of the second property. Right now i solved this by creating a property type int and then assigning weight manually with the following code:
if (objUsuarios.Cargo.Contains("something"))
{
objUsuarios.OrdenCargo = 1;
}
else if (objUsuarios.Cargo.Contains("another thing"))
{
objUsuarios.OrdenCargo = 2;
}
and in my delegate i am using a triple sort, first by branch, then by job, then by employee name:
lstADUsers.Sort(delegate (Usuario x, Usuario y)
{
int valor = x.Piso.CompareTo(y.Piso);
if (valor != 0)
return x.Piso.CompareTo(y.Piso);
else
{
int valorordencargo = x.OrdenCargo.CompareTo(y.OrdenCargo);
if (valorordencargo != 0)
return x.OrdenCargo.CompareTo(y.OrdenCargo);
else
{
int valornombrecargo = x.Cargo.CompareTo(y.Cargo);
if (valornombrecargo != 0)
return x.Cargo.CompareTo(y.Cargo);
else
{
return x.Nombre.CompareTo(y.Nombre);
}
}
}
});