public List <User> GetAllUsers() { List <User> users = new List <User>(); using (_ctx = new GuildCarsEntities()) { var listOfUsers = _ctx.GetAllUsers(); foreach (var user in listOfUsers) { User userToList = new User(); userToList.UserId = user.Id; userToList.Email = user.Email; userToList.Role = user.Name; string userName = user.UserName; string[] splitName = userName.Split(' '); userToList.FirstName = splitName[0]; if (splitName.Length > 1) { userToList.LastName = splitName[1]; } users.Add(userToList); } } return(users); }