pr1/presence/ui/UserConsole.cs

75 lines
2.3 KiB
C#
Raw Normal View History

2024-12-23 09:12:26 +00:00
using presence.data.LocalData.Entity;
using presence.domain.UseCase;
2024-12-05 09:30:01 +00:00
using System;
2024-12-23 09:12:26 +00:00
using System.Collections.Generic;
using System.Linq;
2024-12-05 09:30:01 +00:00
using System.Text;
2024-12-23 09:12:26 +00:00
using System.Threading.Tasks;
2024-12-05 09:30:01 +00:00
2024-12-23 09:12:26 +00:00
namespace presence.ui
2024-12-05 09:30:01 +00:00
{
public class UserConsoleUI
{
2024-12-23 09:12:26 +00:00
UserUseCase _userUseCase;
public UserConsoleUI(UserUseCase userUseCase)
2024-12-05 09:30:01 +00:00
{
2024-12-23 09:12:26 +00:00
_userUseCase = userUseCase;
}
2024-12-05 09:30:01 +00:00
2024-12-23 09:12:26 +00:00
public void DisplayAllUsers()
{
StringBuilder userOutput = new StringBuilder();
foreach (var user in _userUseCase.GetAllUsers())
2024-12-05 09:30:01 +00:00
{
2024-12-23 09:12:26 +00:00
userOutput.AppendLine($"{user.Id}\t{user.FIO}\t{user.GroupId}");
2024-12-05 09:30:01 +00:00
}
2024-12-23 09:12:26 +00:00
Console.WriteLine(userOutput);
}
2024-12-05 09:30:01 +00:00
2024-12-23 09:12:26 +00:00
public void RemoveUserById(string userId)
{
2024-12-05 09:30:01 +00:00
2024-12-23 09:12:26 +00:00
int Id;
bool isParsed = int.TryParse(userId, out Id);
if (!isParsed)
2024-12-05 09:30:01 +00:00
{
2024-12-23 09:12:26 +00:00
Console.WriteLine("Введено не число");
2024-12-05 09:30:01 +00:00
}
2024-12-23 09:12:26 +00:00
string output = _userUseCase.RemoveUserById(Id) ? "Пользователь удален" : "Пользователь не удален";
Console.WriteLine(output);
}
2024-12-05 09:30:01 +00:00
2024-12-23 09:12:26 +00:00
public void UpdateUserById(string userId, String name, string groupId)
{
int UserId;
int GroupId;
bool isParsed = int.TryParse(userId, out UserId);
bool isParsedGroup = int.TryParse(groupId, out GroupId);
if (!isParsed && !isParsedGroup)
2024-12-05 09:30:01 +00:00
{
2024-12-23 09:12:26 +00:00
Console.WriteLine("Введено неверное число");
2024-12-05 09:30:01 +00:00
}
2024-12-23 09:12:26 +00:00
string output = _userUseCase.UpdateUserById(UserId, name, GroupId) ? "Пользователь обновлен" : "Пользователь не обновлен";
Console.WriteLine(output);
}
2024-12-05 09:30:01 +00:00
2024-12-23 09:12:26 +00:00
public void GetUserById(string userId)
{
int Id;
bool isParsed = int.TryParse(userId, out Id);
if (!isParsed)
2024-12-05 09:30:01 +00:00
{
2024-12-23 09:12:26 +00:00
Console.WriteLine("Введено не число");
2024-12-05 09:30:01 +00:00
}
2024-12-23 09:12:26 +00:00
StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.GetUserById(Id);
userOutput.AppendLine($"{user.Id}\t{user.FIO}\t{user.GroupId}");
Console.WriteLine(userOutput);
}
2024-12-05 09:30:01 +00:00
2024-12-23 09:12:26 +00:00
}
}
2024-12-05 09:30:01 +00:00