Demo/UI/GroupConsole.cs

61 lines
1.9 KiB
C#
Raw Normal View History

2024-10-17 12:35:14 +00:00
using Demo.Domain.UseCase;
using Demo.domain.Models;
using System.Text;
namespace Demo.UI
{
public class GroupConsoleUI
{
2024-10-21 10:38:39 +00:00
IGroupUseCase _groupUseCase;
2024-10-17 12:35:14 +00:00
2024-10-21 10:38:39 +00:00
public GroupConsoleUI(IGroupUseCase groupUseCase) {
2024-10-17 12:35:14 +00:00
_groupUseCase = groupUseCase;
}
public void UpdateGroupName(Group group)
{
try
{
Group output = _groupUseCase.UpdateGroupName(group);
StringBuilder groupOutput = new StringBuilder();
groupOutput.AppendLine($"Обновленная группа: {output.Id}\t{output.Name}");
Console.WriteLine(groupOutput);
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при обновлении группы: {ex.Message}");
}
}
2024-10-24 20:41:31 +00:00
public void CreateNewGroup(string Name){
string output = _groupUseCase.CreateGroup(Name) ? "Группа создана" : "Группа не создана";
Console.WriteLine(output);
2024-10-17 12:35:14 +00:00
}
public void DisplayAllGroups()
{
2024-10-24 20:41:31 +00:00
StringBuilder userOutput = new StringBuilder();
2024-10-17 12:35:14 +00:00
foreach (var group in _groupUseCase.GetAllGroups())
{
2024-10-24 20:41:31 +00:00
userOutput.AppendLine($"{group.Id}\t{group.Name}");
2024-10-17 12:35:14 +00:00
}
2024-10-24 20:41:31 +00:00
Console.WriteLine(userOutput);
}
public void RemoveGroupById(int ID){
string output = _groupUseCase.RemoveGroupById(ID) ? "Группа удалена" : "Группа не удалена";
Console.WriteLine(output);
2024-10-17 12:35:14 +00:00
}
2024-10-24 20:41:31 +00:00
public void DisplayGroupByID(int ID){
StringBuilder userOutput = new StringBuilder();
var group = _groupUseCase.GetGroupById(ID);
{
userOutput.AppendLine($"{group.Id}\t{group.Name}");
}
Console.WriteLine(userOutput);
}
}
2024-10-17 12:35:14 +00:00
}