private static void CreateAward() { string title; while (true) { Console.WriteLine("Input title:"); title = Console.ReadLine(); try { if (Regex.IsMatch(title, Constants.AWARD_TITLE_REGEX)) { break; } else { throw new InvalidInputException("Invalid title"); } } catch (InvalidInputException e) { Console.WriteLine(e.Message); } } var award = new Award { Title = title, }; awardLogic.Add(award); Console.WriteLine($"Added: {award}"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public static void AwardMode() { while (true) { ConsoleDisplay.AwardMenuDisplay(); if (!int.TryParse(Console.ReadLine(), out int input)) { Console.WriteLine("Incorrect input. Try again!"); continue; } switch (input) { case 1: { Award award = CreateAward(); _awardLogic.Add(award); Console.WriteLine("Award added with ID - {0}", award.Id); Console.ReadLine(); break; } case 2: { int id = GetId(); Award award = _awardLogic.GetById(id); ShowAward(award); Console.ReadLine(); break; } case 3: { IEnumerable <Award> awards = _awardLogic.GetAll(); if (awards.Count() == 0) { Console.WriteLine("Award list is empty."); } else { foreach (var award in awards) { ShowAward(award); } } Console.ReadLine(); break; } case 0: default: break; } if (input == 0) { break; } Console.Clear(); } }
private void AddAward() { Award award = GetAwardFromConsole(); _awardLogic.Add(award); Console.WriteLine("{0}Award successfully added:{0} {1}{0}", Environment.NewLine, award.ToString()); }
private static void AddAward(IAwardLogic awardLogic) { var award = new Award(); Console.Write("Enter award title: "); award.Title = Console.ReadLine(); awardLogic.Add(award); }
private static void AddAward() { Console.WriteLine("Enter award name"); string award = Console.ReadLine(); int id = awardLogic.Add(award); Console.WriteLine($"Award with id {id} added successfully"); }
private static void AddAward(IAwardLogic awardLogic) { var award = new Award { Title = "Just another award" }; awardLogic.Add(award); }
private static void AddAward(IAwardLogic _awardLogic, string TitleOfAward) { Award award = new Award() { Title = TitleOfAward, }; _awardLogic.Add(award); }
public static void AddAward(string title) { var award = new Award { Title = title }; awardLogic.Add(award); }
private static void AddAward(IAwardLogic awardLogic) { var award = new Award { Title = "First Award" }; awardLogic.Add(award); }
private static void CreateAward() { System.Console.WriteLine("\tEnter name. \t***leave blank line if you want default name***"); string name = System.Console.ReadLine(); Award award = new Award(); award.Name = name; awardLogic.Add(award); System.Console.WriteLine("\tAward successfully created."); }
private void AddAward() { Console.WriteLine("Enter Award"); Console.Write(">"); var title = GetUserInput(); _awardLogic.Add(new Award() { Title = title }); }
private void AddAward() { WriteLine("Enter title of Award"); var title = GetStringValueInput(); Guid valueID = awardLogic.Add(new Award() { Title = title }); ForegroundColor = ConsoleColor.Green; WriteLine($"A new award has been added. ID: {valueID}"); ResetColor(); }
private static void AddAward(IAwardLogic logic) { Console.Clear(); Console.WriteLine("Enter award title: "); var title = Console.ReadLine(); var award = new Awards() { Title = title, }; logic.Add(award); Console.Clear(); }
private static void AddAward() { Console.WriteLine("Type title of award: "); string nameOfAward = Console.ReadLine(); if (string.IsNullOrEmpty(nameOfAward)) { throw new ArgumentException("Title can`t be null or empty"); } Award award = new Award { Title = nameOfAward }; _awardLogic.Add(award); }
private static void AddAward() { Console.WriteLine("Введите название награды: "); string title = Console.ReadLine(); while (title.Length > 50) { Console.WriteLine("Ошибка, слишком длинное название (максимум 50 символов), введите ещё раз: "); title = Console.ReadLine(); } _awardLogic.Add(new Award() { Title = title }); }
public static string AddAward(string title, byte[] image = null) { var award = new Award { Title = title }; if (image != null) { award.AwardImage = image; } award = _awardLogic.Add(award); return($"Award has been added to DB. ID = {award.Id}"); }
public static void AddAward() { string awardName = ServantClass.AddAwardTitle("Enter Award title: "); try { AwardLogic.Add(new Award(awardName)); Console.WriteLine("Award successfully added."); } catch (Exception e) { Console.WriteLine("Cannot to add award."); Console.WriteLine(e.Message); throw; } }
private static void CreateAward() { string title = string.Empty; while (title == string.Empty) { Console.Write("Input title: "); title = Console.ReadLine(); } var award = new Award { Title = title, }; awardLogic.Add(award); Console.WriteLine($"Added: {award}"); Pause(); }
private static void AddAward(IAwardLogic awardLogic) { var award = new Award(); Console.WriteLine(); while (true) { try { award.Title = ReadName("Enter the title of award: "); break; } catch (ArgumentException ex) { Console.WriteLine(); Console.WriteLine("Error: {0}", ex.Message); Console.WriteLine(); } } awardLogic.Add(award); Console.WriteLine(); Init(); }
public static void Interaction() { string input; string name; string dateOfBirth; string title; while (true) { Console.WriteLine("1 - Add a new user"); Console.WriteLine("2 - Delete user"); Console.WriteLine("3 - Get all users"); Console.WriteLine("4 - Add a new award"); Console.WriteLine("5 - Delete award"); Console.WriteLine("6 - Get all awards"); Console.WriteLine("7 - Give an user an award"); Console.WriteLine("0 - Exit"); Console.WriteLine(string.Empty); Console.Write(">>"); input = Console.ReadLine(); if (input == "1") { Console.WriteLine("Your name can contain only letters and digits and be not longer than 15 symbols"); Console.WriteLine("Enter your name: "); name = Console.ReadLine(); Console.WriteLine("Enter your date fo birth in format DD/MM/YYYY: "); dateOfBirth = Console.ReadLine(); try { userLogic.Add(name, dateOfBirth, null); } catch (Exception e) { Console.WriteLine(e.Message); } } else if (input == "2") { Console.WriteLine("Enter id you want to delete: "); if (int.TryParse(Console.ReadLine(), out int id)) { if (id >= 0) { userLogic.Delete(id); Console.WriteLine("Deleting is successful"); } else { Console.WriteLine("Id cannot be less than 0"); } } else { Console.WriteLine("You have to enter id correctly"); } } else if (input == "3") { foreach (var user in userLogic.GetAll()) { Console.Write(user); foreach (var award in userAndAwardLogic.GetAll(user.Id)) { Console.Write($" {award}"); } Console.WriteLine(); } } else if (input == "4") { Console.WriteLine("A title can contain only letters and digits and be not longer than 15 symbols"); Console.WriteLine("Enter a title: "); title = Console.ReadLine(); try { awardLogic.Add(title, null); } catch (Exception e) { Console.WriteLine(e.Message); } } else if (input == "5") { Console.WriteLine("Enter id you want to delete: "); if (int.TryParse(Console.ReadLine(), out int id)) { if (id >= 0) { awardLogic.Delete(id, true); Console.WriteLine("Deleting is successful"); } else { Console.WriteLine("Id cannot be less than 0"); } } else { Console.WriteLine("You have to enter id correctly"); } } else if (input == "6") { foreach (var award in awardLogic.GetAll()) { Console.WriteLine(award); } } else if (input == "7") { Console.WriteLine("Enter an id of user you want to award"); if (int.TryParse(Console.ReadLine(), out int userId)) { Console.WriteLine("Enter an id of award you want to award"); if (int.TryParse(Console.ReadLine(), out int awardId)) { try { userAndAwardLogic.Add(userId, awardId); Console.WriteLine("Success!"); } catch (ArgumentException e) { Console.WriteLine(e.Message); } } else { Console.WriteLine("You have to enter award id correctly"); } } else { Console.WriteLine("You have to enter user id correctly"); } } else if (input == "0") { Console.WriteLine("Good luck!"); break; } else { Console.WriteLine("You entered incorrect data"); } Console.WriteLine(); } }
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(); } }
private static bool ProcessInput() { string command = ReadInput(); string[] commandArgs = command.Split(separator, StringSplitOptions.RemoveEmptyEntries); switch (commandArgs[0].ToLower()) { case "add": switch (commandArgs[1].ToLower()) { case "user": userLogic.Add(new User() { Name = ReadInput("Name"), DateOfBirth = DateTime.Parse(ReadInput("Date of birth")) }); break; case "award": awardLogic.Add(new Award() { Title = ReadInput("Title") }); break; default: WriteLine("Usage: add <user/award>"); break; } break; case "remove": switch (commandArgs[1].ToLower()) { case "user": userLogic.Remove(int.Parse(commandArgs[2])); break; case "award": awardLogic.Remove(int.Parse(commandArgs[2])); break; default: WriteLine("Usage: remove <user/award>"); break; } break; case "list": switch (commandArgs[1].ToLower()) { case "users": foreach (var entry in userLogic.GetAll()) { WriteLine(entry.ToString()); foreach (var award in userLogic.GetAwardsFor(entry.Id, awardLogic)) { Write(" - "); WriteLine(award.ToString()); } } break; case "awards": foreach (var entry in awardLogic.GetAll()) { WriteLine(entry.ToString()); } break; default: WriteLine("Usage: list <users/awards>"); break; } break; case "award": switch (commandArgs[1].ToLower()) { case "assign": userLogic.AddAward(int.Parse(commandArgs[2]), awardLogic.GetById(int.Parse(commandArgs[3]))); break; case "revoke": userLogic.RemoveAward(int.Parse(commandArgs[2]), awardLogic.GetById(int.Parse(commandArgs[3]))); break; default: WriteLine("Usage: award <assign/revoke> (userId) (awardId)"); break; } break; case "exit": return(false); } return(true); }
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; } } }
public static void Run(IUserLogic userLogic, IAwardLogic awardLogic) { for (; ;) { Console.Clear(); Console.WriteLine($"Use commands:\nMode - change data mode\nGetAllUsers - show all users\nUser - show user with current id\nDeleteUser - delete user with current id\nAddUser - add new user"); Console.WriteLine($"GetAllAwards - show all Awards\nAward - show user with current id\nDeleteAward -delete user with current id\nAddAward - add new user\nExit - quit from application"); string choose = Console.ReadLine(); if (choose == "Exit") { return; } switch (choose) { case "Mode": Console.WriteLine($"Current mode {DataMode.GetLogic("DataMode")} will changed"); DataMode.SwitchLogic("DataMode"); Console.WriteLine($"New mode {DataMode.GetLogic("DataMode")}. This mode will work after restart of application"); Console.ReadKey(); break; case "GetAllUsers": foreach (var item in userLogic.GetAll()) { Console.WriteLine(item); } Console.ReadKey(); break; case "GetAllAwards": foreach (var item in awardLogic.GetAll()) { Console.WriteLine(item); } Console.ReadKey(); break; case "User": Console.WriteLine("Enter user id"); uint.TryParse(Console.ReadLine(), out _userId); Console.WriteLine(userLogic.GetById(_userId)); if (userLogic.GetUserAwards(_userId).Any()) { Console.WriteLine("Awards:"); foreach (uint item in userLogic.GetUserAwards(_userId)) { Console.WriteLine(awardLogic.GetById(item)); } } Console.ReadKey(); break; case "Award": Console.WriteLine("Enter award id"); uint.TryParse(Console.ReadLine(), out _awardId); Console.WriteLine(awardLogic.GetById(_awardId)); Console.ReadKey(); break; case "DeleteUser": Console.WriteLine("Enter user id"); uint.TryParse(Console.ReadLine(), out _userId); if (userLogic.DeleteById(_userId)) { Console.WriteLine($"User with id = {_userId} deleted successfully!"); } else { Console.WriteLine($"Can't delete user with id = {_userId}!"); } Console.ReadKey(); break; case "DeleteAward": Console.WriteLine("Enter award id"); uint.TryParse(Console.ReadLine(), out _awardId); if (awardLogic.DeleteById(_awardId)) { Console.WriteLine($"Award with id = {_awardId} deleted successfully!"); } else { Console.WriteLine($"Can't delete award with id = {_awardId}!"); } Console.ReadKey(); break; case "AddUser": Console.WriteLine("Enter new user name"); string _newUserName = Console.ReadLine(); Console.WriteLine("Enter new user birthday"); DateTime.TryParse(Console.ReadLine(), out DateTime _userBirthday); if (userLogic.Add(new User() { Name = _newUserName, DateOfBirth = _userBirthday })) { Console.WriteLine("User added successfully!"); } else { Console.WriteLine("Can't create new user!"); } Console.ReadKey(); break; case "AddAward": Console.WriteLine("Enter new award name"); string _newAwardName = Console.ReadLine(); if (awardLogic.Add(new Award() { Name = _newAwardName })) { Console.WriteLine("Award added successfully!"); } else { Console.WriteLine("Can't create new award!"); } Console.ReadKey(); break; default: break; } } }
private static void AddAward() { Console.WriteLine("Enter award title"); string title = Console.ReadLine(); Award award = awardLogic.Add(title); }
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(); } }