2024-10-28 10:39:15 +00:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-10-17 11:46:19 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using Demo.Domain.Models;
|
|
|
|
|
using Demo.Domain.UseCase;
|
|
|
|
|
|
|
|
|
|
namespace Demo.UI
|
|
|
|
|
{
|
|
|
|
|
public class UserConsoleUI
|
|
|
|
|
{
|
2024-10-21 10:55:18 +00:00
|
|
|
|
IUserUseCase _userUseCase;
|
|
|
|
|
public UserConsoleUI(IUserUseCase userUseCase) {
|
2024-10-17 11:46:19 +00:00
|
|
|
|
_userUseCase = userUseCase;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-24 15:57:52 +00:00
|
|
|
|
public void RemoveUserByGuid(Guid guidUser) {
|
|
|
|
|
|
|
|
|
|
string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален";
|
|
|
|
|
Console.WriteLine(output);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 11:46:19 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-10-21 10:55:18 +00:00
|
|
|
|
IGroupUseCase _groupUseCase;
|
2024-10-28 10:39:15 +00:00
|
|
|
|
IUserUseCase _userUseCase;
|
|
|
|
|
IPresenceUseCase _presenceUseCase;
|
|
|
|
|
public GroupConsoleUI(IGroupUseCase groupUseCase, IUserUseCase userUseCase, IPresenceUseCase presenceUseCase){
|
2024-10-17 11:46:19 +00:00
|
|
|
|
_groupUseCase = groupUseCase;
|
2024-10-28 10:39:15 +00:00
|
|
|
|
_userUseCase = userUseCase;
|
|
|
|
|
_presenceUseCase = presenceUseCase;
|
2024-10-17 11:46:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisplayAllGroups(){
|
|
|
|
|
StringBuilder userOutput = new StringBuilder();
|
|
|
|
|
foreach (var group in _groupUseCase.GetAllGroups())
|
|
|
|
|
{
|
|
|
|
|
userOutput.AppendLine($"{group.ID}\t{group.Name}");
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine(userOutput);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-24 15:57:52 +00:00
|
|
|
|
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) ? "Группа создана" : "Группа не создана";
|
2024-10-22 18:51:54 +00:00
|
|
|
|
Console.WriteLine(output);
|
2024-10-17 11:46:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateGroupName(Group group)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-10-17 12:13:34 +00:00
|
|
|
|
Group output = _groupUseCase.UpdateGroup(group);
|
2024-10-17 11:46:19 +00:00
|
|
|
|
StringBuilder groupOutput = new StringBuilder();
|
|
|
|
|
groupOutput.AppendLine($"Обновленная группа: {output.ID}\t{output.Name}");
|
|
|
|
|
Console.WriteLine(groupOutput);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка при обновлении группы: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-24 15:57:52 +00:00
|
|
|
|
|
|
|
|
|
public void RemoveGroupByID(int ID){
|
|
|
|
|
string output = _groupUseCase.RemoveGroupByID(ID) ? "Группа удалена" : "Группа не удалена";
|
|
|
|
|
Console.WriteLine(output);
|
|
|
|
|
}
|
2024-10-28 10:39:15 +00:00
|
|
|
|
|
|
|
|
|
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}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-17 11:46:19 +00:00
|
|
|
|
}
|
2024-10-22 18:51:54 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2024-10-23 07:53:19 +00:00
|
|
|
|
|
2024-10-23 09:14:11 +00:00
|
|
|
|
public void GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){
|
|
|
|
|
string output = _presenceUseCase.GeneratePresenceWeek(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно";
|
|
|
|
|
Console.WriteLine(output);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 07:53:19 +00:00
|
|
|
|
public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
|
|
|
|
string output = _presenceUseCase.IsAttedance(firstLesson, lastLesson, date, UserGuid) ? "Обновлено" : "Не обновлено";
|
|
|
|
|
Console.WriteLine(output);
|
|
|
|
|
}
|
2024-10-22 18:51:54 +00:00
|
|
|
|
}
|
2024-10-17 11:46:19 +00:00
|
|
|
|
}
|