This commit is contained in:
m1aksim1 2023-03-14 22:57:03 +04:00
parent 14fbb042b5
commit 3683d8d96e
2 changed files with 15 additions and 5 deletions

View File

@ -43,9 +43,16 @@ namespace WorkTime
.ExportAndWriteLine(); .ExportAndWriteLine();
} }
public void AddWorker(Worker worker) public void AddWorker(Worker worker)
{
try
{ {
_context.Workers.Add(worker); _context.Workers.Add(worker);
_context.SaveChanges(); _context.SaveChanges();
} }
catch (Exception e)
{
Console.WriteLine(e.InnerException.Message);
}
}
} }
} }

View File

@ -23,6 +23,8 @@ namespace WorkTime
operation = Console.ReadLine() ?? ""; operation = Console.ReadLine() ?? "";
switch (operation) switch (operation)
{ {
case "0":
break;
case "1": case "1":
controller.GetWorkers(); controller.GetWorkers();
break; break;
@ -39,6 +41,7 @@ namespace WorkTime
controller.GetPosts(); controller.GetPosts();
break; break;
case "6": case "6":
Console.WriteLine("Введите Имя и id должности(1,2)");
Worker worker = new() Worker worker = new()
{ {
Name = Console.ReadLine(), Name = Console.ReadLine(),
@ -47,7 +50,7 @@ namespace WorkTime
controller.AddWorker(worker); controller.AddWorker(worker);
break; break;
case "7": case "7":
Test(controller, context);
break; break;
default: default:
Console.WriteLine("Некорректно введенный номер операции"); Console.WriteLine("Некорректно введенный номер операции");
@ -60,11 +63,11 @@ namespace WorkTime
Random r = new Random(); Random r = new Random();
string name = ""; string name = "";
for (int i = 0; i < 7; i++) for (int i = 0; i < 7; i++)
name += (char)r.Next(3, 255); name += (char)r.Next(65, 89);
Worker worker = new() Worker worker = new()
{ {
Name = name[..7], Name = name[..7],
PostId = r.Next(1,context.Posts.Last().Id), PostId = r.Next(1,2),
}; };
var result = new[] var result = new[]