예제 #1
0
        //дейтсвия для Awards
        private static void AwardsAction()
        {
            while (true)
            {
                Console.WriteLine();
                Console.WriteLine($"1: Find award by ID");
                Console.WriteLine($"2: Find award by Name");
                Console.WriteLine($"3: Find award by the first letter");
                Console.WriteLine($"4: Find award whose name includes the entered word");
                Console.WriteLine($"5: Delete award");
                Console.WriteLine($"6: Edit award");
                Console.WriteLine($"7: EXIT");

                Console.Write("Choose action: ");

                var userEnter = Console.ReadLine();

                switch (userEnter)
                {
                case "1":
                    Console.Write($"Award's ID: ");
                    var id_1     = Console.ReadLine();
                    var result_1 = awardLogic.GetAwardById(id_1);
                    Console.WriteLine($"{result_1.IdAward} : {result_1.Title} : {result_1.Description}{Environment.NewLine}");
                    break;

                case "2":
                    Console.Write($"Award's Title: ");
                    var name_2 = Console.ReadLine();
                    foreach (var item in awardLogic.GetAwardByTitle(name_2))
                    {
                        Console.WriteLine($"{item.IdAward} : {item.Title} : {item.Description}{Environment.NewLine}");
                    }
                    break;

                case "3":
                    Console.Write($"Write letter: ");
                    var letter_3 = Console.ReadLine();
                    foreach (var item in awardLogic.GetAwardByLetter(letter_3))
                    {
                        Console.WriteLine($"{item.IdAward} : {item.Title} : {item.Description}{Environment.NewLine}");
                    }
                    break;

                case "4":
                    Console.Write($"Write word: ");
                    var word = Console.ReadLine();
                    foreach (var item in awardLogic.GetAwardByWord(word))
                    {
                        Console.WriteLine($"{item.IdAward} : {item.Title} : {item.Description}{Environment.NewLine}");
                    }
                    break;

                case "5":
                    Console.Write($"Award's ID: ");
                    var id_5 = Console.ReadLine();
                    awardLogic.DeleteAward(id_5);
                    break;

                case "6":
                    Console.Write($"award's ID: ");
                    var id_6     = Console.ReadLine();
                    var result_6 = awardLogic.GetAwardById(id_6);
                    Console.Write($"award's Titile: ");
                    var title = Console.ReadLine();
                    Console.Write($"award's Description: ");
                    var description = Console.ReadLine();
                    awardLogic.UpdateAward(id_6, title, description);
                    break;

                case "7":
                    return;

                default:
                    break;
                }
            }
        }
예제 #2
0
 public bool DeleteAward(int id)
 {
     return(awardBll.DeleteAward(id));
 }
예제 #3
0
 public static void DeleteAward(IAwardLogic awardLogic, int Id)
 {
     awardLogic.DeleteAward(Id);
 }
예제 #4
0
 private static void DeleteAward(IAwardLogic awardLogic, int Id)
 {
     awardLogic.DeleteAward(Id);
 }
예제 #5
0
        static void Main(string[] args)
        {
            IUserLogic  uLogic  = DependencyResolver.ULogic;
            IAwardLogic awLogic = DependencyResolver.ALogic;
            bool        correct = true;

            while (correct)
            {
                Console.WriteLine("Choose an option");
                Console.WriteLine("1: Create user");
                Console.WriteLine("2: Delete user");
                Console.WriteLine("3: Display users");
                Console.WriteLine("4: Create award");
                Console.WriteLine("5: Delete award");
                Console.WriteLine("6: Display all awards");
                Console.WriteLine("7: To award");
                Console.WriteLine("8: Display user awards");
                Console.WriteLine("0: Exit");
                string option = Console.ReadLine();

                switch (option)
                {
                case "0":
                    correct = false;
                    break;

                case "1":

                    Console.WriteLine("Enter name");
                    string name = Console.ReadLine();
                    Console.WriteLine("Enter Date of birth");
                    string dateOfBirth = Console.ReadLine();
                    bool   success     = uLogic.CreateUser(name, dateOfBirth);
                    if (success)
                    {
                        Console.WriteLine("User saved successfuly");
                    }
                    else
                    {
                        Console.WriteLine("User saving failed, pleace check data");
                    }
                    break;

                case "2":
                    Console.WriteLine("Enter ID");
                    string id = Console.ReadLine();
                    if (int.TryParse(id, out int numId))
                    {
                        uLogic.DeleteUser(numId);
                    }
                    else
                    {
                        Console.WriteLine("ID is NaN");
                    }
                    break;

                case "3":
                    var users = uLogic.DisplayUsers();
                    foreach (var item in users)
                    {
                        Console.WriteLine();
                        Console.WriteLine($"Id = {item.Id}");
                        Console.WriteLine($"Name = {item.Name}");
                        Console.WriteLine($"DateOfBirth = {item.DateOfBirth}");
                        Console.WriteLine($"Age = {item.Age}");
                        Console.WriteLine();
                    }
                    break;

                case "4":
                    Console.WriteLine("Enter award name");
                    string awName = Console.ReadLine();
                    awLogic.CreateAward(awName);
                    break;

                case "5":
                    Console.WriteLine("Enter award ID");
                    var awDelId = Console.ReadLine();
                    if (int.TryParse(awDelId, out int numAwDelId))
                    {
                        awLogic.DeleteAward(numAwDelId);
                    }
                    else
                    {
                        Console.WriteLine("ID is NaN");
                    }
                    awLogic.DeleteAward(numAwDelId);
                    break;

                case "6":
                    var awards = awLogic.DisplayAwards();
                    foreach (var item in awards)
                    {
                        Console.WriteLine(item.Id);
                        Console.WriteLine(item.Name);
                        Console.WriteLine();
                    }
                    break;

                case "7":
                    Console.WriteLine("Enter user ID");
                    string usToAw = Console.ReadLine();
                    Console.WriteLine("Enter award ID");
                    string awToAw = Console.ReadLine();
                    if (int.TryParse(usToAw, out int usToAwNum) && int.TryParse(awToAw, out int awToAwNum))
                    {
                        awLogic.Reward(usToAwNum, awToAwNum);
                    }
                    else
                    {
                        Console.WriteLine("ID is NaN");
                    }
                    break;

                case "8":
                    Console.WriteLine("Enter user ID");
                    string       dispAwId = Console.ReadLine();
                    List <Award> result   = new List <Award>();
                    if (int.TryParse(dispAwId, out int dispAwIdNum))
                    {
                        result = awLogic.DisplayUserAwards(dispAwIdNum);
                    }
                    foreach (var item in result)
                    {
                        Console.WriteLine(item.Name);
                        Console.WriteLine(item.Id);
                    }
                    break;

                default:
                    Console.WriteLine("Enter correct value");
                    break;
                }
            }
        }