presence/ui/GroupConsole.cs
2024-11-29 10:41:36 +03:00

88 lines
4.1 KiB
C#
Raw Permalink 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.ComponentModel.DataAnnotations;
using System.Text;
using Demo.Domain.Models;
using Demo.Domain.UseCase;
namespace Demo.UI
{
public class GroupConsoleUI
{
IGroupUseCase _groupUseCase;
IUserUseCase _userUseCase;
IPresenceUseCase _presenceUseCase;
public GroupConsoleUI(IGroupUseCase groupUseCase, IUserUseCase userUseCase, IPresenceUseCase presenceUseCase){
_groupUseCase = groupUseCase;
_userUseCase = userUseCase;
_presenceUseCase = presenceUseCase;
}
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 DisplayGroupByID(int ID){
StringBuilder userOutput = new StringBuilder();
var group = _groupUseCase.GetGroupById(ID);
{
userOutput.AppendLine($"{group.ID}\t{group.Name}");
}
Console.WriteLine(userOutput);
}
public void CreateNewGroup(string Name){
string output = _groupUseCase.CreateGroup(Name) ? "Группа создана" : "Группа не создана";
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 void RemoveGroupByID(int ID){
string output = _groupUseCase.RemoveGroupByID(ID) ? "Группа удалена" : "Группа не удалена";
Console.WriteLine(output);
}
public void DisplayAllBoutGroup(int groupID){
var users = _userUseCase.GetUsersByGroupID(groupID);
Console.WriteLine($"Группа: {groupID}\tКоличество учеников: {users.Count}");
var presencesByGroup = _presenceUseCase.GetPresenceByGroup(groupID);
var presenceFalseByGroup = _presenceUseCase.GetFalsePresenceByGroup(groupID);
var precentePresenceGroup = 100 - Math.Round((double)presenceFalseByGroup.Count / presencesByGroup.Count * 100);
Console.WriteLine($"Количество занятий: {presencesByGroup.Count}\tОбщий процент посещаемости: {precentePresenceGroup}");
foreach(var user in _userUseCase.GetUsersByGroupID(groupID)){
var countPresences = _presenceUseCase.GetPresenceByUser(user.Guid);
var countFalsePresences = _presenceUseCase.GetFalsePresenceByUser(user.Guid);
var precentePresenceUser = 100 - Math.Round((double)countFalsePresences.Count / countPresences.Count * 100);
if (precentePresenceUser < 40)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"FIO: {user.FIO}\tКоличество посещённых занятий: {countPresences.Count - countFalsePresences.Count}\tКоличество пропущенных занятий: {countFalsePresences.Count}\tПроцент посещаемости: {precentePresenceUser}");
Console.ResetColor();
}
else
{
Console.WriteLine($"FIO: {user.FIO}\tКоличество посещённых занятий: {countPresences.Count - countFalsePresences.Count}\tКоличество пропущенных занятий: {countFalsePresences.Count}\tПроцент посещаемости: {precentePresenceUser}");
}
}
}
}
}