FinalPresenceLexa/UI/GroupConsoleUI.cs
2025-04-28 11:51:01 +03:00

110 lines
3.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using domain.UseCase;
using System.Text;
namespace ui
{
public class GroupConsoleUI
{
private readonly GroupUseCase _groupUseCase;
public GroupConsoleUI(GroupUseCase groupUseCase)
{
_groupUseCase = groupUseCase;
}
public void ShowGroupDetails(int groupId)
{
try
{
var group = _groupUseCase.GetGroupById(groupId);
if (group == null)
{
Console.WriteLine($"Группа с ID {groupId} не найдена.");
return;
}
Console.WriteLine("\n=== Информация о группе ===");
Console.WriteLine($"ID: {group.Id}");
Console.WriteLine($"Название: {group.Id}");
Console.WriteLine($"Количество студентов: {group.Users?.Count ?? 0}");
Console.WriteLine("===========================");
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при получении информации о группе: {ex.Message}");
}
}
public void ShowAllGroups()
{
try
{
Console.WriteLine("\n=== Список всех групп ===");
var groups = _groupUseCase.GetAllGroups();
if (groups == null || !groups.Any())
{
Console.WriteLine("Нет доступных групп.");
return;
}
var output = new StringBuilder();
foreach (var group in groups)
{
output.AppendLine($"{group.Id,-5} | {group.Name,-30} | Студентов: {group.Users?.Count ?? 0}");
}
Console.WriteLine(output);
Console.WriteLine(new string('=', 50));
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при получении списка групп: {ex.Message}");
}
}
public void CreateNewGroup(string groupName)
{
try
{
if (string.IsNullOrWhiteSpace(groupName))
{
Console.WriteLine("Название группы не может быть пустым.");
return;
}
var result = _groupUseCase.CreateGroupAsync(groupName);
Console.WriteLine($"\nГруппа '{result.Id}' успешно создана (ID: {result.Id}).\n");
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при создании группы: {ex.Message}");
}
}
public void RenameGroup(int groupId, string newName)
{
try
{
if (string.IsNullOrWhiteSpace(newName))
{
Console.WriteLine("Новое название группы не может быть пустым.");
return;
}
var updatedGroup = _groupUseCase.UpdateGroupAsync(groupId, newName);
if (updatedGroup == null)
{
Console.WriteLine($"Группа с ID {groupId} не найдена.");
return;
}
Console.WriteLine($"\nГруппа успешно переименована в '{updatedGroup.Name}'.\n");
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при переименовании группы: {ex.Message}");
}
}
}
}