Demo/UI/UserConsole.cs

56 lines
1.8 KiB
C#
Raw Normal View History

using Demo.Domain.UseCase;
2024-10-17 12:35:14 +00:00
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.UI
{
public class UserConsoleUI
{
2024-10-21 10:38:39 +00:00
IUserUseCase _userUseCase;
public UserConsoleUI(IUserUseCase userUseCase) {
_userUseCase = userUseCase;
}
public void RemoveUserByGuid(Guid guidUser) {
string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален";
Console.WriteLine(output);
}
public void DisplayAllUsers()
{
StringBuilder userOutput = new StringBuilder();
foreach (var user in _userUseCase.GetAllUsers())
{
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.Group.Name}");
}
Console.WriteLine(userOutput);
}
2024-10-17 12:35:14 +00:00
public void UpdateUser(User user)
{
try
{
User output = _userUseCase.UpdateUser(user);
StringBuilder userOutput = new StringBuilder();
userOutput.AppendLine($"Обновленный пользователь: {output.Guid}\t{output.FIO}\t{output.Group.Name}");
Console.WriteLine(userOutput);
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при обновлении пользователя: {ex.Message}");
}
}
public void GetUserByGuid(Guid guid){
User output = _userUseCase.GetUserByGuid(guid);
StringBuilder userOutput = new StringBuilder();
userOutput.AppendLine($"{output.Guid}\t{output.FIO}\t{output.Group.Name}");
Console.WriteLine(userOutput);
}
}
}