diff --git a/Zurnal/Date/Repository/SQLRepos/SQLNado.cs b/Zurnal/Date/Repository/SQLRepos/SQLNado.cs index 97f3ebe..3983cc6 100644 --- a/Zurnal/Date/Repository/SQLRepos/SQLNado.cs +++ b/Zurnal/Date/Repository/SQLRepos/SQLNado.cs @@ -1,10 +1,11 @@ + using Zurnal.Date.LocalDate; using Zurnal.domain.Models; using Zurnal.RemaDateBase.DateDao; -namespace Data.Repository +namespace Zurnal.Date.Repository.SQLRepos { - public class SQLGroupRepositoryImpl:IGroupRepository + public class SQLGroupRepositoryImpl : IGroupRepository { private readonly RemoteDateBaseContext _remoteDataBaseContext; @@ -14,6 +15,8 @@ namespace Data.Repository public List AllGroup => throw new NotImplementedException(); + List IGroupRepository.AllGroup => throw new NotImplementedException(); + public bool AddGroup(GroupLocalEntity newGroup) { GroupDao groupDao = new GroupDao { GroupName = newGroup.Name }; @@ -34,41 +37,10 @@ namespace Data.Repository public List GetAllGroups() => LocalStaticData.groups; - public GroupLocalEntity GetGroupById(int groupID) - { - throw new NotImplementedException(); - } - - public bool RemoveGroupById(int groupID) - { - throw new NotImplementedException(); - } - - public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup) + List IGroupRepository.GetAllGroup() { throw new NotImplementedException(); } } - public class SQLPresenceRepositoryImpl: IPresenceRepository -{ -private readonly RemoteDateBaseContext _remoteDatabaseContext; - - public SQLPresenceRepositoryImpl(RemoteDateBaseContext remoteDatabaseContext) - { - _remoteDatabaseContext = remoteDatabaseContext; - } - public DateOnly? GetLastDateByGroupId(int groupId) - { - var lastDate = _remoteDatabaseContext.Presence - .Where(p => p.GroupId == groupId) - .OrderByDescending(p => p.Date) - .Select(p => p.Date) - .FirstOrDefault(); - - return lastDate == default ? (DateOnly?)null : lastDate; - } - -} - } \ No newline at end of file diff --git a/Zurnal/Date/Repository/SQLRepos/SQLPresenceRepositoryImpl.cs b/Zurnal/Date/Repository/SQLRepos/SQLPresenceRepositoryImpl.cs index e69de29..c8eeb01 100644 --- a/Zurnal/Date/Repository/SQLRepos/SQLPresenceRepositoryImpl.cs +++ b/Zurnal/Date/Repository/SQLRepos/SQLPresenceRepositoryImpl.cs @@ -0,0 +1,49 @@ +using Zurnal.Date.LocalDate; +using Zurnal.domain.Models; +using Zurnal.RemaDateBase.DateDao; + +namespace Zurnal.Date.Repository.SQLRepos +{ + public class SQLPresenceRepositoryImpl : IPresenceRepository + { + private readonly RemoteDateBaseContext _remoteDataBaseContext; + + public SQLPresenceRepositoryImpl(RemoteDateBaseContext remoteDataBaseContext) { + _remoteDataBaseContext = remoteDataBaseContext; + } + + public void AddPresence(PresnceDao presence) + { + var result = _remoteDataBaseContext.Presence.Add(presence); + if (result != null) { + _remoteDataBaseContext.SaveChanges(); + } + } + + public PresnceDao GetPresenceById(int id) + { + return _remoteDataBaseContext.Presence.Find(id); + } + + public IEnumerable GetAllPresences() + { + return _remoteDataBaseContext.Presence.ToList(); + } + + public void UpdatePresence(PresnceDao presence) + { + _remoteDataBaseContext.Presence.Update(presence); + _remoteDataBaseContext.SaveChanges(); + } + + public void DeletePresence(int id) + { + var presence = GetPresenceById(id); + if (presence != null) + { + _remoteDataBaseContext.Presence.Remove(presence); + _remoteDataBaseContext.SaveChanges(); + } + } + } +} \ No newline at end of file diff --git a/Zurnal/Date/Repository/SQLRepos/SQLUserRepositoryImpl.cs b/Zurnal/Date/Repository/SQLRepos/SQLUserRepositoryImpl.cs index e69de29..dcba50b 100644 --- a/Zurnal/Date/Repository/SQLRepos/SQLUserRepositoryImpl.cs +++ b/Zurnal/Date/Repository/SQLRepos/SQLUserRepositoryImpl.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Zurnal.Data.Repository; +using Zurnal.domain.Models; +using Zurnal.RemaDateBase.DateDao; + +namespace Zurnal.Date.Repository.SQLRepos +{ + public class SQLUserRepositoryImpl : IUserRepository + { + private readonly RemoteDateBaseContext _remoteDataBaseContext; + + public SQLUserRepositoryImpl(RemoteDateBaseContext remoteDataBaseContext) + { + _remoteDataBaseContext = remoteDataBaseContext; + } + + public List GetAllUsers => + _remoteDataBaseContext.User.Select(user => new UserDao + { + UserGuid = user.UserGuid, + FIO = user.FIO, + GroupID = user.GroupID, + }).ToList(); + + public bool RemoveUserByGuid(Guid userGuid) + { + var user = _remoteDataBaseContext.User.Find(userGuid); + if (user == null) return false; + + _remoteDataBaseContext.User.Remove(user); + _remoteDataBaseContext.SaveChanges(); + return true; + } + + public UserDao? GetUserByGuid(Guid userGuid) + { + var user = _remoteDataBaseContext.User.Find(userGuid); + if (user == null) return null; + + return new UserDao + { + UserGuid = user.UserGuid, + FIO = user.FIO, + GroupID = user.GroupID, + }; + } + + public UserDao? UpdateUser(UserDao userUpdateLocalEnity) + { + var user = _remoteDataBaseContext.User.Find(userUpdateLocalEnity.UserGuid); + if (user == null) return null; + + user.FIO = userUpdateLocalEnity.FIO; + user.GroupID = userUpdateLocalEnity.GroupID; + _remoteDataBaseContext.SaveChanges(); + return userUpdateLocalEnity; + } + } +} \ No newline at end of file diff --git a/Zurnal/Program.cs b/Zurnal/Program.cs index 4997800..15ceb13 100644 --- a/Zurnal/Program.cs +++ b/Zurnal/Program.cs @@ -1,9 +1,13 @@ -using Data.Repository; -using Zurnal.Data.Repository; +using Zurnal.Data.Repository; +using Zurnal.Date.Repository.SQLRepos; using Zurnal.Domain.UseCase; using Zurnal.Presence; using Zurnal.UI; +class Programka +{ + static void Main(string[] args) + { IServiceCollection services = new ServiceCollection(); services @@ -20,3 +24,5 @@ var serviceProvider = services.BuildServiceProvider(); MainMenuUI mainMenuUI = serviceProvider.GetService(); mainMenuUI.DisplayMenu(); +} + } \ No newline at end of file diff --git a/Zurnal/RemaDateBase/DateDao/UserDao.cs b/Zurnal/RemaDateBase/DateDao/UserDao.cs index dadb8a3..419d8f5 100644 --- a/Zurnal/RemaDateBase/DateDao/UserDao.cs +++ b/Zurnal/RemaDateBase/DateDao/UserDao.cs @@ -6,5 +6,5 @@ public Guid UserGuid { get; set; } public GroupDao Group { get; set; } public required int GroupID { get; set; } -} + } } \ No newline at end of file diff --git a/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs b/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs index e69de29..1f792fd 100644 --- a/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs +++ b/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs @@ -0,0 +1,10 @@ +using Zurnal.RemaDateBase.DateDao; + +public interface IPresenceRepository +{ + void AddPresence(PresnceDao presence); + PresnceDao GetPresenceById(int id); + IEnumerable GetAllPresences(); + void UpdatePresence(PresnceDao presence); + void DeletePresence(int id); +} \ No newline at end of file diff --git a/Zurnal/RemaDateBase/Interfase/IUserRepository.cs b/Zurnal/RemaDateBase/Interfase/IUserRepository.cs index 90b0ee2..6d9e015 100644 --- a/Zurnal/RemaDateBase/Interfase/IUserRepository.cs +++ b/Zurnal/RemaDateBase/Interfase/IUserRepository.cs @@ -7,9 +7,9 @@ namespace Zurnal.Data.Repository { public interface IUserRepository { - List GetAllUsers { get; } + List GetAllUsers { get; } bool RemoveUserByGuid(Guid userGuid); - UserLocalEnity? GetUserByGuid(Guid userGuid); - UserLocalEnity? UpdateUser(UserLocalEnity userUpdateLocalEnity); + UserDao? GetUserByGuid(Guid userGuid); + UserDao? UpdateUser(UserDao userUpdateLocalEnity); } } \ No newline at end of file diff --git a/Zurnal/RemaDateBase/RemoutDateBase.cs b/Zurnal/RemaDateBase/RemoutDateBase.cs index cc3141f..4aa807c 100644 --- a/Zurnal/RemaDateBase/RemoutDateBase.cs +++ b/Zurnal/RemaDateBase/RemoutDateBase.cs @@ -6,7 +6,6 @@ public class RemoteDateBaseContext : DbContext public DbSet Group { get; set; } public DbSet User { get; set; } public DbSet Presence { get; set; } - public object Groups { get; internal set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/Zurnal/UI/MeinMenu.cs b/Zurnal/UI/MeinMenu.cs index 058e016..2fa0cb1 100644 --- a/Zurnal/UI/MeinMenu.cs +++ b/Zurnal/UI/MeinMenu.cs @@ -13,7 +13,7 @@ namespace Zurnal.UI } - private void DisplayMenu() + public void DisplayMenu() { while (true) { @@ -26,9 +26,8 @@ namespace Zurnal.UI DisplayMenu(); break; } - } } - } + } \ No newline at end of file diff --git a/Zurnal/obj/Debug/net8.0/Zurnal.csproj.CoreCompileInputs.cache b/Zurnal/obj/Debug/net8.0/Zurnal.csproj.CoreCompileInputs.cache index b74c6d1..ec7a4a4 100644 --- a/Zurnal/obj/Debug/net8.0/Zurnal.csproj.CoreCompileInputs.cache +++ b/Zurnal/obj/Debug/net8.0/Zurnal.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -e7472ea1c8f499a7ec454e6a70d834c4f0deb35d64d70c46a4cd5bc76239a16e +363301da55cc0da9a5b5db64cdaad65e5fa588627917582d0f884f0b7608c9c8 diff --git a/Zurnal/presence_api/ServiceExtensions/ServiceExtensions.cs b/Zurnal/presence_api/ServiceExtensions/ServiceExtensions.cs index c52500b..d95b264 100644 --- a/Zurnal/presence_api/ServiceExtensions/ServiceExtensions.cs +++ b/Zurnal/presence_api/ServiceExtensions/ServiceExtensions.cs @@ -1,6 +1,5 @@ - -using Data.Repository; -using domain; +using Zurnal.Date.Repository.SQLRepos; +using Zurnal.Domain.UseCase; public static class ServiceExtensions { public static void ConfigurateGroup(this IServiceCollection services){ diff --git a/Zurnal/tempCodeRunnerFile.cs b/Zurnal/tempCodeRunnerFile.cs index 96faedd..040a5c0 100644 --- a/Zurnal/tempCodeRunnerFile.cs +++ b/Zurnal/tempCodeRunnerFile.cs @@ -1 +1 @@ -IServiceCollection \ No newline at end of file +MainMenuUI \ No newline at end of file