Demo/UI/UserConsole.cs

50 lines
1.6 KiB
C#
Raw Normal View History

using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Domain.UseCase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Posechaemost.UI
{
public class UserConsoleUI
{
UserUseCase _userUseCase;
public UserConsoleUI(UserUseCase userUseCase) {
_userUseCase = userUseCase;
}
2024-11-06 04:10:09 +00:00
public void RemoveUserById(int userId) {
2024-11-06 04:10:09 +00:00
string output = _userUseCase.RemoveUserById(userId) ? "Пользователь удален" : "Пользователь не удален";
Console.WriteLine(output);
}
2024-10-18 06:47:43 +00:00
public void DisplayAllUsers()
{
StringBuilder userOutput = new StringBuilder();
foreach (var user in _userUseCase.GetAllUsers())
{
2024-11-06 04:10:09 +00:00
userOutput.AppendLine($"{user.UserId}\t{user.FIO}\t{user.GroupId}");
}
Console.WriteLine(userOutput);
}
2024-10-18 06:47:43 +00:00
2024-11-06 04:10:09 +00:00
public void GetUserById(int userId) {
2024-10-18 06:47:43 +00:00
StringBuilder userOutput = new StringBuilder();
2024-11-06 04:10:09 +00:00
var user = _userUseCase.GetUserById(userId);
userOutput.AppendLine($"{user.UserId}\t{user.FIO}\t{user.GroupId}");
2024-10-18 06:47:43 +00:00
Console.WriteLine(userOutput);
2024-11-06 04:10:09 +00:00
}
2024-11-06 04:10:09 +00:00
public void UpdateUserById(int userId, String name, int groupId) {
StringBuilder userOutput = new StringBuilder();
2024-11-06 04:10:09 +00:00
var user = _userUseCase.UpdateUserById(userId, name, groupId) ? "Пользователь обновлен" : "Пользователь не обновлен";
Console.WriteLine(userOutput);
2024-10-18 06:47:43 +00:00
}
}
}
2024-10-18 06:47:43 +00:00