public Customer #region constructor ( int Id, string FirstName, string LastName, string Email, Gender Gender, int Age, PlayTennis PlayTennis, LikeFruit LikeFruit, string Ip ) { this.Id = Id; this.FirstName = FirstName; this.LastName = LastName; this.Email = Email; this.Gender = Gender; this.PlayTennis = PlayTennis; this.LikeFruit = LikeFruit; this.Age = Age; this.Ip = Ip; this.FullName = FirstName + " " + LastName; }
static void Module_Search_Enum(string fileName) { List <Customer> customerList = Parser.CreateListOfCustomers(fileName); List <Customer> hits = new List <Customer>(); string[] responseGenderOptions = new string[] { "Men", "Women", "Other", "Everybody" }; string[] responsePlayTennisOptions = new string[] { "that never play tennis", "that tried tennis once", "that seldom play tennis", "that play tennis once a year", "that play tennis once a moth", "that play tennis once a week", "that play tennis every day", "that play tennis often", "that play tennis any amount of time" }; string[] responseLikeFruitOptions = new string[] { "and like fruit", "but don't like fruit", "and have no opinion on fruit" }; string responseGender = string.Empty; string responsePlayTennis = string.Empty; string responseLikeFruit = string.Empty; Gender gender = Gender.NULL; PlayTennis playTennis = PlayTennis.NULL; LikeFruit likeFruit = LikeFruit.NULL; Console.Write("Gender: (M)ale (F)emale (O)ther (I)gnore: "); switch (Console.ReadLine().ToUpper()) { case "M": gender = Gender.Male; responseGender = responseGenderOptions[0]; break; case "F": gender = Gender.Female; responseGender = responseGenderOptions[1]; break; case "O": gender = Gender.Other; responseGender = responseGenderOptions[2]; break; default: gender = Gender.NULL; responseGender = responseGenderOptions[3]; break; } Console.Write("PlayTennis: (N)ever (O)nce (S)eldom (Y)early (M)onthly (W)eekly (D)aily (Of)ten (I)gnore: "); switch (Console.ReadLine().ToUpper()) { case "N": playTennis = PlayTennis.Never; responsePlayTennis = responsePlayTennisOptions[0]; break; case "O": playTennis = PlayTennis.Once; responsePlayTennis = responsePlayTennisOptions[1]; break; case "S": playTennis = PlayTennis.Seldom; responsePlayTennis = responsePlayTennisOptions[2]; break; case "Y": playTennis = PlayTennis.Yearly; responsePlayTennis = responsePlayTennisOptions[3]; break; case "M": playTennis = PlayTennis.Monthly; responsePlayTennis = responsePlayTennisOptions[4]; break; case "W": playTennis = PlayTennis.Weekly; responsePlayTennis = responsePlayTennisOptions[5]; break; case "D": playTennis = PlayTennis.Daily; responsePlayTennis = responsePlayTennisOptions[6]; break; case "OF": playTennis = PlayTennis.Often; responsePlayTennis = responsePlayTennisOptions[7]; break; default: playTennis = PlayTennis.NULL; responsePlayTennis = responsePlayTennisOptions[8]; break; } Console.Write("LikeFruit: (T)rue (F)alse (I)gnore: "); switch (Console.ReadLine().ToUpper()) { case "T": likeFruit = LikeFruit.True; responseLikeFruit = responseLikeFruitOptions[0]; break; case "F": likeFruit = LikeFruit.False; responseLikeFruit = responseLikeFruitOptions[1]; break; default: likeFruit = LikeFruit.NULL; responseLikeFruit = responseLikeFruitOptions[2]; break; } try { hits = (from c in customerList where (c.Gender == gender || gender == Gender.NULL) where (c.PlayTennis == playTennis || playTennis == PlayTennis.NULL) where (c.LikeFruit == likeFruit || likeFruit == LikeFruit.NULL) select c).ToList(); } catch { throw new Exception("Error - Search Enum"); } PrintMsg($"{responseGender} {responsePlayTennis} {responseLikeFruit}.", ConsoleColor.White); PrintMsg($"Number of hits: {hits.Count()}", ConsoleColor.White); foreach (var item in hits) { Console.ForegroundColor = ConsoleColor.Blue; Console.Write(item.FullName.PadRight(25) + "\t"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(item.Gender + "\t"); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(item.PlayTennis + "\t"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(item.LikeFruit + "\t"); Console.WriteLine(); } Console.ForegroundColor = ConsoleColor.White; Console.Write("Press RETUR to restart: "); Console.ReadLine(); Main(); }