presence_new/ui/UserConsole.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2024-11-16 12:02:17 +00:00
using presence.data.LocalData.Entity;
using presence.domain.UseCase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace presence.ui
{
public class UserConsoleUI
{
UserUseCase _userUseCase;
public UserConsoleUI(UserUseCase userUseCase) {
_userUseCase = userUseCase;
}
public void RemoveUserById(int userId) {
string output = _userUseCase.RemoveUserById(userId) ? "Пользователь удален" : "Пользователь не удален";
Console.WriteLine(output);
}
public void DisplayAllUsers()
{
StringBuilder userOutput = new StringBuilder();
foreach (var user in _userUseCase.GetAllUsers())
{
2024-11-16 14:13:06 +00:00
userOutput.AppendLine($"{user.Id}\t{user.FIO}\t{user.Group}");
2024-11-16 12:02:17 +00:00
}
Console.WriteLine(userOutput);
}
public void GetUserById(int userId) {
StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.GetUserById(userId);
2024-11-16 14:13:06 +00:00
userOutput.AppendLine($"{user.Id}\t{user.FIO}\t{user.GroupId}");
2024-11-16 12:02:17 +00:00
Console.WriteLine(userOutput);
}
public void UpdateUserById(int userId, String name, int groupId) {
StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.UpdateUserById(userId, name, groupId) ? "Пользователь обновлен" : "Пользователь не обновлен";
Console.WriteLine(userOutput);
}
}
}