public List <ContactEntity> GetUserContactsOfPlayer(PlayerEntity player) { List <ContactInfo> fromDb = contactsDal.GetAllContactsOfUsername(player.Username);//contact info from the db, need to convert to contact entity List <ContactEntity> hirarchial = new List <ContactEntity>(); foreach (ContactInfo item in fromDb) { ContactEntity temp = hirarchial.FirstOrDefault(person => person.UserName == item.Username); if (temp == null) {//not exsits in the hirarchial, add him in the hirarchial and his info temp = new ContactEntity(item.Username); temp.Add(item.Type + " " + item.Val); hirarchial.Add(temp); } else {//exsits in the hirarchial, add his info temp.Add(item.Type + " " + item.Val); } } return(hirarchial); }