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