92 lines
3.8 KiB
C#
92 lines
3.8 KiB
C#
using Demo.UI;
|
|
using Demo.Data.RemoteData.RemoteDataBase;
|
|
using Demo.Data.Repository;
|
|
using Demo.Domain.UseCase;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Demo.Domain.Models;
|
|
|
|
namespace Demo
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Добавляем сервисы в контейнер
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddScoped<IUserRepository, SQLUserRepositoryImpl>();
|
|
builder.Services.AddScoped<IGroupRepository, SQLGroupRepositoryImpl>();
|
|
builder.Services.AddScoped<IPresenceRepository, SQLPresenceRepository>();
|
|
builder.Services.AddScoped<UserUseCase>();
|
|
builder.Services.AddScoped<GroupUseCase>();
|
|
builder.Services.AddScoped<UseCasePresence>();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Настройка конвейера обработки запросов
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
});
|
|
|
|
// Инициализация данных
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var services = scope.ServiceProvider;
|
|
var dbContext = new RemoteDatabaseContext();
|
|
DataInitializer.Initialize(dbContext);
|
|
}
|
|
|
|
// Запуск консольного меню
|
|
var context = new RemoteDatabaseContext();
|
|
var userRepository = new SQLUserRepositoryImpl(context);
|
|
var groupRepository = new SQLGroupRepositoryImpl(context);
|
|
var presenceRepository = new SQLPresenceRepository(context);
|
|
|
|
var userUseCase = new UserUseCase(userRepository);
|
|
var groupUseCase = new GroupUseCase(groupRepository);
|
|
var presenceUseCase = new UseCasePresence(presenceRepository);
|
|
|
|
var userConsole = new UserConsole(userUseCase);
|
|
var groupConsole = new GroupConsole(groupUseCase);
|
|
var presenceConsole = new PresenceConsole(presenceUseCase, userUseCase); // Передаем userUseCase
|
|
var excelExporter = new ExcelExporter();
|
|
|
|
// Создаем данные для экспорта
|
|
var group = new Group { Name = "Group 1" };
|
|
var users = new List<User> { new User { Id = Guid.NewGuid(), FIO = "User 1" } }; // Используем Guid для Id
|
|
var presence = new List<Presence> { new Presence { UserId = users[0].Id, IsAttendance = true } };
|
|
|
|
// Указываем путь для сохранения файла
|
|
string directoryPath = @"C:\Users\Наиль\Source\Repos\slarny4\Demo1\Excel";
|
|
string filePath = Path.Combine(directoryPath, "GroupInfo.xlsx");
|
|
|
|
// Проверяем, существует ли директория, и если нет, создаем её
|
|
if (!Directory.Exists(directoryPath))
|
|
{
|
|
Directory.CreateDirectory(directoryPath);
|
|
}
|
|
|
|
// Вызываем метод для экспорта данных в Excel
|
|
excelExporter.ExportGroupInfoToExcel(group, users, presence, filePath);
|
|
|
|
var mainMenu = new MainMenu(userConsole, groupConsole, presenceConsole, excelExporter, groupUseCase, userUseCase, presenceUseCase);
|
|
mainMenu.ShowMenu();
|
|
|
|
// Запуск веб-сервера
|
|
app.Run();
|
|
}
|
|
}
|
|
} |