From 5b14b04f010392e392565a6fba3f0950083441b4 Mon Sep 17 00:00:00 2001 From: Class_Student Date: Fri, 15 Nov 2024 12:36:07 +0300 Subject: [PATCH] hi --- 123/Data/LocalData/Entity/Presence.cs | 2 +- 123/Data/LocalData/Entity/User.cs | 10 +- 123/Data/LocalData/LocalStaticData.cs | 13 +- .../RemoteData/RemoteDatabase/DAO/Group.cs | 15 +++ .../RemoteData/RemoteDatabase/DAO/Presence.cs | 19 +++ .../RemoteData/RemoteDatabase/DAO/User.cs | 18 +++ .../RemoteDatabase/RemoteDatabaseContext.cs | 36 ++++++ 123/Data/ReportsHistory/GroupRepositoty.cs | 33 ----- 123/Data/ReportsHistory/UserRepositoty.cs | 68 ---------- 123/Data/Repository/GroupRepositoty.cs | 65 ++++++++++ 123/Data/Repository/IGroupRepository.cs | 19 +++ 123/Data/Repository/IPresenceRepository.cs | 20 +++ 123/Data/Repository/IUserRepository.cs | 20 +++ 123/Data/Repository/PresenceRepository.cs | 54 ++++++++ 123/Data/Repository/SQLGroupRepository.cs | 121 ++++++++++++++++++ 123/Data/Repository/SQLPresenceRepository.cs | 57 +++++++++ 123/Data/Repository/SQLUserRepository.cs | 93 ++++++++++++++ 123/Data/Repository/UserRepositoty.cs | 73 +++++++++++ 123/Demo.csproj | 8 +- 123/Domain/Models/User.cs | 2 +- 123/Domain/UseCase/GroupUseCase.cs | 32 +++-- 123/Domain/UseCase/PresenceUseCase.cs | 107 ++++++++++++++++ 123/Domain/UseCase/UseCaseGeneratePresence.cs | 67 ++++++++++ 123/Domain/UseCase/UserUseCase.cs | 62 +++++---- 123/Program.cs | 24 +++- 123/UI/GroupConsole.cs | 13 +- 123/UI/MainMenu.cs | 20 ++- 123/UI/PresenceConsole.cs | 100 +++++++++++++++ 123/UI/UserConsole.cs | 43 +++++-- Загрузки - Ярлык.lnk | Bin 0 -> 778 bytes 30 files changed, 1027 insertions(+), 187 deletions(-) create mode 100644 123/Data/RemoteData/RemoteDatabase/DAO/Group.cs create mode 100644 123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs create mode 100644 123/Data/RemoteData/RemoteDatabase/DAO/User.cs create mode 100644 123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs delete mode 100644 123/Data/ReportsHistory/GroupRepositoty.cs delete mode 100644 123/Data/ReportsHistory/UserRepositoty.cs create mode 100644 123/Data/Repository/GroupRepositoty.cs create mode 100644 123/Data/Repository/IGroupRepository.cs create mode 100644 123/Data/Repository/IPresenceRepository.cs create mode 100644 123/Data/Repository/IUserRepository.cs create mode 100644 123/Data/Repository/PresenceRepository.cs create mode 100644 123/Data/Repository/SQLGroupRepository.cs create mode 100644 123/Data/Repository/SQLPresenceRepository.cs create mode 100644 123/Data/Repository/SQLUserRepository.cs create mode 100644 123/Data/Repository/UserRepositoty.cs create mode 100644 123/Domain/UseCase/PresenceUseCase.cs create mode 100644 123/Domain/UseCase/UseCaseGeneratePresence.cs create mode 100644 123/UI/PresenceConsole.cs create mode 100644 Загрузки - Ярлык.lnk diff --git a/123/Data/LocalData/Entity/Presence.cs b/123/Data/LocalData/Entity/Presence.cs index dde230d..86922a3 100644 --- a/123/Data/LocalData/Entity/Presence.cs +++ b/123/Data/LocalData/Entity/Presence.cs @@ -8,7 +8,7 @@ namespace _123.Data.LocalData.Entity { public class PresenceLocalEntity { - public required Guid UserGuid { get; set; } + public required int UserID { get; set; } public bool IsAttedance { get; set; } = true; public required DateOnly Date { get; set; } diff --git a/123/Data/LocalData/Entity/User.cs b/123/Data/LocalData/Entity/User.cs index f6284e7..ba6d84f 100644 --- a/123/Data/LocalData/Entity/User.cs +++ b/123/Data/LocalData/Entity/User.cs @@ -6,16 +6,12 @@ using System.Threading.Tasks; namespace _123.Data.LocalData.Entity { - public class UserLocalEntity : IEquatable + public class UserLocalEntity { public required string UserFIO { get; set; } - public Guid UserGuid { get; set; } + public int UserId { get; set; } public required int GroupID { get; set; } - public bool Equals(UserLocalEntity? other) - { - if (other == null) return false; - return this.UserGuid.Equals(other.UserGuid); - } + } } diff --git a/123/Data/LocalData/LocalStaticData.cs b/123/Data/LocalData/LocalStaticData.cs index 2973c24..b312e30 100644 --- a/123/Data/LocalData/LocalStaticData.cs +++ b/123/Data/LocalData/LocalStaticData.cs @@ -1,4 +1,5 @@ using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; using System; using System.Collections.Generic; using System.Linq; @@ -17,12 +18,12 @@ namespace _123.Data.LocalData }; public static List users => new List { - new UserLocalEntity{UserGuid=Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), UserFIO = "RandomFio", GroupID = 1 }, - new UserLocalEntity{UserGuid=Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), UserFIO = "RandomFio1", GroupID = 2 }, - new UserLocalEntity{UserGuid=Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), UserFIO = "RandomFio2", GroupID = 3 }, - new UserLocalEntity{UserGuid=Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), UserFIO = "RandomFio3", GroupID = 1 }, - new UserLocalEntity{UserGuid=Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), UserFIO = "RandomFio4", GroupID = 2 }, - new UserLocalEntity{UserGuid=Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), UserFIO = "RandomFio5", GroupID = 3 }, + new UserLocalEntity{UserId = 1, UserFIO = "RandomFio", GroupID = 1 }, + new UserLocalEntity{UserId = 2, UserFIO = "RandomFio1", GroupID = 2 }, + new UserLocalEntity{UserId = 3, UserFIO = "RandomFio2", GroupID = 3 }, + new UserLocalEntity{UserId = 4, UserFIO = "RandomFio3", GroupID = 1 }, + new UserLocalEntity{UserId = 5, UserFIO = "RandomFio4", GroupID = 2 }, + new UserLocalEntity{UserId = 6, UserFIO = "RandomFio5", GroupID = 3 }, }; public static List presences => new List { diff --git a/123/Data/RemoteData/RemoteDatabase/DAO/Group.cs b/123/Data/RemoteData/RemoteDatabase/DAO/Group.cs new file mode 100644 index 0000000..ac7fe3e --- /dev/null +++ b/123/Data/RemoteData/RemoteDatabase/DAO/Group.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.RemoteData.RemoteDatabase.DAO +{ + public class GroupDao + { + public int ID { get; set; } + public required string Name { get; set; } + public IEnumerable Users { get; set; } + } +} diff --git a/123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs b/123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs new file mode 100644 index 0000000..49894ba --- /dev/null +++ b/123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.RemoteData.RemoteDatabase.DAO +{ + public class PresenceDao + { + public bool IsAttedance { get; set; } = true; + public required DateOnly Date { get; set; } + + public required int LessonNumber { get; set; } + public UserDao UserDao { get; set; } + public int UserID { get; set; } + public int GroupId { get; set; } + } +} diff --git a/123/Data/RemoteData/RemoteDatabase/DAO/User.cs b/123/Data/RemoteData/RemoteDatabase/DAO/User.cs new file mode 100644 index 0000000..205bed4 --- /dev/null +++ b/123/Data/RemoteData/RemoteDatabase/DAO/User.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.RemoteData.RemoteDatabase.DAO +{ + public class UserDao + { + public required string UserFIO { get; set; } + public int UserID { get; set; } + + public required int GroupID { get; set; } + + public GroupDao Group { get; set; } + } +} diff --git a/123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs b/123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs new file mode 100644 index 0000000..deca170 --- /dev/null +++ b/123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs @@ -0,0 +1,36 @@ +using _123.Data.RemoteData.RemoteDatabase.DAO; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.RemoteData.RemoteDatabase +{ + public class RemoteDatabaseContext: DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseNpgsql("Host = 45.67.56.214; Port = 5421; Username = user3; Database = user3; Password = VOTfZ8PQ"); + } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasKey(group => group.ID); + modelBuilder.Entity().Property(group => group.ID).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(user => user.UserID); + modelBuilder.Entity().Property(user => user.UserID).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(presence => new + { + presence.UserID, + presence.Date, + presence.IsAttedance, + presence.LessonNumber + }); + } + public DbSet Groups { get; set; } + public DbSet Users { get; set; } + public DbSet PresencesDaos { get; set; } + } + } + diff --git a/123/Data/ReportsHistory/GroupRepositoty.cs b/123/Data/ReportsHistory/GroupRepositoty.cs deleted file mode 100644 index 8d8d97a..0000000 --- a/123/Data/ReportsHistory/GroupRepositoty.cs +++ /dev/null @@ -1,33 +0,0 @@ -using _123.Data.LocalData.Entity; -using _123.Data.LocalData; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace _123.Data.ReportsHistory -{ - - public class GroupRepositoryImpl - { - public List GetAllGroups() => LocalStaticData.groups; - - public GroupLocalEntity? UpdateGroup(String name) - { - GroupLocalEntity? groupLocal = GetAllGroups() - .Where(x => x.Name == name).FirstOrDefault(); - if (groupLocal == null) return null; - groupLocal.Name = name; - return groupLocal; - } - public GroupLocalEntity AddGroup(String name, String id) - { - GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault(); - groupLocal.Name = name; - groupLocal.ID = int.Parse(id); - return groupLocal; - - } - } - } diff --git a/123/Data/ReportsHistory/UserRepositoty.cs b/123/Data/ReportsHistory/UserRepositoty.cs deleted file mode 100644 index 5d8f5e2..0000000 --- a/123/Data/ReportsHistory/UserRepositoty.cs +++ /dev/null @@ -1,68 +0,0 @@ -using _123.Data.LocalData; -using _123.Data.LocalData.Entity; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace _123.Data.ReportsHistory -{ - public class UserRepositoryImpl - { - public UserRepositoryImpl() - { - - GetAllUsers = LocalStaticData.users; - } - public List GetAllUsers - { get; set; } - - public bool RemoveUserByGuid(Guid userGuid) - { - UserLocalEntity? userLocal = GetAllUsers - .Where(x => x.UserGuid == userGuid).FirstOrDefault(); - if (userLocal == null) return false; - - return GetAllUsers.Remove(userLocal); - } - public UserLocalEntity FindUserByGuid(Guid userGuid) - { - UserLocalEntity? userLocal = GetAllUsers - .Where(x => x.UserGuid == userGuid).FirstOrDefault(); - if (userLocal == null) throw new Exception("Пользователь не найден"); - return userLocal; - } - - - public UserLocalEntity? GetUserByGuid(Guid userGuid) - { - UserLocalEntity? userLocal = GetAllUsers - .Where(x => x.UserGuid == userGuid).FirstOrDefault(); - if (userLocal == null) return null; - - return userLocal; - } - - public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity) - { - UserLocalEntity? userLocal = GetAllUsers - .Where(x => x.UserGuid == userUpdateLocalEnity.UserGuid).FirstOrDefault(); - if (userLocal == null) return null; - userLocal.UserFIO = userUpdateLocalEnity.UserFIO; - userLocal.GroupID = userUpdateLocalEnity.GroupID; - return userLocal; - - } - public UserLocalEntity? UpdateUserByGuid(Guid userGuid) - { - UserLocalEntity? userLocal = GetAllUsers - .Where(x => x.UserGuid == userGuid).FirstOrDefault(); - if (userLocal == null) return null; - return userLocal; - - } - - } -} diff --git a/123/Data/Repository/GroupRepositoty.cs b/123/Data/Repository/GroupRepositoty.cs new file mode 100644 index 0000000..9e9cc0f --- /dev/null +++ b/123/Data/Repository/GroupRepositoty.cs @@ -0,0 +1,65 @@ +using _123.Data.LocalData.Entity; +using _123.Data.LocalData; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using _123.Data.RemoteData.RemoteDatabase.DAO; + +namespace _123.Data.Repository +{ + + public class GroupRepositoryImpl: IGroupRepository + { + public List GetAllGroups() => LocalStaticData.groups; + public bool AddGroup(String name,String Id) + { + GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault(); + groupLocal.Name = name; + groupLocal.ID = int.Parse(Id); + return true; + } + + public List GetAllGroup() + { + return GetAllGroup(); + } + + public GroupLocalEntity GetGroupById(int groupID) + { + GroupLocalEntity? groupLocal = GetAllGroups() + .Where(x => x.ID == groupID).FirstOrDefault(); + if (groupLocal == null) return null; + return groupLocal; + } + + public bool RemoveGroupById(int groupID) + { + GroupLocalEntity? userLocal = GetAllGroups() + .Where(x => x.ID == groupID).FirstOrDefault(); + if (userLocal == null) return false; + return GetAllGroups().Remove(userLocal); + } + + public bool UpdateGroupById(int groupID, String name) + { + GroupLocalEntity? groupLocal = GetAllGroups() + .Where(x => x.ID == groupID).FirstOrDefault(); + if (groupLocal == null) return false; + groupLocal.Name = name; + return true; + } + + List IGroupRepository.GetAllGroup() + { + throw new NotImplementedException(); + } + + GroupDao IGroupRepository.GetGroupById(int groupID) + { + throw new NotImplementedException(); + } + } + } + diff --git a/123/Data/Repository/IGroupRepository.cs b/123/Data/Repository/IGroupRepository.cs new file mode 100644 index 0000000..9fe2039 --- /dev/null +++ b/123/Data/Repository/IGroupRepository.cs @@ -0,0 +1,19 @@ +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.Repository +{ + public interface IGroupRepository + { + List GetAllGroup(); + bool RemoveGroupById(int groupID); + bool UpdateGroupById(int groupID, String name); + GroupDao GetGroupById(int groupID); + bool AddGroup(String name, String id); + } +} diff --git a/123/Data/Repository/IPresenceRepository.cs b/123/Data/Repository/IPresenceRepository.cs new file mode 100644 index 0000000..1b5eea8 --- /dev/null +++ b/123/Data/Repository/IPresenceRepository.cs @@ -0,0 +1,20 @@ +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using _123.Domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.Repository +{ + public interface IPresenceRepository + { + List GetPresenceByGroup(int groupId); + List GetPresenceByGroupAndDate(int groupId, DateOnly date); + bool UnCheckAttendence (int firstClass, int lastClass, DateOnly date, int UserId); + void AddPresence (PresenceDao presence); + + } +} diff --git a/123/Data/Repository/IUserRepository.cs b/123/Data/Repository/IUserRepository.cs new file mode 100644 index 0000000..5e5011f --- /dev/null +++ b/123/Data/Repository/IUserRepository.cs @@ -0,0 +1,20 @@ +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.Repository +{ + public interface IUserRepository + { + List GetAllUser(); + bool RemoveUserById(int userId); + UserDao FindUserById(int userId); + UserDao? GetUserById(int userId); + UserDao? UpdateUser(UserDao userUpdate); + UserDao? UpdateUserById(int userId); + } +} diff --git a/123/Data/Repository/PresenceRepository.cs b/123/Data/Repository/PresenceRepository.cs new file mode 100644 index 0000000..6c73c37 --- /dev/null +++ b/123/Data/Repository/PresenceRepository.cs @@ -0,0 +1,54 @@ +using _123.Data.LocalData; +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using _123.Domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _123.Data.Repository +{ + public class PresenceRepositoryImpl : IPresenceRepository + + { + public List GetAllPresences + { get; set; } + + public void AddPresence(PresenceDao presence) + { + PresenceDao? presenceLocal = GetAllPresences.FirstOrDefault(); + presenceLocal.UserID = presence.UserID; + presenceLocal.Date = presence.Date; + presenceLocal.IsAttedance = presence.IsAttedance; + presenceLocal.LessonNumber = presence.LessonNumber; + + } + + public List GetPresenceByGroup(int groupId) + { + return GetAllPresences; + } + + public List GetPresenceByGroupAndDate(int groupId, DateOnly date) + { + return GetAllPresences; + } + + public bool UnCheckAttendence(int firstClass, int lastClass, DateOnly date, int userId) + { + var presToUpdate = GetAllPresences + .Where(x => x.UserID == userId && x.LessonNumber >= firstClass + && x.LessonNumber <= lastClass && x.Date == date).ToList(); + foreach (var presence in presToUpdate) + { + presence.IsAttedance = false; + } + return true; + } + + } +} diff --git a/123/Data/Repository/SQLGroupRepository.cs b/123/Data/Repository/SQLGroupRepository.cs new file mode 100644 index 0000000..055a88d --- /dev/null +++ b/123/Data/Repository/SQLGroupRepository.cs @@ -0,0 +1,121 @@ +using _123.Data.LocalData; +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _123.Data.Repository +{ + public class SQLGroupRepositoryImpl : IGroupRepository + { + private readonly RemoteDatabaseContext _remoteDatabaseContext; + + public SQLGroupRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) + { + _remoteDatabaseContext = remoteDatabaseContext; + } + + public List GetAllGroups() + { + var groups = _remoteDatabaseContext.Groups + .Select(g => new GroupDao + { + ID = g.ID, + Name = g.Name + }) + .ToList(); + return groups; + } + + public bool AddGroup(string name, string id) + { + try + { + var groupDao = new GroupDao + { + ID = int.Parse(id), + Name = name, + Users = new List() + }; + _remoteDatabaseContext.Groups.Add(groupDao); + _remoteDatabaseContext.SaveChanges(); + return true; + } + catch + { + return false; + } + } + + public List GetAllGroup() + { + return GetAllGroups(); + } + + public GroupDao GetGroupById(int groupID) + { + var group = _remoteDatabaseContext.Groups + .FirstOrDefault(x => x.ID == groupID); + + if (group == null) return null; + + return new GroupDao + { + ID = group.ID, + Name = group.Name, + Users = group.Users?.Select(u => new UserDao + { + UserID = u.UserID, + UserFIO = u.UserFIO, + GroupID = group.ID + }).ToList() ?? new List() + }; + } + + public bool RemoveGroupById(int groupID) + { + try + { + var group = _remoteDatabaseContext.Groups + .FirstOrDefault(x => x.ID == groupID); + if (group == null) return false; + + if (group.Users != null && group.Users.Any()) + { + return false; + } + + _remoteDatabaseContext.Groups.Remove(group); + _remoteDatabaseContext.SaveChanges(); + return true; + } + catch + { + return false; + } + } + + public bool UpdateGroupById(int groupID, string name) + { + try + { + var group = _remoteDatabaseContext.Groups + .FirstOrDefault(x => x.ID == groupID); + if (group == null) return false; + + group.Name = name; + _remoteDatabaseContext.SaveChanges(); + return true; + } + catch + { + return false; + } + } + } +} diff --git a/123/Data/Repository/SQLPresenceRepository.cs b/123/Data/Repository/SQLPresenceRepository.cs new file mode 100644 index 0000000..65acfb7 --- /dev/null +++ b/123/Data/Repository/SQLPresenceRepository.cs @@ -0,0 +1,57 @@ +using _123.Data.LocalData; +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.Repository +{ + public class SQLPresenceRepositoryImpl : IPresenceRepository + { + private readonly RemoteDatabaseContext _remoteDatabaseContext; + + public SQLPresenceRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) + { + _remoteDatabaseContext = remoteDatabaseContext; + } + + public void AddPresence(PresenceDao presence) + { + _remoteDatabaseContext.PresencesDaos.Add(presence); + _remoteDatabaseContext.SaveChanges(); + } + + public List GetPresenceByGroup(int groupId) + { + return _remoteDatabaseContext.PresencesDaos + .Where(p => p.GroupId == groupId) + .ToList(); + } + + public List GetPresenceByGroupAndDate(int groupId, DateOnly date) + { + return _remoteDatabaseContext.PresencesDaos + .Where(p => p.GroupId == groupId && p.Date == date) + .ToList(); + } + + public bool UnCheckAttendence(int firstClass, int lastClass, DateOnly date, int userId) + { + var presToUpdate = _remoteDatabaseContext.PresencesDaos + .Where(x => x.UserID == userId && x.LessonNumber >= firstClass + && x.LessonNumber <= lastClass && x.Date == date).ToList(); + + foreach (var presence in presToUpdate) + { + presence.IsAttedance = false; + } + + _remoteDatabaseContext.SaveChanges(); + return true; + } + } +} diff --git a/123/Data/Repository/SQLUserRepository.cs b/123/Data/Repository/SQLUserRepository.cs new file mode 100644 index 0000000..3db9c1f --- /dev/null +++ b/123/Data/Repository/SQLUserRepository.cs @@ -0,0 +1,93 @@ +using _123.Data.LocalData; +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.Repository +{ + public class SQLUserRepositoryImpl : IUserRepository + { + private readonly RemoteDatabaseContext _remoteDatabaseContext; + + public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) + { + _remoteDatabaseContext = remoteDatabaseContext; + } + + public UserDao FindUserById(int userId) + { + var user = _remoteDatabaseContext.Users + .FirstOrDefault(x => x.UserID == userId); + if (user == null) throw new Exception("Пользователь не найден"); + return user; + } + + public List GetAllUser() + { + return _remoteDatabaseContext.Users + .Select(u => new UserDao + { + UserID = u.UserID, + UserFIO = u.UserFIO, + GroupID = u.GroupID, + Group = u.Group + }) + .ToList(); + } + + public UserDao? GetUserById(int userId) + { + return _remoteDatabaseContext.Users + .FirstOrDefault(x => x.UserID == userId); + } + + public bool RemoveUserById(int userId) + { + try + { + var user = _remoteDatabaseContext.Users + .FirstOrDefault(x => x.UserID == userId); + if (user == null) return false; + + _remoteDatabaseContext.Users.Remove(user); + _remoteDatabaseContext.SaveChanges(); + return true; + } + catch + { + return false; + } + } + + public UserDao? UpdateUser(UserDao userUpdate) + { + try + { + var user = _remoteDatabaseContext.Users + .FirstOrDefault(x => x.UserID == userUpdate.UserID); + if (user == null) return null; + + user.UserFIO = userUpdate.UserFIO; + user.GroupID = userUpdate.GroupID; + + _remoteDatabaseContext.SaveChanges(); + return user; + } + catch + { + return null; + } + } + + public UserDao? UpdateUserById(int userId) + { + return _remoteDatabaseContext.Users + .FirstOrDefault(x => x.UserID == userId); + } + } +} diff --git a/123/Data/Repository/UserRepositoty.cs b/123/Data/Repository/UserRepositoty.cs new file mode 100644 index 0000000..e260d6d --- /dev/null +++ b/123/Data/Repository/UserRepositoty.cs @@ -0,0 +1,73 @@ +using _123.Data.LocalData; +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using _123.Data.Repository; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _123.Data.ReportsHistory +{ + public class UserRepositoryImpl: IUserRepository + { + public UserRepositoryImpl() + { + + GetAllUsers = LocalStaticData.users.Select(it => new UserDao { GroupID = it.GroupID, UserFIO = it.UserFIO, UserID = it.UserId}).ToList(); + } + public List GetAllUsers + { get; set; } + + public List GetAllUser() + { + return GetAllUsers; + } + public bool RemoveUserById(int userId) + { + UserDao? userLocal = GetAllUsers + .Where(x => x.UserID == userId).FirstOrDefault(); + if (userLocal == null) return false; + + return GetAllUsers.Remove(userLocal); + } + public UserDao FindUserById(int userId) + { + UserDao? userLocal = GetAllUsers + .Where(x => x.UserID == userId).FirstOrDefault(); + if (userLocal == null) throw new Exception("Пользователь не найден"); + return userLocal; + } + + + public UserDao? GetUserById(int userId) + { + UserDao? userLocal = GetAllUsers + .Where(x => x.UserID == userId).FirstOrDefault(); + if (userLocal == null) return null; + + return userLocal; + } + + public UserDao? UpdateUser(UserDao userUpdateDao) + { + UserDao? userLocal = GetAllUsers + .Where(x => x.UserID == userUpdateDao.UserID).FirstOrDefault(); + if (userLocal == null) return null; + userLocal.UserFIO = userUpdateDao.UserFIO; + userLocal.GroupID = userUpdateDao.GroupID; + return userLocal; + + } + public UserDao? UpdateUserById(int userId) + { + UserDao? userLocal = GetAllUsers + .Where(x => x.UserID == userId).FirstOrDefault(); + if (userLocal == null) return null; + return userLocal; + + } + } +} diff --git a/123/Demo.csproj b/123/Demo.csproj index ebb8a92..47c142b 100644 --- a/123/Demo.csproj +++ b/123/Demo.csproj @@ -9,7 +9,13 @@ - + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + diff --git a/123/Domain/Models/User.cs b/123/Domain/Models/User.cs index e43f1e6..a0f10a5 100644 --- a/123/Domain/Models/User.cs +++ b/123/Domain/Models/User.cs @@ -9,7 +9,7 @@ namespace _123.Domain.Models public class User { public required string UserFIO { get; set; } - public Guid UserGuid { get; set; } + public int UserID { get; set; } public required Group UserGroup { get; set; } } diff --git a/123/Domain/UseCase/GroupUseCase.cs b/123/Domain/UseCase/GroupUseCase.cs index fece855..60ce3a7 100644 --- a/123/Domain/UseCase/GroupUseCase.cs +++ b/123/Domain/UseCase/GroupUseCase.cs @@ -6,31 +6,41 @@ using System.Text; using System.Threading.Tasks; using _123.Domain.Models; using _123.Data.LocalData.Entity; +using _123.Data.Repository; namespace _123.Domain.UseCase { public class GroupUseCase { - private GroupRepositoryImpl _repositoryGroupImpl; - public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl) + private readonly IGroupRepository _repositoryGroupImpl; + public GroupUseCase(IGroupRepository repositoryGroupImpl) { _repositoryGroupImpl = repositoryGroupImpl; } - public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() + + public List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() .Select(it => new Group { ID = it.ID, Name = it.Name }).ToList(); - public Group UpdateGroupName(String name, String name1) + public bool UpdateGroupName(string id, string name) { - GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name); - if (result == null) throw new Exception(""); - Group? group = GetAllGroups().FirstOrDefault(it => it.Name == result!.Name); - if (group == null) throw new Exception(""); - return new Group { ID = group.ID, Name = name1 }; + return _repositoryGroupImpl.UpdateGroupById(int.Parse(id), name); } - public GroupLocalEntity AddGroup(String name, string id) + + public bool AddGroup(string name, string id) { return _repositoryGroupImpl.AddGroup(name, id); } + + public Group GetGroupById(int id) + { + var group = _repositoryGroupImpl.GetGroupById(id); + if (group == null) return null; + return new Group { ID = group.ID, Name = group.Name }; + } + + public bool RemoveGroupById(int id) + { + return _repositoryGroupImpl.RemoveGroupById(id); + } } - } diff --git a/123/Domain/UseCase/PresenceUseCase.cs b/123/Domain/UseCase/PresenceUseCase.cs new file mode 100644 index 0000000..930175d --- /dev/null +++ b/123/Domain/UseCase/PresenceUseCase.cs @@ -0,0 +1,107 @@ +using _123.Data.LocalData.Entity; +using _123.Data.ReportsHistory; +using _123.Data.Repository; +using _123.Domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Domain.UseCase +{ + public class PresenceUseCase + { + private readonly IPresenceRepository _presenceRepositoryImpl; + private readonly IGroupRepository _groupRepositoryImpl; + private readonly IUserRepository _userRepositoryImpl; + public List GetPresenceByGroup(int groupId) + { + var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList(); + + var presenceByGroup = _presenceRepositoryImpl.GetPresenceByGroup(groupId) + .Where(x => users.Any(user => user.UserID == x.UserID)) + .Select(presence => new Presence + { + User = new User + { + UserID = presence.UserID, + UserGroup = new Group + { + ID = groupId, + Name = _groupRepositoryImpl.GetAllGroup().First(group => group.ID == groupId).Name + }, + UserFIO = users.First(user => user.UserID == presence.UserID).UserFIO, + }, + ClassNum = presence.LessonNumber, + Date = presence.Date, + IsAttedance = presence.IsAttedance, + }).ToList(); + return (List)presenceByGroup; + } + public List GetPresenceByGroupAndDate(int groupId, DateOnly date) + { + var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList(); + + var presenceByGroup = _presenceRepositoryImpl.GetPresenceByGroup(groupId) + .Where(x => users.Any(user => user.UserID == x.UserID && x.Date == date)) + .Select(presence => new Presence + { + User = new User + { + UserID = presence.UserID, + UserGroup = new Group + { + ID = groupId, + Name = _groupRepositoryImpl.GetAllGroup().First(group => group.ID == groupId).Name + }, + UserFIO = users.First(user => user.UserID == presence.UserID).UserFIO, + }, + ClassNum = presence.LessonNumber, + Date = presence.Date, + IsAttedance = presence.IsAttedance, + }).ToList(); + return presenceByGroup; + } + public bool UnCheckAttendance(int firstClass, int lastClass, DateOnly date, int userID) + { + return _presenceRepositoryImpl.UnCheckAttendence(firstClass, lastClass, date, userID); + } + + public Dictionary GetPresenceStatsByGroup(int groupId) + { + var stats = new Dictionary(); + + // Получаем всех студентов группы + var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList(); + stats["Количество студентов"] = users.Count; + + // Получаем все записи посещаемости для группы + var presences = _presenceRepositoryImpl.GetPresenceByGroup(groupId); + + // Считаем количество уникальных занятий + var uniqueLessons = presences + .Select(p => new { p.Date, p.LessonNumber }) + .Distinct() + .Count(); + stats["Количество занятий"] = uniqueLessons; + + // Считаем общую посещаемость + var totalAttendances = presences.Count(p => p.IsAttedance); + var totalPossibleAttendances = users.Count * uniqueLessons; + + if (totalPossibleAttendances > 0) + { + var attendancePercentage = (totalAttendances * 100) / totalPossibleAttendances; + stats["Процент посещаемости"] = attendancePercentage; + } + else + { + stats["Процент посещаемости"] = 0; + } + + return stats; + } + } +} diff --git a/123/Domain/UseCase/UseCaseGeneratePresence.cs b/123/Domain/UseCase/UseCaseGeneratePresence.cs new file mode 100644 index 0000000..a263751 --- /dev/null +++ b/123/Domain/UseCase/UseCaseGeneratePresence.cs @@ -0,0 +1,67 @@ +using _123.Data.LocalData.Entity; +using _123.Data.ReportsHistory; +using _123.Data.Repository; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Domain.UseCase +{ + public class UseCaseGeneratePresence + { + private readonly PresenceRepositoryImpl _presenceRepositoryImpl; + private readonly GroupRepositoryImpl _groupRepositoryImpl; + private readonly UserRepositoryImpl _userRepositoryImpl; + + public UseCaseGeneratePresence(PresenceRepositoryImpl repositoryImpl, + UserRepositoryImpl userRepositoryImpl, + GroupRepositoryImpl groupRepositoryImpl) + { + _presenceRepositoryImpl = repositoryImpl; + _userRepositoryImpl = userRepositoryImpl; + _groupRepositoryImpl = groupRepositoryImpl; + } + + public void AddPrecence(int firstClass, int lastClass, int groupId, DateOnly date) + { + var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList(); + List presence = new List(); + for (int i = firstClass; i < lastClass; i++) + { + foreach (var user in users) + { + PresenceLocalEntity pres = new PresenceLocalEntity { LessonNumber = i, UserID = user.UserID, Date = date }; + } + } + } + + public void AddPresenceForWeek(int firstClass, int lastClass, int groupId, DateOnly startDate) + { + var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList(); + List presence = new List(); + + for (int dayOffset = 0; dayOffset < 7; dayOffset++) + { + DateOnly date = startDate.AddDays(dayOffset); + + for (int i = firstClass; i < lastClass; i++) + { + foreach (var user in users) + { + PresenceLocalEntity pres = new PresenceLocalEntity + { + LessonNumber = i, + UserID = user.UserID, + Date = date + }; + presence.Add(pres); + } + } + } + } + } + + +} diff --git a/123/Domain/UseCase/UserUseCase.cs b/123/Domain/UseCase/UserUseCase.cs index 95d70bf..5c966da 100644 --- a/123/Domain/UseCase/UserUseCase.cs +++ b/123/Domain/UseCase/UserUseCase.cs @@ -1,5 +1,7 @@ using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; using _123.Data.ReportsHistory; +using _123.Data.Repository; using _123.Domain.Models; using System; using System.Collections.Generic; @@ -11,54 +13,68 @@ namespace _123.Domain.UseCase { public class UserUseCase { - private UserRepositoryImpl _repositoryUserImpl; - private GroupRepositoryImpl _repositoryGroupImpl; + private readonly IUserRepository _repositoryUserImpl; + private readonly IGroupRepository _repositoryGroupImpl; - public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) + public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl) { _repositoryUserImpl = repositoryImpl; _repositoryGroupImpl = repositoryGroupImpl; } - public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() + public List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() .Select(it => new Group { ID = it.ID, Name = it.Name }).ToList(); - public List GetAllUsers() => _repositoryUserImpl.GetAllUsers - .Join(_repositoryGroupImpl.GetAllGroups(), + + public List GetAllUsers() => _repositoryUserImpl.GetAllUser() + .Join(_repositoryGroupImpl.GetAllGroup(), user => user.GroupID, group => group.ID, (user, group) => new User { UserFIO = user.UserFIO, - UserGuid = user.UserGuid, + UserID = user.UserID, UserGroup = new Group { ID = group.ID, Name = group.Name } } ).ToList(); - public bool RemoveUserByGuid(Guid userGuid) + public bool RemoveUserByGuid(int userId) { - return _repositoryUserImpl.RemoveUserByGuid(userGuid); + return _repositoryUserImpl.RemoveUserById(userId); } + public User UpdateUser(User user) { - UserLocalEntity userLocalEnity = new UserLocalEntity { UserFIO = user.UserFIO, GroupID = user.UserGroup.ID, UserGuid = user.UserGuid }; - UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEnity); - if (result == null) throw new Exception(""); - Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result!.GroupID); - if (group == null) throw new Exception(""); - return new User { UserFIO = user.UserFIO, UserGuid = user.UserGuid, UserGroup = group }; + UserDao userDao = new UserDao { + UserFIO = user.UserFIO, + GroupID = user.UserGroup.ID, + UserID = user.UserID + }; + UserDao? result = _repositoryUserImpl.UpdateUser(userDao); + if (result == null) throw new Exception("Не удалось обновить пользователя"); + Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result.GroupID); + if (group == null) throw new Exception("Группа не найдена"); + return new User { UserFIO = user.UserFIO, UserID = user.UserID, UserGroup = group }; } - public UserLocalEntity FindUserByGuid(Guid userGuid) + + public User FindUserByGuid(int userId) { - return _repositoryUserImpl.FindUserByGuid(userGuid); + var userDao = _repositoryUserImpl.FindUserById(userId); + return new User + { + UserID = userDao.UserID, + UserFIO = userDao.UserFIO, + UserGroup = GetAllGroups().FirstOrDefault(g => g.ID == userDao.GroupID) + }; } - public UserLocalEntity UpdateUserByGuid(Guid userGuid, String name, String gro) + + public UserDao UpdateUserByGuid(int userId, string name, string groupId) { - UserLocalEntity? result = _repositoryUserImpl.UpdateUserByGuid(userGuid); - if (result == null) throw new Exception(""); - Group? group = GetAllGroups().FirstOrDefault(it => it.ID == int.Parse(gro)); - if (group == null) throw new Exception(""); - return new UserLocalEntity { UserFIO = name, GroupID = int.Parse(gro), UserGuid = userGuid}; + UserDao? result = _repositoryUserImpl.UpdateUserById(userId); + if (result == null) throw new Exception("Пользователь не найден"); + Group? group = GetAllGroups().FirstOrDefault(it => it.ID == int.Parse(groupId)); + if (group == null) throw new Exception("Группа не найдена"); + return new UserDao { UserFIO = name, GroupID = int.Parse(groupId), UserID = userId }; } } } diff --git a/123/Program.cs b/123/Program.cs index b9d7ee3..71f1eb0 100644 --- a/123/Program.cs +++ b/123/Program.cs @@ -1,10 +1,22 @@ -using _123.Data.ReportsHistory; +using _123.Data.RemoteData.RemoteDatabase; +using _123.Data.ReportsHistory; +using _123.Data.Repository; using _123.Domain.UseCase; using _123.UI; +using Microsoft.Extensions.DependencyInjection; +using System.Text.RegularExpressions; -GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); -UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl(); -UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl); -GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl); +IServiceCollection services = new ServiceCollection(); +services + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddDbContext() + .AddSingleton() + .AddSingleton() + .AddSingleton(); +var serviceProvider = services.BuildServiceProvider (); + +var mainMenuUI = serviceProvider.GetRequiredService(); -MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase); \ No newline at end of file diff --git a/123/UI/GroupConsole.cs b/123/UI/GroupConsole.cs index 6d145d2..6d21013 100644 --- a/123/UI/GroupConsole.cs +++ b/123/UI/GroupConsole.cs @@ -28,20 +28,13 @@ namespace _123.UI { StringBuilder groupOutput = new StringBuilder(); var group = _groupUseCase.UpdateGroupName(name,name1); - { - groupOutput.AppendLine($"{group.Name}\t{group.ID}"); - } - Console.WriteLine(groupOutput); } public void AddGroup (String name, String id) { - StringBuilder groupOutput = new StringBuilder(); - var group = _groupUseCase.AddGroup(name,id); - { - groupOutput.AppendLine($"{group.Name}\t{group.ID}"); - } - Console.WriteLine(groupOutput); + string output = _groupUseCase.AddGroup(name , id) ? " " : " "; + Console.WriteLine(output); } + } } \ No newline at end of file diff --git a/123/UI/MainMenu.cs b/123/UI/MainMenu.cs index 8099cb6..309de15 100644 --- a/123/UI/MainMenu.cs +++ b/123/UI/MainMenu.cs @@ -14,10 +14,13 @@ namespace _123.UI GroupConsoleUI _groupConsoleUI; - public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase) + PresenceConsoleUI _presenceConsoleUI; + + public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase, PresenceUseCase presenceUseCase) { _userConsoleUI = new UserConsoleUI(userUseCase); _groupConsoleUI = new GroupConsoleUI(groupUseCase); + _presenceConsoleUI = new PresenceConsoleUI(presenceUseCase); DisplayMenu(); @@ -30,12 +33,17 @@ namespace _123.UI switch (Console.ReadLine()) { case "1": _userConsoleUI.DisplayAllUsers(); break; - case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; + case "2": _userConsoleUI.RemoveUserById(int.Parse(Console.ReadLine())); break; case "3": _groupConsoleUI.DisplayAllGroups(); break; - case "4": _userConsoleUI.FindUserByGuid(Guid.Parse(Console.ReadLine()));break; - case "5": _userConsoleUI.UpdateUserByGuid(Guid.Parse(Console.ReadLine()),Console.ReadLine(), Console.ReadLine()); break; - case "6": _groupConsoleUI.UpdateGroupName(Console.ReadLine(),Console.ReadLine()); break; - case "7": _groupConsoleUI.AddGroup(Console.ReadLine(), Console.ReadLine());break; + case "4": _userConsoleUI.FindUserById(int.Parse(Console.ReadLine())); break; + case "5": _userConsoleUI.UpdateUserById(int.Parse(Console.ReadLine()), Console.ReadLine(), Console.ReadLine()); break; + case "6": _groupConsoleUI.UpdateGroupName(Console.ReadLine(), Console.ReadLine()); break; + case "7": _groupConsoleUI.AddGroup(Console.ReadLine(), Console.ReadLine()); break; + case "8": _presenceConsoleUI.GetPresenceByGroup(int.Parse(Console.ReadLine())); break; + case "9": _presenceConsoleUI.GetPresenceByGroupAndDAte(int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine())); break; + case "10": _presenceConsoleUI.UnCheckAttendence(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine()), int.Parse(Console.ReadLine())); break; + case "11": _presenceConsoleUI.AddPresence(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine())); break; + default: DisplayMenu(); break; diff --git a/123/UI/PresenceConsole.cs b/123/UI/PresenceConsole.cs new file mode 100644 index 0000000..60d9eee --- /dev/null +++ b/123/UI/PresenceConsole.cs @@ -0,0 +1,100 @@ +using _123.Domain.UseCase; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.UI +{ + public class PresenceConsoleUI + { + PresenceUseCase _presenceUseCase; + UseCaseGeneratePresence _useCaseGeneratePresence; + private PresenceUseCase presenceUseCase; + + public PresenceConsoleUI(PresenceUseCase presenceUseCase, UseCaseGeneratePresence useCaseGeneratePresence) + { + _presenceUseCase = presenceUseCase; + _useCaseGeneratePresence = useCaseGeneratePresence; + } + + public PresenceConsoleUI(PresenceUseCase presenceUseCase) + { + this.presenceUseCase = presenceUseCase; + } + + public void GetPresenceByGroup(int groupId) + { + StringBuilder presenceOutput = new StringBuilder(); + var presence = _presenceUseCase.GetPresenceByGroup(groupId); + foreach (var p in presence) + { + presenceOutput.AppendLine($"{p.ClassNum}\t{p.User}\t{p.Date}"); + } + Console.WriteLine(presenceOutput); + } + + public void GetPresenceByGroupAndDAte(int groupId, DateOnly date) + { + StringBuilder presenceOutput = new StringBuilder(); + var presence = _presenceUseCase.GetPresenceByGroupAndDate(groupId, date); + foreach (var p in presence) + { + presenceOutput.AppendLine($"{p.ClassNum}\t{p.User}\t{p.Date}"); + } + Console.WriteLine(presenceOutput); + } + + public void UnCheckAttendence(int firstClass, int lastClass, DateOnly date, int userId) + { + var result = _presenceUseCase.UnCheckAttendance(firstClass, lastClass, date, userId); + Console.WriteLine(result ? "Посещаемость успешно обновлена" : "Ошибка при обновлении посещаемости"); + } + + public void AddPresence(int firstClass, int lastClass, int groupId, DateOnly date) + { + try + { + _useCaseGeneratePresence.AddPrecence(firstClass, lastClass, groupId, date); + Console.WriteLine("Посещаемость успешно добавлена"); + } + catch (Exception ex) + { + Console.WriteLine($"Ошибка при добавлении посещаемости: {ex.Message}"); + } + } + public void GetPresenceStatsByGroup(int groupId) + { + var stats = _presenceUseCase.GetPresenceStatsByGroup(groupId); + StringBuilder output = new StringBuilder(); + + output.AppendLine($"Информация о группе {groupId}:"); + output.AppendLine($"Количество студентов: {stats["Количество студентов"]}"); + output.AppendLine($"Количество занятий: {stats["Количество занятий"]}"); + output.AppendLine($"Общий процент посещаемости: {stats["Процент посещаемости"]}%"); + output.AppendLine("\nСтатистика по студентам:"); + + var presence = _presenceUseCase.GetPresenceByGroup(groupId); + var students = presence.GroupBy(p => p.User) + .Select(g => new { + Student = g.Key, + Total = stats["Количество занятий"], + Attended = g.Count(p => p.IsAttedance), + Missed = stats["Количество занятий"] - g.Count(p => p.IsAttedance), + Percentage = (g.Count(p => p.IsAttedance) * 100) / stats["Количество занятий"] + }); + + foreach (var student in students) + { + output.AppendLine($"\nСтудент: {student.Student.UserFIO}"); + output.AppendLine($"Посещено занятий: {student.Attended}"); + output.AppendLine($"Пропущено занятий: {student.Missed}"); + output.AppendLine($"Процент посещаемости: {student.Percentage}%"); + } + + Console.WriteLine(output.ToString()); + } + } + +} diff --git a/123/UI/UserConsole.cs b/123/UI/UserConsole.cs index c85aa36..2952bb5 100644 --- a/123/UI/UserConsole.cs +++ b/123/UI/UserConsole.cs @@ -17,10 +17,9 @@ namespace _123.UI _userUseCase = userUseCase; } - public void RemoveUserByGuid(Guid guidUser) + public void RemoveUserById(int userId) { - - string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален"; + string output = _userUseCase.RemoveUserByGuid(userId) ? "Пользователь удален" : "Пользователь не удален"; Console.WriteLine(output); } @@ -29,27 +28,43 @@ namespace _123.UI StringBuilder userOutput = new StringBuilder(); foreach (var user in _userUseCase.GetAllUsers()) { - userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.UserGroup.Name}"); + userOutput.AppendLine($"{user.UserID}\t{user.UserFIO}\t{user.UserGroup.Name}"); } Console.WriteLine(userOutput); } - public void FindUserByGuid (Guid guidUser) + + public void FindUserById(int userId) { StringBuilder userOutput = new StringBuilder(); - var user = _userUseCase.FindUserByGuid(guidUser); - { - userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.GroupID}"); - } + var user = _userUseCase.FindUserByGuid(userId); + userOutput.AppendLine($"{user.UserID}\t{user.UserFIO}\t{user.UserGroup}"); Console.WriteLine(userOutput); } - public void UpdateUserByGuid(Guid userGuid,String name,String group) + + public void UpdateUserById(int userId, String name, String groupId) { - StringBuilder userOutput = new StringBuilder(); - var user = _userUseCase.UpdateUserByGuid(userGuid,name,group); + try { - userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.GroupID}"); + 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}"); } - Console.WriteLine(userOutput); } } } diff --git a/Загрузки - Ярлык.lnk b/Загрузки - Ярлык.lnk new file mode 100644 index 0000000000000000000000000000000000000000..dc2ead35e19005a3cf5d3fb03aa8261b1b494649 GIT binary patch literal 778 zcmeZaU|?VrVFHp23V)(6f-a|G3Wtd0z~722p|mt$@vAjx+c12x<&?I zzFE~do$tp@{C5fGRg3G{Op}4274fF4>ZRBs1jrf9}t60fyE$*UkJn?w=K&`*07y=NpR~mh6DaLB`$;l#pOT> zKsG1>F}n9+@B~K;g9}4GLpd;La)5LqFqnXm3I&!x8f4){v0Rt6y#*f2Jsk9w*jDt& Z0>v{xYCM40P3l??h|R!Y07^P2007dirN#gN literal 0 HcmV?d00001