private static void RewardUser(IUserListBLL users, IAwardListBLL awards) { int temp = 0; var collection = users.GetAll(); if (awards.GetAll().Count() > 0) { foreach (var item in collection) { System.Console.WriteLine("{0} - {1}", ++temp, item); } System.Console.Write("Enter number: "); temp = 0; int.TryParse(System.Console.ReadLine(), out temp); if (temp > 0 && temp < collection.Count() + 1) { var selected_user = collection.ElementAt(temp - 1); Entites.AwardDTO selected_award; temp = 0; foreach (var item in awards.GetAll()) { System.Console.WriteLine("{0} - {1}", ++temp, item); } System.Console.Write("Enter number: "); temp = 0; int.TryParse(System.Console.ReadLine(), out temp); if (temp > 0 && temp < awards.GetAll().Count() + 1) { selected_award = awards.GetAll().ElementAt(temp - 1); var value = selected_user.Awards.FirstOrDefault(item => item.Name == selected_award.Name); if (value == null) { selected_user.Awards.Add(selected_award); selected_award.Users.Add(selected_user); System.Console.WriteLine("{0} - awarded with - \"{1}\" !", selected_user.Name, selected_award); } else { System.Console.WriteLine("This user already rewarded with this award"); } } } } else { System.Console.WriteLine("There is no awards. Please add some.. =)"); } }
private static void Remove(IAwardListBLL logic, IUserListBLL userslogic) { int temp = 0; var collection = logic.GetAll(); var users = userslogic.GetAll(); foreach (var item in collection) { System.Console.WriteLine("{0} - {1}", ++temp, item); } System.Console.Write("Enter number: "); temp = 0; int.TryParse(System.Console.ReadLine(), out temp); if (temp > 0 && temp < collection.Count() + 1) { var item = collection.ElementAt(temp - 1); foreach (var user in users) { var value = user.Awards.FirstOrDefault(i => i.Name == item.Name); if (value != null) { user.Awards.Remove(item); } } logic.Delete(item.Id); System.Console.WriteLine("{0} - Deleted!", item); } }