2024-10-18 14:03:25 +00:00
|
|
|
|
using Demo.Domain.UseCase;
|
|
|
|
|
using System;
|
2024-10-18 10:20:54 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Demo.UI
|
|
|
|
|
{
|
2024-11-10 18:56:16 +00:00
|
|
|
|
public class GroupConsoleUI
|
2024-10-18 10:20:54 +00:00
|
|
|
|
{
|
2024-11-10 18:56:16 +00:00
|
|
|
|
private readonly GroupUseCase _groupUseCase;
|
2024-10-18 14:03:25 +00:00
|
|
|
|
|
|
|
|
|
public GroupConsoleUI(GroupUseCase groupUseCase)
|
|
|
|
|
{
|
|
|
|
|
_groupUseCase = groupUseCase;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
public void FindGroupById(int IdGroup)
|
|
|
|
|
{
|
|
|
|
|
_groupUseCase.FindGroupById(IdGroup);
|
|
|
|
|
}
|
2024-10-18 14:03:25 +00:00
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
// Метод для отображения всех групп
|
|
|
|
|
public void DisplayAllGroups()
|
2024-10-18 14:03:25 +00:00
|
|
|
|
{
|
2024-11-10 18:56:16 +00:00
|
|
|
|
Console.WriteLine("\n=== Список всех групп ===");
|
|
|
|
|
StringBuilder groupOutput = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
foreach (var group in _groupUseCase.GetAllGroups())
|
|
|
|
|
{
|
|
|
|
|
groupOutput.AppendLine($"{group.Id}\t{group.Name}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(groupOutput);
|
|
|
|
|
Console.WriteLine("===========================\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для добавления новой группы
|
|
|
|
|
public void AddGroup(string groupName)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_groupUseCase.AddGroup(groupName);
|
|
|
|
|
Console.WriteLine($"\nГруппа {groupName} добавлена.\n");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
2024-10-18 14:03:25 +00:00
|
|
|
|
{
|
2024-11-10 18:56:16 +00:00
|
|
|
|
Console.WriteLine($"Ошибка: {ex.Message}\n");
|
2024-10-18 14:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
public void RemoveGroup(string groupIdStr)
|
2024-10-18 14:03:25 +00:00
|
|
|
|
{
|
2024-11-10 18:56:16 +00:00
|
|
|
|
int groupId = int.Parse(groupIdStr);
|
|
|
|
|
_groupUseCase.RemoveGroupById(groupId);
|
|
|
|
|
Console.WriteLine($"Группа с ID: {groupId} удалена");
|
2024-10-18 14:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
// Метод для обновления названия группы
|
|
|
|
|
public void UpdateGroupName(int groupId, string newGroupName)
|
2024-10-18 14:03:25 +00:00
|
|
|
|
{
|
2024-11-10 18:56:16 +00:00
|
|
|
|
_groupUseCase.UpdateGroup(groupId, newGroupName);
|
|
|
|
|
Console.WriteLine($"\nНазвание группы с ID {groupId} изменено на {newGroupName}.\n");
|
2024-10-18 14:03:25 +00:00
|
|
|
|
}
|
2024-10-18 10:20:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|