From 3683d8d96e703696b3d894772affe2a352fbf6c6 Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Tue, 14 Mar 2023 22:57:03 +0400 Subject: [PATCH] fix --- WorkTime/WorkTime/Controller.cs | 11 +++++++++-- WorkTime/WorkTime/Program.cs | 9 ++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/WorkTime/WorkTime/Controller.cs b/WorkTime/WorkTime/Controller.cs index 53a52b0..003827b 100644 --- a/WorkTime/WorkTime/Controller.cs +++ b/WorkTime/WorkTime/Controller.cs @@ -44,8 +44,15 @@ namespace WorkTime } public void AddWorker(Worker worker) { - _context.Workers.Add(worker); - _context.SaveChanges(); + try + { + _context.Workers.Add(worker); + _context.SaveChanges(); + } + catch (Exception e) + { + Console.WriteLine(e.InnerException.Message); + } } } } \ No newline at end of file diff --git a/WorkTime/WorkTime/Program.cs b/WorkTime/WorkTime/Program.cs index 08da5e4..aa63c59 100644 --- a/WorkTime/WorkTime/Program.cs +++ b/WorkTime/WorkTime/Program.cs @@ -23,6 +23,8 @@ namespace WorkTime operation = Console.ReadLine() ?? ""; switch (operation) { + case "0": + break; case "1": controller.GetWorkers(); break; @@ -39,6 +41,7 @@ namespace WorkTime controller.GetPosts(); break; case "6": + Console.WriteLine("Введите Имя и id должности(1,2)"); Worker worker = new() { Name = Console.ReadLine(), @@ -47,7 +50,7 @@ namespace WorkTime controller.AddWorker(worker); break; case "7": - + Test(controller, context); break; default: Console.WriteLine("Некорректно введенный номер операции"); @@ -60,11 +63,11 @@ namespace WorkTime Random r = new Random(); string name = ""; for (int i = 0; i < 7; i++) - name += (char)r.Next(3, 255); + name += (char)r.Next(65, 89); Worker worker = new() { Name = name[..7], - PostId = r.Next(1,context.Posts.Last().Id), + PostId = r.Next(1,2), }; var result = new[]