71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
using presence.Data.LocalData.Entity;
|
|
using presence.Domain.Models;
|
|
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.RemoveUserByGuid(userId) ? "Пользователь удален" : "Пользователь не удален";
|
|
Console.WriteLine(output);
|
|
}
|
|
|
|
public void DisplayAllUsers()
|
|
{
|
|
StringBuilder userOutput = new StringBuilder();
|
|
foreach (var user in _userUseCase.GetAllUsers())
|
|
{
|
|
userOutput.AppendLine($"{user.UserID}\t{user.UserFIO}\t{user.UserGroup.Name}");
|
|
}
|
|
Console.WriteLine(userOutput);
|
|
}
|
|
|
|
public void FindUserById(int userId)
|
|
{
|
|
StringBuilder userOutput = new StringBuilder();
|
|
var user = _userUseCase.FindUserByGuid(userId);
|
|
userOutput.AppendLine($"{user.UserID}\t{user.UserFIO}\t{user.UserGroup}");
|
|
Console.WriteLine(userOutput);
|
|
}
|
|
|
|
public void UpdateUserById(int userId, String name, String groupId)
|
|
{
|
|
try
|
|
{
|
|
var group = _userUseCase.GetAllGroups().FirstOrDefault(g => g.ID == int.Parse(groupId));
|
|
if (group == null)
|
|
{
|
|
Console.WriteLine("Группа не найдена");
|
|
return;
|
|
}
|
|
|
|
var updatedUser = _userUseCase.UpdateUser(new User
|
|
{
|
|
UserID = userId,
|
|
UserFIO = name,
|
|
UserGroup = group
|
|
});
|
|
|
|
Console.WriteLine($"Пользователь обновлен: {updatedUser.UserID}\t{updatedUser.UserFIO}\t{updatedUser.UserGroup.Name}");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Ошибка при обновлении пользователя: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|