Demo/UI/UserConsole.cs
2024-10-22 21:51:54 +03:00

117 lines
4.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text;
using Demo.Domain.Models;
using Demo.Domain.UseCase;
namespace Demo.UI
{
public class UserConsoleUI
{
IUserUseCase _userUseCase;
public UserConsoleUI(IUserUseCase userUseCase) {
_userUseCase = userUseCase;
}
public void RemoveUserByGuid(Guid guidUser) {
string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален";
Console.WriteLine(output);
}
public void DisplayAllUsers()
{
StringBuilder userOutput = new StringBuilder();
foreach (var user in _userUseCase.GetAllUsers())
{
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.Group.Name}");
}
Console.WriteLine(userOutput);
}
public void UpdateUserByGuid(User user)
{
try
{
User output = _userUseCase.UpdateUser(user);
StringBuilder userOutput = new StringBuilder();
userOutput.AppendLine($"Обновленный пользователь: {output.Guid}\t{output.FIO}\t{output.Group.Name}");
Console.WriteLine(userOutput);
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при обновлении пользователя: {ex.Message}");
}
}
public void DisplayUserByGuid(Guid guid){
User output = _userUseCase.GetUserByGuid(guid);
StringBuilder userOutput = new StringBuilder();
userOutput.AppendLine($"{output.Guid}\t{output.FIO}\t{output.Group.Name}");
Console.WriteLine(userOutput);
}
}
public class GroupConsoleUI
{
IGroupUseCase _groupUseCase;
public GroupConsoleUI(IGroupUseCase groupUseCase){
_groupUseCase = groupUseCase;
}
public void DisplayAllGroups(){
StringBuilder userOutput = new StringBuilder();
foreach (var group in _groupUseCase.GetAllGroups())
{
userOutput.AppendLine($"{group.ID}\t{group.Name}");
}
Console.WriteLine(userOutput);
}
public void CreateNewGroup(Group group){
string output = _groupUseCase.CreateGroup(group) ? "Группа создана" : "Группа не создана";
Console.WriteLine(output);
}
public void UpdateGroupName(Group group)
{
try
{
Group output = _groupUseCase.UpdateGroup(group);
StringBuilder groupOutput = new StringBuilder();
groupOutput.AppendLine($"Обновленная группа: {output.ID}\t{output.Name}");
Console.WriteLine(groupOutput);
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при обновлении группы: {ex.Message}");
}
}
}
public class PresenceConsoleUI{
IPresenceUseCase _presenceUseCase;
public PresenceConsoleUI (IPresenceUseCase presenceUseCase){
_presenceUseCase = presenceUseCase;
}
public void DisplayPresenceByGroup(int groupID){
StringBuilder stringBuilder = new StringBuilder();
foreach(Presence presence in _presenceUseCase.GetPresenceByGroup(groupID)){
stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}");
}
Console.WriteLine(stringBuilder);
}
public void DisplayPresenceByGroupByTime(int groupID, DateOnly date){
StringBuilder stringBuilder = new StringBuilder();
foreach(Presence presence in _presenceUseCase.GetPresenceByGroupByTime(groupID, date)){
stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}");
}
Console.WriteLine(stringBuilder);
}
public void GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date){
string output = _presenceUseCase.GeneratePresence(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно";
Console.WriteLine(output);
}
}
}