2024-11-11 09:07:11 +00:00
|
|
|
|
using domain.UseCase;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace ui
|
|
|
|
|
{
|
|
|
|
|
public class GroupConsoleUI
|
|
|
|
|
{
|
|
|
|
|
private readonly GroupUseCase _groupUseCase;
|
|
|
|
|
|
|
|
|
|
public GroupConsoleUI(GroupUseCase groupUseCase)
|
|
|
|
|
{
|
|
|
|
|
_groupUseCase = groupUseCase;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FindGroupById(int groupId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var group = _groupUseCase.FindGroupById(groupId);
|
|
|
|
|
Console.WriteLine($"ID группы: {group.Id} Название группы: {group.Name}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 09:00:26 +00:00
|
|
|
|
|
2024-11-11 09:07:11 +00:00
|
|
|
|
public void DisplayAllGroups()
|
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 09:00:26 +00:00
|
|
|
|
|
2024-11-11 09:07:11 +00:00
|
|
|
|
public void AddGroup(string groupName)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-11-13 09:00:26 +00:00
|
|
|
|
ValidateGroupName(groupName);
|
2024-11-11 09:07:11 +00:00
|
|
|
|
_groupUseCase.AddGroup(groupName);
|
|
|
|
|
Console.WriteLine($"\nГруппа {groupName} добавлена.\n");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка: {ex.Message}\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveGroup(string groupIdStr)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int groupId = int.Parse(groupIdStr);
|
2024-11-13 09:00:26 +00:00
|
|
|
|
ValidateGroupId(groupId);
|
2024-11-11 09:07:11 +00:00
|
|
|
|
_groupUseCase.RemoveGroupById(groupId);
|
|
|
|
|
Console.WriteLine($"Группа с ID: {groupId} удалена");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка: {ex.Message}\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-14 11:46:38 +00:00
|
|
|
|
|
2024-11-11 09:07:11 +00:00
|
|
|
|
public void UpdateGroupName(int groupId, string newGroupName)
|
|
|
|
|
{
|
2024-11-14 11:46:38 +00:00
|
|
|
|
var isUpdated = _groupUseCase.UpdateGroup(groupId, newGroupName);
|
|
|
|
|
|
|
|
|
|
if (isUpdated)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"\nНазвание группы с ID {groupId} успешно изменено на {newGroupName}.\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"\nОшибка: Группа с ID {groupId} не существует в базе данных.\n");
|
|
|
|
|
}
|
2024-11-11 09:07:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-14 11:46:38 +00:00
|
|
|
|
private void ValidateGroupId(int groupId)
|
2024-11-11 09:07:11 +00:00
|
|
|
|
{
|
2024-11-14 11:46:38 +00:00
|
|
|
|
if (groupId < 1)
|
2024-11-11 09:07:11 +00:00
|
|
|
|
{
|
2024-11-14 11:46:38 +00:00
|
|
|
|
throw new ArgumentException("Введите корректный ID группы.");
|
2024-11-11 09:07:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-14 11:46:38 +00:00
|
|
|
|
private void ValidateGroupName(string groupName)
|
2024-11-11 09:07:11 +00:00
|
|
|
|
{
|
2024-11-14 11:46:38 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(groupName))
|
2024-11-11 09:07:11 +00:00
|
|
|
|
{
|
2024-11-14 11:46:38 +00:00
|
|
|
|
throw new ArgumentException("Имя группы не может быть пустым.");
|
2024-11-11 09:07:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|