diff --git a/Data/Entity/Group.cs b/Data/Entity/Group.cs index 0032a5c..e0b05ad 100644 --- a/Data/Entity/Group.cs +++ b/Data/Entity/Group.cs @@ -1,15 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Demo.domain.Models +namespace Demo.Domain.Models { public class GroupLocalEntity { - public required int Id { get; set; } - public required string Name { get; set; } - + public required int ID {get; set; } + public required string Name{get; set; } } } \ No newline at end of file diff --git a/Data/Entity/Presence.cs b/Data/Entity/Presence.cs index d3a5474..29995e7 100644 --- a/Data/Entity/Presence.cs +++ b/Data/Entity/Presence.cs @@ -1,16 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Demo.domain.Models -{ - public class PresenceLocalEntity - { - public required Guid UserGuid { get; set; } +namespace Demo.Domain.Models{ + public class PresenceLocalEntity{ + public required Guid UserGuid{get; set; } public bool IsAttedance { get; set; } = true; public required DateOnly Date { get; set; } + public required int LessonNumber { get; set; } } } \ No newline at end of file diff --git a/Data/Entity/User.cs b/Data/Entity/User.cs index df6f2e6..1d14a68 100644 --- a/Data/Entity/User.cs +++ b/Data/Entity/User.cs @@ -1,24 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Demo.domain.Models -{ - public class UserLocalEntity : IEquatable - { - public required string FIO { get; set; } - public Guid Guid { get; set; } - - public required int GroupID { get; set; } - - +namespace Demo.Domain.Models{ + public class UserLocalEntity :IEquatable{ + public required string FIO{get; set; } + public Guid Guid {get; set; } + public required int GroupID{get; set; } public bool Equals(UserLocalEntity? other) { if (other == null) return false; return this.Guid.Equals(other.Guid); } - } +} } \ No newline at end of file diff --git a/Data/LocalData/LocalStaticData.cs b/Data/LocalData/LocalStaticData.cs index e6dc4e3..4d26fdd 100644 --- a/Data/LocalData/LocalStaticData.cs +++ b/Data/LocalData/LocalStaticData.cs @@ -1,21 +1,14 @@ -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.NetworkInformation; -using System.Text; -using System.Threading.Tasks; +using Demo.Domain.Models; namespace Demo.Data.LocalData { - public static class LocalStaticData + public class LocalStaticData { public static List groups => new List - { - new GroupLocalEntity{ Id = 1, Name = "ИП1-21" }, - new GroupLocalEntity{ Id = 2, Name = "ИП1-22" }, - new GroupLocalEntity{ Id = 3, Name = "ИП1-23" }, + new GroupLocalEntity{ID = 1, Name = "ИП1-21"}, + new GroupLocalEntity{ID = 2, Name = "ИП1-22"}, + new GroupLocalEntity{ID = 3, Name = "ИП1-23"}, }; public static List users => new List diff --git a/Data/RemoteData/RemoteDataBase/DAO/Group.cs b/Data/RemoteData/RemoteDataBase/DAO/Group.cs index abd6eb9..dc1f561 100644 --- a/Data/RemoteData/RemoteDataBase/DAO/Group.cs +++ b/Data/RemoteData/RemoteDataBase/DAO/Group.cs @@ -1,10 +1,9 @@ - -namespace Demo.Data.RemoteData.RemoteDataBase.DAO +namespace Demo.Data.RemoteData.RemoteDataBase.DAO { - public class GroupDao { - - public int Id { get; set; } - public string Name { get; set; } - public IEnumerable User { get; set; } + public class GroupDAO + { + public int ID {get; set; } + public string Name{get; set; } + public IEnumerable Users {get; set; } } } \ No newline at end of file diff --git a/Data/RemoteData/RemoteDataBase/DAO/Presence.cs b/Data/RemoteData/RemoteDataBase/DAO/Presence.cs index 62b1ab6..c7d9622 100644 --- a/Data/RemoteData/RemoteDataBase/DAO/Presence.cs +++ b/Data/RemoteData/RemoteDataBase/DAO/Presence.cs @@ -1,12 +1,11 @@ - -namespace Demo.Data.RemoteData.RemoteDataBase.DAO { - - public class PresenceDao { - - public Guid UserGuid { get; set; } - public bool IsAttedance { get; set; } - public DateOnly Date { get; set; } - public int LessonNumber { get; set; } - public UserDao userDao { get; set; } +namespace Demo.Data.RemoteData.RemoteDataBase.DAO +{ + public class PresenceDAO + { + public Guid UserGuid {get; set; } + public bool IsAttedance {get; set; } + public DateOnly Date {get; set; } + public int LessonNumber {get; set; } + public UserDAO userDAO {get; set; } } } \ No newline at end of file diff --git a/Data/RemoteData/RemoteDataBase/DAO/User.cs b/Data/RemoteData/RemoteDataBase/DAO/User.cs index b636c33..5c042d2 100644 --- a/Data/RemoteData/RemoteDataBase/DAO/User.cs +++ b/Data/RemoteData/RemoteDataBase/DAO/User.cs @@ -2,11 +2,11 @@ using System.Text.RegularExpressions; namespace Demo.Data.RemoteData.RemoteDataBase.DAO { - public class UserDao + public class UserDAO { - public string FIO { get; set; } + public string FIO { get; set; } public Guid Guid {get; set; } public int GroupID {get; set;} - public GroupDao Group {get; set; } + public GroupDAO Group {get; set; } } } \ No newline at end of file diff --git a/Data/RemoteData/RemoteDataBase/RemoteDatabaseContext.cs b/Data/RemoteData/RemoteDataBase/RemoteDatabaseContext.cs index 438762c..b043a5e 100644 --- a/Data/RemoteData/RemoteDataBase/RemoteDatabaseContext.cs +++ b/Data/RemoteData/RemoteDataBase/RemoteDatabaseContext.cs @@ -1,33 +1,28 @@ using Demo.Data.RemoteData.RemoteDataBase.DAO; using Microsoft.EntityFrameworkCore; -namespace Data.RemoteData.RemoteDataBase.DAO +namespace Demo.Data.RemoteData.RemoteDataBase { - - public class RemoteDatabaseContext: DbContext { - - public DbSet Groups { get; set; } - public DbSet Users { get; set; } - public DbSet PresenceDaos { get; set; } + public class RemoteDatabaseContext: DbContext + { + public DbSet Groups {get; set; } + public DbSet Users {get; set;} + public DbSet PresenceDaos{get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseNpgsql("Host=localhost;" + - "Port=5432;" + - "Username=postgres;" + - "Password=1234;" + - "Database=postgres"); + optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Username=myuser;Password=mypassword;Database=mydatabase"); } - protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().HasKey(group => group.Id); - modelBuilder.Entity().Property(group => group.Id).ValueGeneratedOnAdd(); - modelBuilder.Entity().HasKey(user => user.Guid); - modelBuilder.Entity().Property(user => user.Guid).ValueGeneratedOnAdd(); - modelBuilder.Entity().HasKey(presence => new { + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasKey(group => group.ID); + modelBuilder.Entity().Property(group => group.ID).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(user => user.Guid); + modelBuilder.Entity().Property(user => user.Guid).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(presence => new { presence.UserGuid, presence.Date, - presence.IsAttedance, presence.LessonNumber }); } diff --git a/Data/Repository/GroupRepositoryImpl.cs b/Data/Repository/GroupRepositoryImpl.cs index b71de89..d1a9d4b 100644 --- a/Data/Repository/GroupRepositoryImpl.cs +++ b/Data/Repository/GroupRepositoryImpl.cs @@ -1,64 +1,55 @@ +using Demo.Domain.Models; using Demo.Data.LocalData; -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Data.RemoteData.RemoteDataBase.DAO; +using Demo.Data.RemoteData.RemoteDataBase; using Demo.Data.RemoteData.RemoteDataBase.DAO; namespace Demo.Data.Repository { public class SQLGroupRepositoryImpl : IGroupRepository { - private readonly RemoteDatabaseContext _remoteDatabaseContext; - public SQLGroupRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) { - + public SQLGroupRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext){ _remoteDatabaseContext = remoteDatabaseContext; - GetAllGroups = _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, Id = x.Id}).ToList(); + GetAllGroups = _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, ID = x.ID}).ToList(); } + public List GetAllGroups { get; set; } public List GetAllGroup() { - return _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, Id = x.Id}).ToList(); + return _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, ID = x.ID}).ToList(); } - public GroupLocalEntity? UpdateGroupName(GroupLocalEntity groupUpdateLocalEntity) { + public GroupLocalEntity? GetGroupById(int ID){ + var groupDAO = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.ID == ID); + return new GroupLocalEntity{Name = groupDAO.Name, ID = groupDAO.ID}; + } - var group = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupUpdateLocalEntity.Id); + public GroupLocalEntity? CreateGroup(string Name) { + GroupDAO groupDAO = new GroupDAO{Name = Name}; + var result = _remoteDatabaseContext.Groups.Add(groupDAO); + _remoteDatabaseContext.SaveChanges(); + return new GroupLocalEntity{Name = groupDAO.Name, ID = groupDAO.ID}; + } + + public GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup){ + var group = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.ID == updatedGroup.ID); if (group == null){ return null; } - group.Name = groupUpdateLocalEntity.Name; + group.Name = updatedGroup.Name; _remoteDatabaseContext.SaveChanges(); - return new GroupLocalEntity{Name = group.Name, Id = group.Id}; + return new GroupLocalEntity{Name = group.Name, ID = group.ID}; } - public GroupLocalEntity? CreateGroup(string Name) { - - GroupDao groupDAO = new GroupDao{Name = Name}; - var result = _remoteDatabaseContext.Groups.Add(groupDAO); - _remoteDatabaseContext.SaveChanges(); - return new GroupLocalEntity{Name = groupDAO.Name, Id = groupDAO.Id}; - } - - public bool RemoveGroupById(int groupID) - { - var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupID); - _remoteDatabaseContext.Groups.Remove(groupDao); + public bool RemoveGroupByID(int ID){ + var groupDAO = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.ID == ID); + _remoteDatabaseContext.Groups.Remove(groupDAO); _remoteDatabaseContext.SaveChanges(); return true; } - - public GroupLocalEntity? GetGroupById(int groupId) { - var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupId); - return new GroupLocalEntity{Name = groupDao.Name, Id = groupDao.Id}; - } } -} +} \ No newline at end of file diff --git a/Data/Repository/IGroupRepository.cs b/Data/Repository/IGroupRepository.cs index 0ba2c67..b48d1da 100644 --- a/Data/Repository/IGroupRepository.cs +++ b/Data/Repository/IGroupRepository.cs @@ -1,18 +1,13 @@ -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Demo.Domain.Models; namespace Demo.Data.Repository { public interface IGroupRepository { List GetAllGroup(); - bool RemoveGroupById(int groupID); - GroupLocalEntity? UpdateGroupName(GroupLocalEntity updatedGroup); - GroupLocalEntity? GetGroupById(int groupID); + GroupLocalEntity? GetGroupById(int ID); + bool RemoveGroupByID(int groupId); + GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup); GroupLocalEntity? CreateGroup(string Name); } } \ No newline at end of file diff --git a/Data/Repository/IPresenceRepository.cs b/Data/Repository/IPresenceRepository.cs index fd187d2..bce6080 100644 --- a/Data/Repository/IPresenceRepository.cs +++ b/Data/Repository/IPresenceRepository.cs @@ -1,13 +1,11 @@ -using Demo.domain.Models; +using Demo.Domain.Models; namespace Demo.Data.Repository { public interface IPresenceRepository { - List GetPresences(); - List GetPresencesByGroup(); - List GetPresencesByGroupAndDate(); + List GetAllPresences(); + void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid); List GeneratePresence(List presenceLocalEntities); - void UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid); } } \ No newline at end of file diff --git a/Data/Repository/IUserRepository.cs b/Data/Repository/IUserRepository.cs index 9560b00..a57dd9d 100644 --- a/Data/Repository/IUserRepository.cs +++ b/Data/Repository/IUserRepository.cs @@ -1,17 +1,12 @@ -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Demo.Domain.Models; namespace Demo.Data.Repository { public interface IUserRepository { List GetAllUser(); - bool RemoveUserByGuid(Guid userGuid); - UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEntity); - UserLocalEntity? GetUserByGuid(Guid userGuid); + UserLocalEntity? GetUserByGuid(Guid guid); + bool RemoveUserByGuid(Guid guid); + UserLocalEntity? UpdateUser(UserLocalEntity updatedUser); } } \ No newline at end of file diff --git a/Data/Repository/PresenceRepositoryImpl.cs b/Data/Repository/PresenceRepositoryImpl.cs index 7690638..1b00299 100644 --- a/Data/Repository/PresenceRepositoryImpl.cs +++ b/Data/Repository/PresenceRepositoryImpl.cs @@ -1,45 +1,33 @@ -using Data.RemoteData.RemoteDataBase.DAO; +using Demo.Data.LocalData; +using Demo.Data.RemoteData.RemoteDataBase; using Demo.Data.RemoteData.RemoteDataBase.DAO; -using Demo.domain.Models; +using Demo.Domain.Models; namespace Demo.Data.Repository { public class SQLPresenceRepositoryImpl : IPresenceRepository { - private readonly RemoteDatabaseContext _remoteDatabaseContext; public SQLPresenceRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext){ _remoteDatabaseContext = remoteDatabaseContext; GetAllPresence = _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList(); } - public List GetAllPresence = new List{}; - public List GetPresences() - { - return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList(); - } - - public List GetPresencesByGroup() - { - return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList(); - } - - public List GetPresencesByGroupAndDate() - { + public List GetAllPresences(){ return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList(); } public List GeneratePresence(List presenceLocalEntities) { - var presences = presenceLocalEntities.Select(x => new PresenceDao + var presences = presenceLocalEntities.Select(x => new PresenceDAO { UserGuid = x.UserGuid, IsAttedance = x.IsAttedance, LessonNumber = x.LessonNumber, Date = x.Date, - userDao = _remoteDatabaseContext.Users.FirstOrDefault(u => u.Guid == x.UserGuid) + userDAO = _remoteDatabaseContext.Users.FirstOrDefault(u => u.Guid == x.UserGuid) }).ToList(); _remoteDatabaseContext.PresenceDaos.AddRange(presences); @@ -48,7 +36,7 @@ namespace Demo.Data.Repository return presenceLocalEntities; } - public void UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ + public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ var presencesToUpdate = _remoteDatabaseContext.PresenceDaos .Where(x => x.LessonNumber >= firstLesson && x.LessonNumber <= lastLesson @@ -62,5 +50,6 @@ namespace Demo.Data.Repository _remoteDatabaseContext.SaveChanges(); } + } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Data/Repository/UserRepositoryImpl.cs b/Data/Repository/UserRepositoryImpl.cs index 2e7a302..ea4090c 100644 --- a/Data/Repository/UserRepositoryImpl.cs +++ b/Data/Repository/UserRepositoryImpl.cs @@ -1,52 +1,45 @@ -using Data.RemoteData.RemoteDataBase.DAO; +using Demo.Domain.Models; using Demo.Data.LocalData; -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Demo.Data.RemoteData.RemoteDataBase; namespace Demo.Data.Repository { - public class SQLUserRepositoryImpl:IUserRepository + public class SQLUserRepositoryImpl : IUserRepository { - private readonly RemoteDatabaseContext _remoteDatabaseContext; - - public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) { + + public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext){ _remoteDatabaseContext = remoteDatabaseContext; GetAllUsers = _remoteDatabaseContext.Users.Select(x => new UserLocalEntity{FIO = x.FIO, Guid = x.Guid, GroupID = x.GroupID}).ToList(); } + public List GetAllUsers { get; set; } - public List GetAllUser() - { + public List GetAllUser(){ return _remoteDatabaseContext.Users.Select(x => new UserLocalEntity{FIO = x.FIO, Guid = x.Guid, GroupID = x.GroupID}).ToList(); } - public bool RemoveUserByGuid(Guid userGuid) - { - var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid); + public UserLocalEntity? GetUserByGuid(Guid guid){ + var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == guid); + return new UserLocalEntity{FIO = userDAO.FIO, GroupID = userDAO.GroupID, Guid = guid}; + } + + public bool RemoveUserByGuid(Guid guid){ + var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == guid); _remoteDatabaseContext.Users.Remove(userDAO); _remoteDatabaseContext.SaveChanges(); return true; } - public UserLocalEntity? GetUserByGuid(Guid userGuid) { - var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid); - return new UserLocalEntity{FIO = userDAO.FIO, GroupID = userDAO.GroupID, Guid = userGuid}; - } - - public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEntity) { - var user = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userUpdateLocalEntity.Guid); + public UserLocalEntity? UpdateUser(UserLocalEntity updatedUser){ + var user = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == updatedUser.Guid); if (user == null){ return null; } - user.FIO = userUpdateLocalEntity.FIO; - user.GroupID = userUpdateLocalEntity.GroupID; + user.FIO = updatedUser.FIO; + user.GroupID = updatedUser.GroupID; _remoteDatabaseContext.SaveChanges(); return new UserLocalEntity{FIO = user.FIO, Guid = user.Guid, GroupID = user.GroupID}; } diff --git a/Domain/Models/Group.cs b/Domain/Models/Group.cs index 29c2f56..ef15cfd 100644 --- a/Domain/Models/Group.cs +++ b/Domain/Models/Group.cs @@ -1,19 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Demo.domain.Models +namespace Demo.Domain.Models { public class Group { - public required int Id { get; set; } - public required string Name { get; set; } + public required int ID{get; set; } + public required string Name{get; set; } public static Group Parse(string input){ string[] words = input.Split(" "); - return new Group{Id = Convert.ToInt32(words[0]), Name = words[1]}; + return new Group{ID = Convert.ToInt32(words[0]), Name = words[1]}; } } } \ No newline at end of file diff --git a/Domain/Models/Presence.cs b/Domain/Models/Presence.cs index f4a7fd8..8fddb96 100644 --- a/Domain/Models/Presence.cs +++ b/Domain/Models/Presence.cs @@ -1,15 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Demo.domain.Models +namespace Demo.Domain.Models { public class Presence { - - public required User User { get; set; } + public required User User{get; set; } public bool IsAttedance { get; set; } = true; public required DateOnly Date { get; set; } diff --git a/Domain/Models/User.cs b/Domain/Models/User.cs index aaaa75c..d1f6626 100644 --- a/Domain/Models/User.cs +++ b/Domain/Models/User.cs @@ -1,22 +1,38 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Demo.domain.Models +namespace Demo.Domain.Models { public class User { - public required string FIO { get; set; } - public Guid Guid { get; set; } + public required string FIO{get; set; } + public Guid Guid{get; set; } + public required Group Group{get; set; } - public required Group Group { get; set; } - - - public static User Parse(string input){ + public static User Parse(string input) + { string[] words = input.Split(" "); - return new User{FIO = words[0], Guid = Guid.Parse(words[1]), Group = new Group{Id = Convert.ToInt32(words[2]), Name = words[3]}}; + + if (words.Length < 4) + { + throw new FormatException("Input string does not have the expected number of elements."); + } + + try + { + return new User + { + FIO = words[0], + Guid = Guid.Parse(words[1]), + Group = new Group + { + ID = Convert.ToInt32(words[2]), + Name = words[3] + } + }; + } + catch (FormatException ex) + { + Console.WriteLine("Error parsing input: " + ex.Message); + throw; + } } } } \ No newline at end of file diff --git a/Domain/UseCase/GroupUseCase.cs b/Domain/UseCase/GroupUseCase.cs index 9a50619..e6aca77 100644 --- a/Domain/UseCase/GroupUseCase.cs +++ b/Domain/UseCase/GroupUseCase.cs @@ -1,62 +1,54 @@ +using Demo.Domain.Models; using Demo.Data.Repository; -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Demo.Domain.UseCase { - public class GroupUseCase:IGroupUseCase + public class GroupUseCase : IGroupUseCase { - + private readonly IUserRepository _repositoryUserImpl; private readonly IGroupRepository _repositoryGroupImpl; - - public GroupUseCase(IGroupRepository groupRepository, IUserRepository repositoryUserImpl) + public GroupUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl) { - _repositoryGroupImpl = groupRepository; + _repositoryGroupImpl = repositoryGroupImpl; + _repositoryUserImpl = repositoryUserImpl; } public List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() - .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); - - public Group UpdateGroupName(Group group) { - - GroupLocalEntity groupLocalEntity = new GroupLocalEntity - { - Id = group.Id, - Name = group.Name - }; - GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroupName(groupLocalEntity); - if (result == null) - { - throw new Exception(""); - } - return new Group - { - Id = result.Id, - Name = result.Name - }; + .Select(it => new Group{ID = it.ID, Name = it.Name}).ToList(); + public Group GetGroupById(int groupID) + { + GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupID); + if (groupLocalEntity == null) throw new Exception("bello"); + return new Group{ID = groupID, Name = groupLocalEntity.Name}; } - public bool RemoveGroupById(int groupId) { - - return _repositoryGroupImpl.RemoveGroupById(groupId); - } - - public bool CreateGroup(string Name) { - + public bool CreateGroup(string Name){ _repositoryGroupImpl.CreateGroup(Name); return true; } - public Group GetGroupById(int groupId) { + public Group UpdateGroup(Group group) + { + GroupLocalEntity groupLocalEntity = new GroupLocalEntity + { + ID = group.ID, + Name = group.Name + }; + GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity); + if (result == null) + { + throw new Exception("Не удалось обновить пользователя: пользователь не найден."); + } + return new Group + { + ID = result.ID, + Name = result.Name + }; + } - GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupId); - if (groupLocalEntity == null) throw new Exception("bello"); - return new Group{Id = groupId, Name = groupLocalEntity.Name}; + public bool RemoveGroupByID(int userID) { + return _repositoryGroupImpl.RemoveGroupByID(userID); } } -} +} \ No newline at end of file diff --git a/Domain/UseCase/IGroupUseCase.cs b/Domain/UseCase/IGroupUseCase.cs index 2f086f1..c6d2d49 100644 --- a/Domain/UseCase/IGroupUseCase.cs +++ b/Domain/UseCase/IGroupUseCase.cs @@ -1,17 +1,12 @@ -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Demo.Domain.Models; namespace Demo.Domain.UseCase { public interface IGroupUseCase { List GetAllGroups(); - bool RemoveGroupById(int groupId); - Group UpdateGroupName(Group group); + bool RemoveGroupByID(int groupID); + Group UpdateGroup(Group group); Group GetGroupById(int groupID); bool CreateGroup(string Name); } diff --git a/Domain/UseCase/IPresenceUseCase.cs b/Domain/UseCase/IPresenceUseCase.cs index 79dae8f..f8c1c66 100644 --- a/Domain/UseCase/IPresenceUseCase.cs +++ b/Domain/UseCase/IPresenceUseCase.cs @@ -1,13 +1,13 @@ -using Demo.domain.Models; +using Demo.Domain.Models; namespace Demo.Domain.UseCase { public interface IPresenceUseCase { - List GetPresencesByGroup(int groupId); - List GetPresencesByGroupAndDate(int groupId, DateOnly date); - bool UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid); - bool GeneratePresence(int firstLesson, int lastLesson, int groupId, DateOnly date); - bool GenerateWeekPresence(int firstLesson, int lastLesson, int groupId, DateOnly date); + List GetPresenceByGroup(int groupID); + List GetPresenceByGroupByTime(int groupID, DateOnly date); + bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid); + bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date); + bool GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date); } } \ No newline at end of file diff --git a/Domain/UseCase/IUserUseCase.cs b/Domain/UseCase/IUserUseCase.cs index 6dd57e1..98f2b15 100644 --- a/Domain/UseCase/IUserUseCase.cs +++ b/Domain/UseCase/IUserUseCase.cs @@ -1,18 +1,12 @@ -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Demo.Domain.Models; namespace Demo.Domain.UseCase { public interface IUserUseCase { - List GetAllGroups(); List GetAllUsers(); - User GetUserByGuid(Guid userGuid); bool RemoveUserByGuid(Guid userGuid); User UpdateUser(User user); + User GetUserByGuid(Guid userGuid); } } \ No newline at end of file diff --git a/Domain/UseCase/PresenceUseCase.cs b/Domain/UseCase/PresenceUseCase.cs index b9d2044..847cd05 100644 --- a/Domain/UseCase/PresenceUseCase.cs +++ b/Domain/UseCase/PresenceUseCase.cs @@ -1,34 +1,57 @@ +using System.Security.Cryptography.X509Certificates; using Demo.Data.Repository; -using Demo.domain.Models; +using Demo.Domain.Models; namespace Demo.Domain.UseCase { public class PresenceUseCase : IPresenceUseCase { - private readonly IUserRepository _repositoryUserImpl; + private readonly IUserRepository _repositoryUserImpl; private readonly IPresenceRepository _repositoryPresenceImpl; private readonly IGroupRepository _repositoryGroupImpl; - public PresenceUseCase(IPresenceRepository presenceRepository, IUserRepository repositoryUserImpl, IGroupRepository repositoryGroupImpl) + public PresenceUseCase(IPresenceRepository repositoryPresenceImpl, IUserRepository repositoryUserImpl, IGroupRepository repositoryGroupImpl) { - _repositoryPresenceImpl = presenceRepository; - _repositoryGroupImpl = repositoryGroupImpl; + _repositoryPresenceImpl = repositoryPresenceImpl; _repositoryUserImpl = repositoryUserImpl; + _repositoryGroupImpl = repositoryGroupImpl; } - public List GetPresencesByGroup(int groupId) - { + public List GetPresenceByGroup(int groupID){ var usersByGroup = _repositoryUserImpl.GetAllUser() - .Where(user => user.GroupID == groupId).ToList(); + .Where(user => user.GroupID == groupID).ToList(); - var presenceByGroup = _repositoryPresenceImpl.GetPresencesByGroup() + var presenceByGroup = _repositoryPresenceImpl.GetAllPresences() .Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid)) .Select(presence => new Presence{ User = new User{ Guid = presence.UserGuid, Group = new Group{ - Id = groupId, - Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name + ID = groupID, + Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name + }, + FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO, + }, + LessonNumber = presence.LessonNumber, + Date = presence.Date, + IsAttedance = presence.IsAttedance + }).ToList(); + + return presenceByGroup; + } + + public List GetPresenceByGroupByTime(int groupID, DateOnly date){ + var usersByGroup = _repositoryUserImpl.GetAllUser() + .Where(user => user.GroupID == groupID).ToList(); + + var presenceByGroup = _repositoryPresenceImpl.GetAllPresences() + .Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid && x.Date == date)) + .Select(presence => new Presence{ + User = new User{ + Guid = presence.UserGuid, + Group = new Group{ + ID = groupID, + Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name }, FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO, }, @@ -40,56 +63,43 @@ namespace Demo.Domain.UseCase return presenceByGroup; } - public List GetPresencesByGroupAndDate(int groupId, DateOnly date) - { - var usersByGroup = _repositoryUserImpl.GetAllUser() - .Where(user => user.GroupID == groupId).ToList(); - - var presenceByGroupAndDate = _repositoryPresenceImpl.GetPresencesByGroup() - .Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid && x.Date == date)) - .Select(presence => new Presence{ - User = new User{ - Guid = presence.UserGuid, - Group = new Group{ - Id = groupId, - Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name - }, - FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO, - }, - LessonNumber = presence.LessonNumber, - Date = presence.Date, - IsAttedance = presence.IsAttedance - }).ToList(); - - return presenceByGroupAndDate; - } - - public bool UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ - _repositoryPresenceImpl.UpdateAttedance(firstLesson, lastLesson, date, UserGuid); + public bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ + _repositoryPresenceImpl.IsAttedance(firstLesson, lastLesson, date, UserGuid); return true; } - public bool GeneratePresence(int firstLesson, int lastLesson, int groupId, DateOnly date){ - List presenceList = new List{}; - var usersByGroup = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupId); - for (int i = firstLesson; i <= lastLesson; i++){ - foreach(UserLocalEntity user in usersByGroup){ - presenceList.Add(new Presence{ - User = new User{ - Group = new Group{ - Id = groupId, - Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name + public bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date) + { + var usersByGroup = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupID).ToList(); + var groupName = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name; + + List presenceList = new List(); + + for (int i = firstLesson; i <= lastLesson; i++) + { + foreach (UserLocalEntity user in usersByGroup) + { + presenceList.Add(new Presence + { + User = new User + { + Group = new Group + { + ID = groupID, + Name = groupName + }, + FIO = user.FIO, + Guid = user.Guid }, - FIO = usersByGroup.First(user2 => user2.Guid == user.Guid).FIO, - Guid = user.Guid - }, - IsAttedance = true, - Date = date, - LessonNumber = i}); + IsAttedance = true, + Date = date, + LessonNumber = i + }); } } - var presenceLocalEntity = presenceList.Select(x => new PresenceLocalEntity{ + var presenceLocalEntity = presenceList.Select(x => new PresenceLocalEntity + { UserGuid = x.User.Guid, IsAttedance = x.IsAttedance, LessonNumber = x.LessonNumber, @@ -101,9 +111,9 @@ namespace Demo.Domain.UseCase return true; } - public bool GenerateWeekPresence(int firstLesson, int lastLesson, int groupId, DateOnly date){ + public bool GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){ for (int i = 0; i < 8; i++){ - GeneratePresence(firstLesson, lastLesson, groupId, date.AddDays(i)); + GeneratePresence(firstLesson, lastLesson, groupID, date.AddDays(i)); } return true; } diff --git a/Domain/UseCase/UserUseCase.cs b/Domain/UseCase/UserUseCase.cs index 182fae5..86da31a 100644 --- a/Domain/UseCase/UserUseCase.cs +++ b/Domain/UseCase/UserUseCase.cs @@ -1,73 +1,70 @@ +using Demo.Domain.Models; using Demo.Data.Repository; -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Demo.Domain.UseCase { public class UserUseCase : IUserUseCase { - private readonly IUserRepository _repositoryUserImpl; - private readonly IGroupRepository _repositoryGroupImpl; + private readonly IUserRepository _repositoryUserImpl; + private readonly IGroupRepository _repositoryGroupImpl; - public UserUseCase(IUserRepository userRepository, IGroupRepository groupRepository) + public UserUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl) { - _repositoryUserImpl = userRepository; - _repositoryGroupImpl = groupRepository; + _repositoryGroupImpl = repositoryGroupImpl; + _repositoryUserImpl = repositoryUserImpl; } public List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() - .Select(it => new Group{Id = it.Id, Name = it.Name}).ToList(); + .Select(it => new Group{ID = it.ID, Name = it.Name}).ToList(); public List GetAllUsers() => _repositoryUserImpl.GetAllUser() .Join(_repositoryGroupImpl.GetAllGroup(), user => user.GroupID, - group => group.Id, + group => group.ID, (user, group) => new User{ FIO = user.FIO, Guid = user.Guid, Group = new Group{ - Id = group.Id, + ID = group.ID, Name = group.Name} } ).ToList(); - public User GetUserByGuid(Guid userGuid) { + public User GetUserByGuid(Guid userGuid){ UserLocalEntity? userLocalEntity = _repositoryUserImpl.GetUserByGuid(userGuid); if (userLocalEntity == null) throw new Exception("bello"); - Group? group = GetAllGroups().FirstOrDefault(it => userLocalEntity.GroupID == it.Id); + Group? group = GetAllGroups().FirstOrDefault(it => userLocalEntity.GroupID == it.ID); if (group == null) throw new Exception("bello"); return new User{ FIO = userLocalEntity.FIO, Guid = userLocalEntity.Guid, Group = new Group{ - Id = group.Id, + ID = group.ID, Name = group.Name} - }; + }; } public bool RemoveUserByGuid(Guid userGuid) { - return _repositoryUserImpl.RemoveUserByGuid(userGuid); + return _repositoryUserImpl.RemoveUserByGuid(userGuid); } - public User UpdateUser(User user) { + + public User UpdateUser(User user) + { UserLocalEntity userLocalEntity = new UserLocalEntity { FIO = user.FIO, Guid = user.Guid, - GroupID = user.Group.Id + GroupID = user.Group.ID }; UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEntity); if (result == null) { - throw new Exception(""); + throw new Exception("Не удалось обновить пользователя: пользователь не найден."); } - Group? group = GetAllGroups().FirstOrDefault(it => result.GroupID == it.Id); + Group? group = GetAllGroups().FirstOrDefault(it => result.GroupID == it.ID); if (group == null) { - throw new Exception(""); + throw new Exception("Не удалось обновить пользователя: группа не найдена."); } return new User { @@ -75,6 +72,6 @@ namespace Demo.Domain.UseCase Guid = result.Guid, Group = group }; - } + } } } \ No newline at end of file diff --git a/Migrations/20241024202926_InitialCreate.Designer.cs b/Migrations/20241028031712_InitialCreate.Designer.cs similarity index 80% rename from Migrations/20241024202926_InitialCreate.Designer.cs rename to Migrations/20241028031712_InitialCreate.Designer.cs index 36f45d2..4edcf56 100644 --- a/Migrations/20241024202926_InitialCreate.Designer.cs +++ b/Migrations/20241028031712_InitialCreate.Designer.cs @@ -1,6 +1,6 @@ // using System; -using Data.RemoteData.RemoteDataBase.DAO; +using Demo.Data.RemoteData.RemoteDataBase; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace Demo.Migrations { [DbContext(typeof(RemoteDatabaseContext))] - [Migration("20241024202926_InitialCreate")] + [Migration("20241028031712_InitialCreate")] partial class InitialCreate { /// @@ -25,24 +25,24 @@ namespace Demo.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b => { - b.Property("Id") + b.Property("ID") .ValueGeneratedOnAdd() .HasColumnType("integer"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); b.Property("Name") .IsRequired() .HasColumnType("text"); - b.HasKey("Id"); + b.HasKey("ID"); b.ToTable("Groups"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b => { b.Property("UserGuid") .HasColumnType("uuid"); @@ -50,23 +50,23 @@ namespace Demo.Migrations b.Property("Date") .HasColumnType("date"); - b.Property("IsAttedance") - .HasColumnType("boolean"); - b.Property("LessonNumber") .HasColumnType("integer"); - b.Property("userDaoGuid") + b.Property("IsAttedance") + .HasColumnType("boolean"); + + b.Property("userDAOGuid") .HasColumnType("uuid"); - b.HasKey("UserGuid", "Date", "IsAttedance", "LessonNumber"); + b.HasKey("UserGuid", "Date", "LessonNumber"); - b.HasIndex("userDaoGuid"); + b.HasIndex("userDAOGuid"); b.ToTable("PresenceDaos"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b => { b.Property("Guid") .ValueGeneratedOnAdd() @@ -86,21 +86,21 @@ namespace Demo.Migrations b.ToTable("Users"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b => { - b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", "userDao") + b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", "userDAO") .WithMany() - .HasForeignKey("userDaoGuid") + .HasForeignKey("userDAOGuid") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("userDao"); + b.Navigation("userDAO"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b => { - b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", "Group") - .WithMany("User") + b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", "Group") + .WithMany("Users") .HasForeignKey("GroupID") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -108,9 +108,9 @@ namespace Demo.Migrations b.Navigation("Group"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b => { - b.Navigation("User"); + b.Navigation("Users"); }); #pragma warning restore 612, 618 } diff --git a/Migrations/20241024202926_InitialCreate.cs b/Migrations/20241028031712_InitialCreate.cs similarity index 85% rename from Migrations/20241024202926_InitialCreate.cs rename to Migrations/20241028031712_InitialCreate.cs index 0690743..b76e162 100644 --- a/Migrations/20241024202926_InitialCreate.cs +++ b/Migrations/20241028031712_InitialCreate.cs @@ -16,13 +16,13 @@ namespace Demo.Migrations name: "Groups", columns: table => new { - Id = table.Column(type: "integer", nullable: false) + ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Groups", x => x.Id); + table.PrimaryKey("PK_Groups", x => x.ID); }); migrationBuilder.CreateTable( @@ -40,7 +40,7 @@ namespace Demo.Migrations name: "FK_Users_Groups_GroupID", column: x => x.GroupID, principalTable: "Groups", - principalColumn: "Id", + principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); @@ -49,26 +49,26 @@ namespace Demo.Migrations columns: table => new { UserGuid = table.Column(type: "uuid", nullable: false), - IsAttedance = table.Column(type: "boolean", nullable: false), Date = table.Column(type: "date", nullable: false), LessonNumber = table.Column(type: "integer", nullable: false), - userDaoGuid = table.Column(type: "uuid", nullable: false) + IsAttedance = table.Column(type: "boolean", nullable: false), + userDAOGuid = table.Column(type: "uuid", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_PresenceDaos", x => new { x.UserGuid, x.Date, x.IsAttedance, x.LessonNumber }); + table.PrimaryKey("PK_PresenceDaos", x => new { x.UserGuid, x.Date, x.LessonNumber }); table.ForeignKey( - name: "FK_PresenceDaos_Users_userDaoGuid", - column: x => x.userDaoGuid, + name: "FK_PresenceDaos_Users_userDAOGuid", + column: x => x.userDAOGuid, principalTable: "Users", principalColumn: "Guid", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( - name: "IX_PresenceDaos_userDaoGuid", + name: "IX_PresenceDaos_userDAOGuid", table: "PresenceDaos", - column: "userDaoGuid"); + column: "userDAOGuid"); migrationBuilder.CreateIndex( name: "IX_Users_GroupID", diff --git a/Migrations/RemoteDatabaseContextModelSnapshot.cs b/Migrations/RemoteDatabaseContextModelSnapshot.cs index 9a23270..4d73666 100644 --- a/Migrations/RemoteDatabaseContextModelSnapshot.cs +++ b/Migrations/RemoteDatabaseContextModelSnapshot.cs @@ -1,6 +1,6 @@ // using System; -using Data.RemoteData.RemoteDataBase.DAO; +using Demo.Data.RemoteData.RemoteDataBase; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -22,24 +22,24 @@ namespace Demo.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b => { - b.Property("Id") + b.Property("ID") .ValueGeneratedOnAdd() .HasColumnType("integer"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); b.Property("Name") .IsRequired() .HasColumnType("text"); - b.HasKey("Id"); + b.HasKey("ID"); b.ToTable("Groups"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b => { b.Property("UserGuid") .HasColumnType("uuid"); @@ -47,23 +47,23 @@ namespace Demo.Migrations b.Property("Date") .HasColumnType("date"); - b.Property("IsAttedance") - .HasColumnType("boolean"); - b.Property("LessonNumber") .HasColumnType("integer"); - b.Property("userDaoGuid") + b.Property("IsAttedance") + .HasColumnType("boolean"); + + b.Property("userDAOGuid") .HasColumnType("uuid"); - b.HasKey("UserGuid", "Date", "IsAttedance", "LessonNumber"); + b.HasKey("UserGuid", "Date", "LessonNumber"); - b.HasIndex("userDaoGuid"); + b.HasIndex("userDAOGuid"); b.ToTable("PresenceDaos"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b => { b.Property("Guid") .ValueGeneratedOnAdd() @@ -83,21 +83,21 @@ namespace Demo.Migrations b.ToTable("Users"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b => { - b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", "userDao") + b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", "userDAO") .WithMany() - .HasForeignKey("userDaoGuid") + .HasForeignKey("userDAOGuid") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("userDao"); + b.Navigation("userDAO"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b => { - b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", "Group") - .WithMany("User") + b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", "Group") + .WithMany("Users") .HasForeignKey("GroupID") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -105,9 +105,9 @@ namespace Demo.Migrations b.Navigation("Group"); }); - modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b => + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b => { - b.Navigation("User"); + b.Navigation("Users"); }); #pragma warning restore 612, 618 } diff --git a/Program.cs b/Program.cs index 023de35..e72e659 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,4 @@ - -using Data.RemoteData.RemoteDataBase.DAO; +using Demo.Data.RemoteData.RemoteDataBase; using Demo.Data.Repository; using Demo.Domain.UseCase; using Demo.UI; @@ -7,7 +6,8 @@ using Microsoft.Extensions.DependencyInjection; IServiceCollection services = new ServiceCollection(); -services + services + .AddDbContext() .AddSingleton() .AddSingleton() @@ -18,6 +18,6 @@ services .AddSingleton() .AddSingleton(); -var serviceProvider = services.BuildServiceProvider(); + var serviceProvider = services.BuildServiceProvider(); -MainMenuUI? mainMenuUI = serviceProvider.GetService(); + MainMenuUI? mainMenuUI = serviceProvider.GetService(); diff --git a/UI/GroupConsole.cs b/UI/GroupConsole.cs deleted file mode 100644 index e0acab9..0000000 --- a/UI/GroupConsole.cs +++ /dev/null @@ -1,60 +0,0 @@ -using Demo.Domain.UseCase; -using Demo.domain.Models; -using System.Text; - - -namespace Demo.UI -{ - public class GroupConsoleUI - { - IGroupUseCase _groupUseCase; - - public GroupConsoleUI(IGroupUseCase groupUseCase) { - _groupUseCase = groupUseCase; - } - - public void UpdateGroupName(Group group) - { - try - { - Group output = _groupUseCase.UpdateGroupName(group); - StringBuilder groupOutput = new StringBuilder(); - groupOutput.AppendLine($"Обновленная группа: {output.Id}\t{output.Name}"); - Console.WriteLine(groupOutput); - } - catch (Exception ex) - { - Console.WriteLine($"Ошибка при обновлении группы: {ex.Message}"); - } - } - - public void CreateNewGroup(string Name){ - string output = _groupUseCase.CreateGroup(Name) ? "Группа создана" : "Группа не создана"; - Console.WriteLine(output); - } - - 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 RemoveGroupById(int ID){ - string output = _groupUseCase.RemoveGroupById(ID) ? "Группа удалена" : "Группа не удалена"; - Console.WriteLine(output); - } - - public void DisplayGroupByID(int ID){ - StringBuilder userOutput = new StringBuilder(); - var group = _groupUseCase.GetGroupById(ID); - { - userOutput.AppendLine($"{group.Id}\t{group.Name}"); - } - Console.WriteLine(userOutput); - } - } -} diff --git a/UI/MainMenu.cs b/UI/MainMenu.cs index cc86ec8..f12b713 100644 --- a/UI/MainMenu.cs +++ b/UI/MainMenu.cs @@ -1,16 +1,11 @@ +using Demo.Domain.Models; using Demo.Domain.UseCase; -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Demo.UI { public class MainMenuUI { - + UserConsoleUI _userConsoleUI; GroupConsoleUI _groupConsoleUI; PresenceConsoleUI _presenceConsoleUI; @@ -28,29 +23,28 @@ namespace Demo.UI { switch (Console.ReadLine()) { + case "1": _groupConsoleUI.DisplayAllGroups(); break; + case "2": _groupConsoleUI.CreateNewGroup(Console.ReadLine()); break; + case "3": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break; + case "4": _groupConsoleUI.DisplayGroupByID(Convert.ToInt32(Console.ReadLine())); break; + case "5": _groupConsoleUI.RemoveGroupByID(Convert.ToInt32(Console.ReadLine())); break; - case "1": _userConsoleUI.DisplayAllUsers(); break; - case "2": _userConsoleUI.GetUserByGuid(Guid.Parse(Console.ReadLine())); break; - case "3": _userConsoleUI.UpdateUser(User.Parse(Console.ReadLine())); break; - case "4": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; - - case "5": _groupConsoleUI.DisplayAllGroups(); break; - case "6": _groupConsoleUI.CreateNewGroup(Console.ReadLine()); break; - case "7": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break; - case "8": _groupConsoleUI.DisplayGroupByID(Convert.ToInt32(Console.ReadLine())); break; - case "9": _groupConsoleUI.RemoveGroupById(Convert.ToInt32(Console.ReadLine())); break; + case "6": _userConsoleUI.DisplayAllUsers(); break; + case "7": _userConsoleUI.DisplayUserByGuid(Guid.Parse(Console.ReadLine())); break; + case "8": _userConsoleUI.UpdateUserByGuid(User.Parse(Console.ReadLine())); break; + case "9": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; + case "10": Console.WriteLine("писяпопакака"); break; - case "10": _presenceConsoleUI.DisplayPresenceByGroup(Convert.ToInt32(Console.ReadLine())); break; - case "11": _presenceConsoleUI.DisplayPresenceByGroupAndDate(Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break; - case "12": _presenceConsoleUI.GeneratePresence(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break; - case "13": _presenceConsoleUI.GeneratePresenceWeek(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break; - case "14": _presenceConsoleUI.IsAttedance(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine())), Guid.Parse(Console.ReadLine())); break; + case "11": _presenceConsoleUI.DisplayPresenceByGroup(Convert.ToInt32(Console.ReadLine())); break; + case "12": _presenceConsoleUI.DisplayPresenceByGroupByTime(Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break; + case "13": _presenceConsoleUI.GeneratePresence(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break; + case "14": _presenceConsoleUI.GeneratePresenceWeek(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break; + case "15": _presenceConsoleUI.IsAttedance(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine())), Guid.Parse(Console.ReadLine())); break; default: DisplayMenu(); break; } - } } diff --git a/UI/PresenceConsole.cs b/UI/PresenceConsole.cs deleted file mode 100644 index 2f34252..0000000 --- a/UI/PresenceConsole.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Demo.Domain.UseCase; -using Demo.domain.Models; -using System.Text; - -namespace Demo.UI -{ - - 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.GetPresencesByGroup(groupID)){ - stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}"); - } - Console.WriteLine(stringBuilder); - } - - public void DisplayPresenceByGroupAndDate(int groupID, DateOnly date){ - StringBuilder stringBuilder = new StringBuilder(); - foreach(Presence presence in _presenceUseCase.GetPresencesByGroupAndDate(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); - } - - public void GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){ - string output = _presenceUseCase.GenerateWeekPresence(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно"; - Console.WriteLine(output); - } - - public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ - string output = _presenceUseCase.UpdateAttedance(firstLesson, lastLesson, date, UserGuid) ? "Обновлено" : "Не обновлено"; - Console.WriteLine(output); - } - } -} \ No newline at end of file diff --git a/UI/UserConsole.cs b/UI/UserConsole.cs index e895507..6087a45 100644 --- a/UI/UserConsole.cs +++ b/UI/UserConsole.cs @@ -1,10 +1,6 @@ -using Demo.Domain.UseCase; -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; +using Demo.Domain.Models; +using Demo.Domain.UseCase; namespace Demo.UI { @@ -15,12 +11,6 @@ namespace Demo.UI _userUseCase = userUseCase; } - public void RemoveUserByGuid(Guid guidUser) { - - string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален"; - Console.WriteLine(output); - } - public void DisplayAllUsers() { StringBuilder userOutput = new StringBuilder(); @@ -31,7 +21,13 @@ namespace Demo.UI Console.WriteLine(userOutput); } - public void UpdateUser(User user) + public void RemoveUserByGuid(Guid guidUser) { + + string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален"; + Console.WriteLine(output); + } + + public void UpdateUserByGuid(User user) { try { @@ -46,11 +42,100 @@ namespace Demo.UI } } - public void GetUserByGuid(Guid guid){ + 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 + { + IGroupUseCase _groupUseCase; + public GroupConsoleUI(IGroupUseCase groupUseCase){ + _groupUseCase = groupUseCase; + } + + 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 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); + } + + public void GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){ + string output = _presenceUseCase.GeneratePresenceWeek(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно"; + Console.WriteLine(output); + } + + public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ + string output = _presenceUseCase.IsAttedance(firstLesson, lastLesson, date, UserGuid) ? "Обновлено" : "Не обновлено"; + Console.WriteLine(output); + } + } } \ No newline at end of file