using System.Collections.Generic;
namespace PeopleConsoleApplication
static List<Person> people = Database.GetPeople();
static void Main(string[] args)
Console.WriteLine("Program START");
Console.WriteLine("Select a command: list, \n add, \n edit, \n delete, \n listbyname, \n listbyid, \n listmen, \n listwomen, \n listbyscore, \n purgefailure, \n exit");
string command = Console.ReadLine();
if (command == "listbyname")
List<Person> listMen = people.Where(p => p.Gender == Sex.Male).ToList();
if (command == "listbyid")
List<Person> listById = people.OrderBy(p => p.Id).ToList();
if (command == "listmen")
List<Person> listMen = people.Where(p => p.Gender == Sex.Male).ToList();
if (command == "listwomen")
List<Person> listWomen = people.Where(p => p.Gender == Sex.Male).ToList();
if (command == "listbyscore")
List<Person> listByScore = people.OrderBy(p => p.Score).ToList();
if (command == "purgefailure")
Console.WriteLine("Program END");
static void List(List<Person> lstPeople)
lstPeople = lstPeople != null ? people : lstPeople;
Console.WriteLine("=======PEOPLE=======");
if (people != null && people.Count != 0)
foreach (var person in people)
nameLength = nameLength > person.Name.Length ? nameLength : person.Name.Length;
Console.WriteLine("Id " + "Name".PadRight(nameLength + 2) + "Gender".PadRight(nameLength + 2) + "Score".PadRight(nameLength + 2));
foreach (var person in people)
StringBuilder sbPerson = new StringBuilder();
sbPerson.Append(person.Id.ToString().PadRight(4));
sbPerson.Append(person.Name.PadRight(nameLength + 2));
sbPerson.Append(person.Gender.ToString().PadRight(nameLength + 2));
sbPerson.Append(person.Score.ToString().PadRight(nameLength + 2));
Console.WriteLine(sbPerson.ToString());
Console.WriteLine("Input Id#");
string id = Console.ReadLine();
Console.WriteLine("Input Name");
string name = Console.ReadLine();
Console.WriteLine("Input Gender");
string gender = Console.ReadLine();
Console.WriteLine("Input Score");
string score = Console.ReadLine();
Person person = new Person();
person.Id = Convert.ToInt32(id);
if (gender.ToUpper().Equals("M") || gender.Equals("Male"))
person.Gender = Sex.Male;
else if (gender.ToUpper().Equals("F") || gender.Equals("Female"))
person.Gender = Sex.Female;
person.Score = Convert.ToInt32(score);
Console.WriteLine("Input ID# to edit:");
string id = Console.ReadLine();
string gender = string.Empty;
string score = string.Empty;
var editPerson = people.Where(p => p.Id == Convert.ToInt32(id));
foreach (var item in editPerson)
Console.WriteLine("Input Name:");
item.Name = Console.ReadLine();
Console.WriteLine("Input Gender");
gender = Console.ReadLine();
if (gender.ToUpper().Equals("M") || gender.Equals("Male"))
else if (gender.ToUpper().Equals("F") || gender.Equals("Female"))
item.Gender = Sex.Female;
Console.WriteLine("Input Score");
score = Console.ReadLine();
item.Score = Convert.ToInt32(score);
Console.WriteLine("Input ID# to delete or All to delete all records.");
string id = Console.ReadLine();
if (id.ToUpper() == "ALL")
people.RemoveAll(p => p.Id == Convert.ToInt32(id));
static void PurgeFailure()
people.RemoveAll(p => p.Score < 70);
public static List<Person> GetPeople()
var result = new List<Person>();
Name = "Juanita Dela Cruz",
public int Id { get; set; }
public string Name { get; set; }
public Sex Gender { get; set; }
public int Score { get; set; }