private static void RemoveAwardById() { Console.Write("Enter award's id: "); if (!int.TryParse(Console.ReadLine(), out int id)) { throw new ArgumentException("Id must be a number"); } _awardLogic.RemoveById(id); }
private static void AwardMode() { while (true) { AwardMenu(); if (!int.TryParse(Console.ReadLine(), out int Award)) { Console.WriteLine("Incorrect input. Try again."); continue; } switch (Award) { case 1: { Award award = CreateAward(); _awardLogic.Add(award); Console.WriteLine($"Award added {award.Id} : {award.Title}"); Console.WriteLine($"Press any key to continue"); Console.ReadLine(); break; } case 2: { int id = GetId(); Award award = _awardLogic.GetById(id); ShowAward(award); Console.WriteLine($"Press any key to continue"); Console.ReadLine(); break; } case 3: { ShowAllAwards(); Console.WriteLine($"Press any key to continue"); Console.ReadLine(); break; } case 4: { int id = GetId(); if (_awardLogic.RemoveById(id)) { _userLogic.RemoveInUsers(id); Console.WriteLine($"Award {id} is removed."); } else { Console.WriteLine("Wrong id."); } Console.WriteLine($"Press any key to continue"); Console.ReadLine(); break; } case 0: default: break; } if (Award == 0) { break; } Console.Clear(); } }
public static bool RemoveAward(int id) { return(_awardLogic.RemoveById(id)); }
private static void Run() { while (true) { Console.Clear(); ShowMenu(); if (!int.TryParse(Console.ReadLine(), out int selectMode)) { Console.WriteLine("Incorrect input. Try again:"); continue; } switch (selectMode) { //"1. Show all Users in DB" case 1: { Console.Clear(); Console.WriteLine("List of Users in DB."); ShowUsersWithAwards(); Console.ReadLine(); break; } //"2. Add User to DB." case 2: { Console.Clear(); Console.WriteLine("Adding User to DB."); var userToAdd = Service.CreateUser(); _userLogic.Add(userToAdd); Console.WriteLine($"User has been added to DB. ID = {userToAdd.Id}"); Console.ReadLine(); break; } //"3. Remove User with specified." case 3: { Console.Clear(); Console.WriteLine("Removing User from DB."); ShowUsersWithAwards(); var idToRemove = Service.GetId(); if (_userLogic.RemoveById(idToRemove)) { Console.WriteLine($"User with ID = {idToRemove} is removed from DB."); } else { Console.WriteLine($"User with ID = {idToRemove} not found."); } Console.ReadLine(); break; } //"4. Show all Awards in DB" case 4: { Console.Clear(); Console.WriteLine("List of Awards in DB."); ShowAwards(); Console.ReadLine(); break; } //"5. Add Award to DB." case 5: { Console.Clear(); Console.WriteLine("Adding Award to DB."); var awardToAdd = Service.CreateAward(); _awardLogic.Add(awardToAdd); Console.WriteLine($"Award has been added to DB. ID = {awardToAdd.Id}"); Console.ReadLine(); break; } //"6. Remove Award with specified ID." case 6: { Console.Clear(); Console.WriteLine("Removing Award from DB."); ShowAwards(); var idToRemove = Service.GetId(); if (_awardLogic.RemoveById(idToRemove)) { Console.WriteLine($"Award with ID = {idToRemove} is removed from DB."); } else { Console.WriteLine($"Award with ID = {idToRemove} not found."); } Console.ReadLine(); break; } //"7. Give Award to User." case 7: { Console.Clear(); Console.WriteLine("Give Award to User." + Environment.NewLine); ShowUsersWithAwards(); Console.WriteLine(); Console.WriteLine("Select User to be given Award:"); var userId = Service.GetId(); Console.WriteLine(); ShowAwards(); Console.WriteLine(); Console.WriteLine("Select Award to be given to User:"******"Award has been given to User."); } else { Console.WriteLine("Award cannot be given to User."); } Console.ReadLine(); break; } //"8. Take Award from User." case 8: { Console.Clear(); Console.WriteLine("Take Award from User." + Environment.NewLine); ShowUsersWithAwards(); Console.WriteLine(); Console.WriteLine("Select User to be taken Award:"); var userId = Service.GetId(); Console.WriteLine(); if (!ShowAwardsOfUser(userId)) { Console.ReadLine(); break; } Console.WriteLine(); Console.WriteLine("Select Award to be taken from User:"******"Award has been taken from User."); } else { Console.WriteLine("Award cannot be taken from User."); } Console.ReadLine(); break; } //"0. Exit." case 0: default: { break; } } if (selectMode == 0) { break; } } }
private static void AwardMode() { while (true) { ShowAwardMenu(); if (!int.TryParse(Console.ReadLine(), out int selectAward)) { Console.WriteLine("Incorrect input. Try again."); continue; } switch (selectAward) { // add new award case 1: { Award award = CreateAward(); _awardLogic.Add(award); Console.WriteLine($"Award added. Awards's ID is {award.Id}"); Console.ReadLine(); break; } // get award by id case 2: { int id = GetId(); Award award = _awardLogic.GetById(id); ShowAward(award); Console.ReadLine(); break; } // show all awards case 3: { ShowAllAwards(); Console.ReadLine(); break; } // remove award by id case 4: { int id = GetId(); if (_awardLogic.RemoveById(id)) { Console.WriteLine($"Award with ID = {id} is removed."); } else { Console.WriteLine(NO_AWARD_ID); } Console.ReadLine(); break; } // exit case 0: default: break; } if (selectAward == 0) { break; } Console.Clear(); } }