presence123/Demo/UI/UserConsole.cs

69 lines
1.8 KiB
C#
Raw Normal View History

2024-10-30 09:06:35 +00:00
using Demo.domain.Models;
using Demo.Domain.UseCase;
using System;
namespace Demo.UI
{
public class UserConsole
{
private readonly UserUseCase _userUseCase;
public UserConsole(UserUseCase userUseCase)
{
_userUseCase = userUseCase;
}
public void ShowAllUsers()
{
var users = _userUseCase.GetAllUsers();
if (users.Count == 0)
{
Console.WriteLine("No users found.");
return;
}
foreach (var user in users)
{
Console.WriteLine($"User GUID: {user.Guid}, FIO: {user.FIO}, Group ID: {user.Group.Id}");
}
}
public void UpdateUser(Guid userGuid)
{
Console.WriteLine("Enter new FIO:");
string newFIO = Console.ReadLine();
Console.WriteLine("Enter new Group ID:");
int newGroupID = int.Parse(Console.ReadLine());
var user = new User
{
Guid = userGuid,
FIO = newFIO,
Group = new Group { Id = newGroupID }
};
_userUseCase.UpdateUser(user);
Console.WriteLine("User updated successfully.");
}
public void DeleteUser(Guid userGuid)
{
_userUseCase.RemoveUserByGuid(userGuid);
Console.WriteLine("User deleted successfully.");
}
public void FindUser(Guid userGuid)
{
var user = _userUseCase.GetAllUsers().FirstOrDefault(u => u.Guid == userGuid);
if (user != null)
{
Console.WriteLine($"User found: {user.FIO}, Group ID: {user.Group.Id}");
}
else
{
Console.WriteLine("User not found.");
}
}
}
}