добавлен контролер для работы с базой данных
This commit is contained in:
parent
a4e186c78f
commit
fd1f8e103b
57
WorkTime/WorkTime/Controller.cs
Normal file
57
WorkTime/WorkTime/Controller.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WorkTime.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ConsoleTableExt;
|
||||
|
||||
namespace WorkTime
|
||||
{
|
||||
internal class Controller
|
||||
{
|
||||
private readonly CourseContext _context;
|
||||
|
||||
public Controller(CourseContext scheduleContext)
|
||||
{
|
||||
_context = scheduleContext;
|
||||
}
|
||||
|
||||
public void GetWorkers()
|
||||
{
|
||||
ConsoleTableBuilder.From(_context.Workers.Select(x => new { x.Id, x.Name,x.DateEmployment}).ToList())
|
||||
.WithTitle("Workers")
|
||||
.ExportAndWriteLine();
|
||||
}
|
||||
public void GetProject()
|
||||
{
|
||||
ConsoleTableBuilder.From(_context.Projects.Select(x => new { x.Id, x.Name, x.Ready }).ToList())
|
||||
.WithTitle("Workers")
|
||||
.ExportAndWriteLine();
|
||||
}
|
||||
public void GetSalary()
|
||||
{
|
||||
ConsoleTableBuilder.From(_context.SalaryWithAllowances.Select(x => new { x.Id, x.Name, x.Должность, x.CalcSalary }).ToList())
|
||||
.WithTitle("Workers")
|
||||
.ExportAndWriteLine();
|
||||
}
|
||||
public void GetSalaryOnCurrentMonth()
|
||||
{
|
||||
ConsoleTableBuilder.From(_context.GetSalaryOnCurrentMonths.Select(x => new { x.WorkerId, x.Name, x.Salary, x.Hours}).ToList())
|
||||
.WithTitle("Workers")
|
||||
.ExportAndWriteLine();
|
||||
}
|
||||
public void GetPosts()
|
||||
{
|
||||
ConsoleTableBuilder.From(_context.Posts.Select(x => new { x.Id,x.Name, x.Salary }).ToList())
|
||||
.WithTitle("Workers")
|
||||
.ExportAndWriteLine();
|
||||
}
|
||||
public void AddWorker(Worker worker)
|
||||
{
|
||||
_context.Workers.Add(worker);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
9
WorkTime/WorkTime/HelloText.txt
Normal file
9
WorkTime/WorkTime/HelloText.txt
Normal file
@ -0,0 +1,9 @@
|
||||
Запущена программа.
|
||||
Нажмите 0 для выхода.
|
||||
1 для получения списка всех сотрудников
|
||||
2 для получения списка всех проектов
|
||||
3 для получения зароботной платы сотрудника с надбавками"
|
||||
4 для получения зароботной платы сотрудника за тякущий месяц"
|
||||
5 для получения всех должностей
|
||||
6 Добавить сотрудника
|
||||
7 запустить тестирование всех функций
|
@ -1,16 +1,59 @@
|
||||
namespace WorkTime
|
||||
using WorkTime;
|
||||
using WorkTime.Models;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace WorkTime
|
||||
{
|
||||
class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
using (var context = new CourseContext())
|
||||
string text;
|
||||
using (var sr = new StreamReader("HelloText.txt"))
|
||||
{
|
||||
foreach (var salary in context.SalaryWithAllowances)
|
||||
text = sr.ReadToEnd();
|
||||
}
|
||||
|
||||
using var context = new CourseContext();
|
||||
Controller controller = new(context);
|
||||
string operation = "";
|
||||
do
|
||||
{
|
||||
Console.WriteLine($"{salary.Name} {salary.CalcSalary}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine(text);
|
||||
operation = Console.ReadLine() ?? "";
|
||||
switch (operation)
|
||||
{
|
||||
case "1":
|
||||
controller.GetWorkers();
|
||||
break;
|
||||
case "2":
|
||||
controller.GetProject();
|
||||
break;
|
||||
case "3":
|
||||
controller.GetSalary();
|
||||
break;
|
||||
case "4":
|
||||
controller.GetSalaryOnCurrentMonth();
|
||||
break;
|
||||
case "5":
|
||||
controller.GetPosts();
|
||||
break;
|
||||
case "6":
|
||||
Worker worker = new()
|
||||
{
|
||||
Name = Console.ReadLine(),
|
||||
PostId = int.Parse(Console.ReadLine()),
|
||||
};
|
||||
controller.AddWorker(worker);
|
||||
break;
|
||||
case "7":
|
||||
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Некорректно введенный номер операции");
|
||||
break;
|
||||
}
|
||||
} while (operation != "0");
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ConsoleTableExt" Version="3.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
Loading…
Reference in New Issue
Block a user