diff --git a/Data/Repository/IPresenceRepository.cs b/Data/Repository/IPresenceRepository.cs index 2819961..ee2554d 100644 --- a/Data/Repository/IPresenceRepository.cs +++ b/Data/Repository/IPresenceRepository.cs @@ -9,10 +9,10 @@ namespace Posechaemost.Data.Repository { public interface IPresenceRepository { - List GetPresenceListByGroup(int groupId); - List GetPresenceListByGroupAndDate(int groupId, DateOnly date); - - void UncheckAttendence(Presence presence); + List GetPresenceByGroup(int groupId); + List GetPresenceByGroupAndDate(int groupId, DateOnly date); + bool UncheckAttendence(PresenceLocalEntity presence); + void AddPresence(PresenceLocalEntity presence); } } \ No newline at end of file diff --git a/Data/Repository/PresenceRepositoryImpl.cs b/Data/Repository/PresenceRepositoryImpl.cs index fa54297..20961e7 100644 --- a/Data/Repository/PresenceRepositoryImpl.cs +++ b/Data/Repository/PresenceRepositoryImpl.cs @@ -16,19 +16,37 @@ namespace Posechaemost.Data.Repository public List GetAllPresences { get; set; } - public List GetPresenceListByGroup(int groupId) + public void AddPresence(PresenceLocalEntity presence) + { + PresenceLocalEntity? presenceLocal = GetAllPresences.FirstOrDefault(); + // GroupLocalEntity? group = new GroupLocalEntity(); + presenceLocal.ClassNumber = presence.ClassNumber; + presence.UserGuid = presence.UserGuid; + presenceLocal.Date = presence.Date; + presenceLocal.IsAttendence = presence.IsAttendence; + } + + public List GetPresenceByGroup(int groupId) { return GetAllPresences; } - public List GetPresenceListByGroupAndDate(int groupId, DateOnly date) + public List GetPresenceByGroupAndDate(int groupId, DateOnly date) { return GetAllPresences; } - public void UncheckAttendence(Presence presence) + public bool UncheckAttendence(PresenceLocalEntity presence) { - throw new NotImplementedException(); + var presToUpdate = GetAllPresences + .Where(x => x.IsAttendence == presence.IsAttendence + && x.UserGuid == presence.UserGuid && x.Date == presence.Date + && x.ClassNumber == presence.ClassNumber).ToList(); + + foreach (var pres in presToUpdate) { + presence.IsAttendence = false; + } + return true; } } } \ No newline at end of file diff --git a/Domain/UseCase/PresenceUseCase.cs b/Domain/UseCase/PresenceUseCase.cs new file mode 100644 index 0000000..adcc8b3 --- /dev/null +++ b/Domain/UseCase/PresenceUseCase.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using Posechaemost.Data.LocalData.Entity; +using Posechaemost.Data.Repository; +using Posechaemost.Domain.Models; + +namespace Posechaemost.Domain.UseCase +{ + public class PresenceUseCase + { + private readonly PresenceRepositoryImpl _repositoryPresenceImpl; + private readonly UserRepositoryImpl _repositoryUserImpl; + private readonly GroupRepositoryImpl _repositoryGroupImpl; + + public PresenceUseCase(PresenceRepositoryImpl repositoryImpl, UserRepositoryImpl userRepositoryImpl, GroupRepositoryImpl groupRepositoryImpl) { + _repositoryPresenceImpl = repositoryImpl; + _repositoryUserImpl = userRepositoryImpl; + _repositoryGroupImpl = groupRepositoryImpl; + } + + public List GetPresenceByGroup(int groupId) { + var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList(); + + var presenceByGroup = _repositoryPresenceImpl.GetPresenceByGroup(groupId) + .Where(x => users.Any(user => user.Guid == x.UserGuid)) + .Select(presence => new Presence{ + User = new User{ + Guid = presence.UserGuid, + GroupId = new Group{ + Id = groupId, + Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name + }, + FIO = users.First(user => user.Guid == presence.UserGuid).FIO, + }, + ClassNumber = presence.ClassNumber, + Date = presence.Date, + IsAttendence = presence.IsAttendence + }).ToList(); + return presenceByGroup; + } + + public List GetPresenceByGroupAndDate(int groupId, DateOnly date) { + var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList(); + + var presenceByGroupAndDate = _repositoryPresenceImpl.GetPresenceByGroupAndDate(groupId, date) + .Where(x => users.Any(user => user.Guid == x.UserGuid && x.Date == date)) + .Select(presence => new Presence{ + User = new User{ + Guid = presence.UserGuid, + GroupId = new Group{ + Id = groupId, + Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name + }, + FIO = users.First(user => user.Guid == presence.UserGuid).FIO, + }, + ClassNumber = presence.ClassNumber, + Date = presence.Date, + IsAttendence = presence.IsAttendence + }).ToList(); + return presenceByGroupAndDate; + } + + public bool UncheckAttendence(PresenceLocalEntity presence) { + return _repositoryPresenceImpl.UncheckAttendence(presence); + } + } +} \ No newline at end of file diff --git a/Domain/UseCase/UseCasePresence.cs b/Domain/UseCase/UseCasePresence.cs deleted file mode 100644 index 8d6437e..0000000 --- a/Domain/UseCase/UseCasePresence.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using Posechaemost.Data.LocalData.Entity; -using Posechaemost.Data.Repository; -using Posechaemost.Domain.Models; - -namespace Posechaemost.Domain.UseCase -{ - public class UseCasePresence - { - private readonly PresenceRepositoryImpl _repositoryPresenceImpl; - private readonly UserRepositoryImpl _repositoryUserImpl; - private readonly GroupRepositoryImpl _repositoryGroupImpl; - - public UseCasePresence(PresenceRepositoryImpl repositoryImpl, UserRepositoryImpl userRepositoryImpl, GroupRepositoryImpl groupRepositoryImpl) { - _repositoryPresenceImpl = repositoryImpl; - _repositoryUserImpl = userRepositoryImpl; - _repositoryGroupImpl = groupRepositoryImpl; - } - - - } -} \ No newline at end of file diff --git a/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs b/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs index 54063eb..8b54eee 100644 --- a/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs +++ b/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4105b8029769b2ea442771dc29b948bad308afc9")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6b32e405d76bb739524c318b227f1fa95db1cba6")] [assembly: System.Reflection.AssemblyProductAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache b/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache index b8df37a..4e37887 100644 --- a/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache @@ -1 +1 @@ -2d28f4118d0518446dabfbd87d6de7e33862a518a80b4f754a0e37e26437422d +4adf1b2c58c78e6eafd52a8be1c408433fb9f4a3525dbf62f4e5019169eebcab diff --git a/obj/Posechaemost.csproj.nuget.dgspec.json b/obj/Posechaemost.csproj.nuget.dgspec.json index e259d72..e6763e0 100644 --- a/obj/Posechaemost.csproj.nuget.dgspec.json +++ b/obj/Posechaemost.csproj.nuget.dgspec.json @@ -78,7 +78,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.402/PortableRuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.403/PortableRuntimeIdentifierGraph.json" } } } diff --git a/obj/project.assets.json b/obj/project.assets.json index ae62223..cb9e1f0 100644 --- a/obj/project.assets.json +++ b/obj/project.assets.json @@ -2187,7 +2187,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.402/PortableRuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.403/PortableRuntimeIdentifierGraph.json" } } } diff --git a/obj/project.nuget.cache b/obj/project.nuget.cache index 40ae4e3..1f16185 100644 --- a/obj/project.nuget.cache +++ b/obj/project.nuget.cache @@ -1,6 +1,6 @@ { "version": 2, - "dgSpecHash": "gSN3MF76u68=", + "dgSpecHash": "Mj/MlEhPDCU=", "success": true, "projectFilePath": "/home/gara/csharp/Posechaemost/Posechaemost.csproj", "expectedPackageFiles": [