diff --git a/Demo/Data/LocalData/Entity/Group.cs b/Demo/Data/Entity/Group.cs similarity index 90% rename from Demo/Data/LocalData/Entity/Group.cs rename to Demo/Data/Entity/Group.cs index 6041311..3ade4dc 100644 --- a/Demo/Data/LocalData/Entity/Group.cs +++ b/Demo/Data/Entity/Group.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Demo.domain.Models +namespace Demo.Data.Entity { public class GroupLocalEntity { diff --git a/Demo/Data/LocalData/Entity/Presence.cs b/Demo/Data/Entity/Presence.cs similarity index 80% rename from Demo/Data/LocalData/Entity/Presence.cs rename to Demo/Data/Entity/Presence.cs index 71c2474..834adc9 100644 --- a/Demo/Data/LocalData/Entity/Presence.cs +++ b/Demo/Data/Entity/Presence.cs @@ -4,12 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Demo.domain.Models +namespace Demo.Data.Entity { public class PresenceLocalEntity { public required Guid UserGuid { get; set; } - public bool IsAttedance { get; set; } = true; + public bool IsAttedance { get; set; } public required DateOnly Date { get; set; } public required int LessonNumber { get; set; } diff --git a/Demo/Data/LocalData/Entity/User.cs b/Demo/Data/Entity/User.cs similarity index 84% rename from Demo/Data/LocalData/Entity/User.cs rename to Demo/Data/Entity/User.cs index 5af4881..01ff20d 100644 --- a/Demo/Data/LocalData/Entity/User.cs +++ b/Demo/Data/Entity/User.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Demo.domain.Models +namespace Demo.Data.Entity { public class UserLocalEnity : IEquatable { @@ -13,12 +13,12 @@ namespace Demo.domain.Models public required int GroupID { get; set; } - + public bool Equals(UserLocalEnity? other) { if (other == null) return false; - return this.Guid.Equals(other.Guid); + return Guid.Equals(other.Guid); } } } diff --git a/Demo/Data/LocalData/LocalStaticData.cs b/Demo/Data/LocalData/LocalStaticData.cs index 5fd9fd4..491156e 100644 --- a/Demo/Data/LocalData/LocalStaticData.cs +++ b/Demo/Data/LocalData/LocalStaticData.cs @@ -1,4 +1,4 @@ -using Demo.domain.Models; +using Demo.Data.Entity; using System; using System.Collections.Generic; using System.Linq; diff --git a/Demo/Data/RemoteData/RemoteDataBase/DAO/Group.cs b/Demo/Data/RemoteData/RemoteDataBase/DAO/Group.cs new file mode 100644 index 0000000..818fcc7 --- /dev/null +++ b/Demo/Data/RemoteData/RemoteDataBase/DAO/Group.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; + +namespace Demo.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/Demo/Data/RemoteData/RemoteDataBase/DAO/Presence.cs b/Demo/Data/RemoteData/RemoteDataBase/DAO/Presence.cs new file mode 100644 index 0000000..d2f9b32 --- /dev/null +++ b/Demo/Data/RemoteData/RemoteDataBase/DAO/Presence.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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; } + + } +} diff --git a/Demo/Data/RemoteData/RemoteDataBase/DAO/User.cs b/Demo/Data/RemoteData/RemoteDataBase/DAO/User.cs new file mode 100644 index 0000000..d2f7cc5 --- /dev/null +++ b/Demo/Data/RemoteData/RemoteDataBase/DAO/User.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.Data.RemoteData.RemoteDataBase.DAO +{ + public class UserDao + { + public required string F10 { get; set; } + public Guid Guid { get; set; } + public required int GroupId { get; set; } + public GroupDao Group { get; set; } + } +} diff --git a/Demo/Data/RemoteData/RemoteDataBase/RemoteDatabaseContex.cs b/Demo/Data/RemoteData/RemoteDataBase/RemoteDatabaseContex.cs new file mode 100644 index 0000000..317c8d7 --- /dev/null +++ b/Demo/Data/RemoteData/RemoteDataBase/RemoteDatabaseContex.cs @@ -0,0 +1,39 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Npgsql; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; +using System.Reflection.Emit; +using System.Text; +using System.Threading.Tasks; +using Demo.Data.RemoteData.RemoteDataBase.DAO; +using Demo.domain.Models; + +namespace Demo.Data.RemoteData.RemoteDataBase +{ + public class RemoteDatabaseContex : 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=45.67.56.214;Port=5421;Username=user9;Database=user9;Password=X8C8NTnD;"); + } + 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/Demo/Data/Repository/GroupRepositoryImpl.cs b/Demo/Data/Repository/GroupRepositoryImpl.cs index e02cc8d..0b78e50 100644 --- a/Demo/Data/Repository/GroupRepositoryImpl.cs +++ b/Demo/Data/Repository/GroupRepositoryImpl.cs @@ -1,4 +1,5 @@ -using Demo.Data.LocalData; +using Demo.Data.Entity; +using Demo.Data.LocalData; using Demo.domain.Models; using System.Collections.Generic; using System.Linq; diff --git a/Demo/Data/Repository/IGroupRepository.cs b/Demo/Data/Repository/IGroupRepository.cs index fb1d75a..97e0f59 100644 --- a/Demo/Data/Repository/IGroupRepository.cs +++ b/Demo/Data/Repository/IGroupRepository.cs @@ -1,19 +1,13 @@ -using Demo.domain.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Demo.Data.Entity; namespace Demo.Data.Repository { public interface IGroupRepository { - bool AddGroup(GroupLocalEntity newGroup); + bool AddGroup(GroupLocalEntity newGroup); List GetAllGroup(); - GroupLocalEntity GetGroupById(int groupID); - bool RemoveGroupById(int groupID); - bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup); + GroupLocalEntity GetGroupById(int groupId); + bool UpdateGroupById(int groupId, GroupLocalEntity updatedGroup); + bool RemoveGroupById(int groupId); } - } diff --git a/Demo/Data/Repository/IPresenceRepository.cs b/Demo/Data/Repository/IPresenceRepository.cs new file mode 100644 index 0000000..433174d --- /dev/null +++ b/Demo/Data/Repository/IPresenceRepository.cs @@ -0,0 +1,11 @@ +using Demo.Data.Entity; +using System.Collections.Generic; + +namespace Demo.Data.Repository +{ + public interface IPresenceRepository + { + bool AddPresence(PresenceLocalEntity newPresence); + List GetAllPresences(); + } +} diff --git a/Demo/Data/Repository/IUserRepository.cs b/Demo/Data/Repository/IUserRepository.cs new file mode 100644 index 0000000..d508279 --- /dev/null +++ b/Demo/Data/Repository/IUserRepository.cs @@ -0,0 +1,14 @@ +using Demo.Data.Entity; +using System.Collections.Generic; + +namespace Demo.Data.Repository +{ + public interface IUserRepository + { + bool AddUser(UserLocalEnity newUser); + List GetAllUsers(); + UserLocalEnity GetUserById(Guid userID); + bool RemoveUserById(Guid userID); + bool UpdateUserById(Guid userID, UserLocalEnity updatedUser); + } +} \ No newline at end of file diff --git a/Demo/Data/Repository/SQLGroupRepositoryLmpl.cs b/Demo/Data/Repository/SQLGroupRepositoryLmpl.cs new file mode 100644 index 0000000..5d39495 --- /dev/null +++ b/Demo/Data/Repository/SQLGroupRepositoryLmpl.cs @@ -0,0 +1,90 @@ +using Demo.Data.Entity; +using Demo.Data.RemoteData.RemoteDataBase; +using Demo.Data.RemoteData.RemoteDataBase.DAO; +using System.Collections.Generic; +using System.Linq; + +namespace Demo.Data.Repository +{ + class SQLGroupRepositoryLmpl : IGroupRepository + { + private readonly RemoteDatabaseContex _remoteDatabaseContext; + + public SQLGroupRepositoryLmpl(RemoteDatabaseContex remoteDatabaseContext) + { + _remoteDatabaseContext = remoteDatabaseContext; + } + + public bool AddGroup(GroupLocalEntity newGroup) + { + GroupDao groupDao = new GroupDao { Name = newGroup.Name }; + var result = _remoteDatabaseContext.Groups.Add(groupDao); + _remoteDatabaseContext.SaveChanges(); + if (result != null) return true; + return false; + } + + public List GetAllGroup() + { + var groups = _remoteDatabaseContext.Groups.ToList(); + + return groups.Select(g => new GroupLocalEntity + { + Id = g.Id, + Name = g.Name + }).ToList(); + } + + + public GroupLocalEntity GetGroupById(int groupID) + { + var group = _remoteDatabaseContext.Groups + .FirstOrDefault(g => g.Id == groupID); + + if (group == null) + { + return null; + } + + return new GroupLocalEntity + { + Id = group.Id, + Name = group.Name + }; + } + + public bool RemoveGroupById(int groupID) + { + var group = _remoteDatabaseContext.Groups + .FirstOrDefault(g => g.Id == groupID); + + if (group == null) + { + return false; + } + + _remoteDatabaseContext.Groups.Remove(group); + _remoteDatabaseContext.SaveChanges(); + + return true; + } + + public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup) + { + var existingGroup = _remoteDatabaseContext.Groups + .FirstOrDefault(g => g.Id == groupID); + + if (existingGroup == null) + { + return false; + } + + existingGroup.Name = updatedGroup.Name; + + _remoteDatabaseContext.SaveChanges(); + + return true; + } + + } +} diff --git a/Demo/Data/Repository/SQLPresenceRepositoryLmpl.cs b/Demo/Data/Repository/SQLPresenceRepositoryLmpl.cs new file mode 100644 index 0000000..4a5e026 --- /dev/null +++ b/Demo/Data/Repository/SQLPresenceRepositoryLmpl.cs @@ -0,0 +1,45 @@ +using Demo.Data.Entity; +using Demo.Data.RemoteData.RemoteDataBase; +using Demo.Data.RemoteData.RemoteDataBase.DAO; +using System.Collections.Generic; +using System.Linq; + +namespace Demo.Data.Repository +{ + public class SQLPresenceRepositoryImpl : IPresenceRepository + { + private readonly RemoteDatabaseContex _remoteDatabaseContext; + + public SQLPresenceRepositoryImpl(RemoteDatabaseContex remoteDatabaseContext) + { + _remoteDatabaseContext = remoteDatabaseContext; + } + + public bool AddPresence(PresenceLocalEntity newPresence) + { + var presenceDao = new PresenceDao + { + UserGuid = newPresence.UserGuid, + IsAttedance = newPresence.IsAttedance, // Используем IsAttendance + Date = newPresence.Date, + LessonNumber = newPresence.LessonNumber + }; + + _remoteDatabaseContext.PresenceDaos.Add(presenceDao); + return _remoteDatabaseContext.SaveChanges() > 0; // Возвращаем true, если изменения сохранены + } + + public List GetAllPresences() + { + return _remoteDatabaseContext.PresenceDaos + .Select(p => new PresenceLocalEntity + { + UserGuid = p.UserGuid, + IsAttedance = p.IsAttedance, // Обратите внимание на правильное название свойства + Date = p.Date, + LessonNumber = p.LessonNumber + }) + .ToList(); + } + } +} diff --git a/Demo/Data/Repository/SQLUserRepositoeyLmpl.cs b/Demo/Data/Repository/SQLUserRepositoeyLmpl.cs new file mode 100644 index 0000000..728f981 --- /dev/null +++ b/Demo/Data/Repository/SQLUserRepositoeyLmpl.cs @@ -0,0 +1,94 @@ +using Demo.Data.Entity; +using Demo.Data.RemoteData.RemoteDataBase; +using Demo.Data.RemoteData.RemoteDataBase.DAO; +using System.Collections.Generic; +using System.Linq; + +namespace Demo.Data.Repository +{ + public class SQLUserRepositoryImpl : IUserRepository + { + private readonly RemoteDatabaseContex _remoteDatabaseContext; + + public SQLUserRepositoryImpl(RemoteDatabaseContex remoteDatabaseContext) + { + _remoteDatabaseContext = remoteDatabaseContext; + } + + public bool AddUser(UserLocalEnity newUser) + { + var userDao = new UserDao + { + Guid = Guid.NewGuid(), + F10 = newUser.FIO, + GroupId = newUser.GroupID + }; + + _remoteDatabaseContext.Users.Add(userDao); + + return _remoteDatabaseContext.SaveChanges() > 0; + } + + + public List GetAllUsers() + { + return _remoteDatabaseContext.Users + .Select(user => new UserLocalEnity + { + Guid = user.Guid, + FIO = user.F10, + GroupID = user.GroupId + }) + .ToList(); + } + + public UserLocalEnity GetUserById(Guid userID) + { + var user = _remoteDatabaseContext.Users.Find(userID); + + if (user == null) + { + return null; + } + return new UserLocalEnity + { + Guid = user.Guid, + GroupID = user.GroupId, + FIO = user.F10 + }; + } + + + + public bool RemoveUserById(Guid userID) + { + var user = _remoteDatabaseContext.Users.Find(userID); + + if (user == null) + { + return false; + } + + _remoteDatabaseContext.Users.Remove(user); + _remoteDatabaseContext.SaveChanges(); + + return true; + } + + + public bool UpdateUserById(Guid userID, UserLocalEnity updatedUser) + { + var user = _remoteDatabaseContext.Users.Find(userID); + + if (user == null) + { + return false; + } + user.GroupId = updatedUser.GroupID; + user.Guid = updatedUser.Guid; + _remoteDatabaseContext.SaveChanges(); + + return true; + } + } +} diff --git a/Demo/Data/Repository/UserRepositoryImpl.cs b/Demo/Data/Repository/UserRepositoryImpl.cs index bf9ae8c..ebafa42 100644 --- a/Demo/Data/Repository/UserRepositoryImpl.cs +++ b/Demo/Data/Repository/UserRepositoryImpl.cs @@ -1,5 +1,5 @@ -using Demo.Data.LocalData; -using Demo.domain.Models; +using Demo.Data.Entity; +using Demo.Data.LocalData; using System; using System.Collections.Generic; using System.Linq; diff --git a/Demo/Demo.csproj b/Demo/Demo.csproj index 1ea2759..ad196e3 100644 --- a/Demo/Demo.csproj +++ b/Demo/Demo.csproj @@ -8,7 +8,17 @@ - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/Demo/Domain/UseCase/GroupUseCase.cs b/Demo/Domain/UseCase/GroupUseCase.cs index 47e68f2..59e9507 100644 --- a/Demo/Domain/UseCase/GroupUseCase.cs +++ b/Demo/Domain/UseCase/GroupUseCase.cs @@ -1,4 +1,5 @@ -using Demo.Data.LocalData; +using Demo.Data.Entity; +using Demo.Data.LocalData; using Demo.Data.Repository; using Demo.domain.Models; using System.Collections.Generic; @@ -8,15 +9,15 @@ namespace Demo.Domain.UseCase { public class GroupUseCase { - private GroupRepositoryImpl _repositoryGroupImpl; + private IGroupRepository _repositoryGroupImpl; - public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl) + public GroupUseCase(IGroupRepository repositoryGroupImpl) { _repositoryGroupImpl = repositoryGroupImpl; } public bool RemoveGroupById(int groupID) { - var group = _repositoryGroupImpl.GetAllGroups.FirstOrDefault(g => g.Id == groupID); + var group = _repositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == groupID); if (group != null) { _repositoryGroupImpl.RemoveGroupById(groupID); diff --git a/Demo/Domain/UseCase/UseCasePresence.cs b/Demo/Domain/UseCase/UseCasePresence.cs index 5a762fa..9edb158 100644 --- a/Demo/Domain/UseCase/UseCasePresence.cs +++ b/Demo/Domain/UseCase/UseCasePresence.cs @@ -1,5 +1,5 @@ -using Demo.Data.LocalData; -using Demo.domain.Models; +using Demo.Data.Entity; +using Demo.Data.LocalData; using System.Collections.Generic; using System.Linq; @@ -32,23 +32,25 @@ namespace Demo.Domain.UseCase presence.IsAttedance = false; } } - public void GenerateDailySchedule(int groupId, int startLesson, int endLesson) + public void GenerateDailySchedule(int groupId, int startLesson, int endLesson, DateTime date) { var usersInGroup = LocalStaticData.users .Where(u => u.GroupID == groupId) .ToList(); - + + LocalStaticData.presences.RemoveAll(p => usersInGroup.Select(users => users.Guid).Contains(p.UserGuid) && p.Date == DateOnly.FromDateTime(date)); Console.WriteLine($"Расписание для группы {groupId}:"); - + foreach (var user in usersInGroup) { + for (int lesson = startLesson; lesson <= endLesson; lesson++) { var presence = new PresenceLocalEntity { UserGuid = user.Guid, IsAttedance = true, - Date = DateOnly.FromDateTime(DateTime.Now), + Date = DateOnly.FromDateTime(date), LessonNumber = lesson }; @@ -57,6 +59,14 @@ namespace Demo.Domain.UseCase Console.WriteLine($"User: {user.Guid}, Attended: {presence.IsAttedance}, Date: {presence.Date}, Lesson: {presence.LessonNumber}"); } } + + } + public void GenerateWeeklySchedule(int groupId, int startLesson, int endLesson, DateTime date) + { + for(int i = 0; i < 7;i++) + { + GenerateDailySchedule(groupId, startLesson, endLesson, date.AddDays(i)); + } } } } diff --git a/Demo/Domain/UseCase/UserUseCase.cs b/Demo/Domain/UseCase/UserUseCase.cs index 7c841c8..36dc736 100644 --- a/Demo/Domain/UseCase/UserUseCase.cs +++ b/Demo/Domain/UseCase/UserUseCase.cs @@ -1,4 +1,5 @@ -using Demo.Data.Repository; +using Demo.Data.Entity; +using Demo.Data.Repository; using Demo.domain.Models; using System; using System.Collections.Generic; @@ -8,11 +9,11 @@ namespace Demo.Domain.UseCase { public class UserUseCase { - private readonly UserRepositoryImpl _repositoryUserImpl; + private readonly IUserRepository _repositoryUserImpl; private readonly IGroupRepository _repositoryGroupImpl; - public UserUseCase(UserRepositoryImpl repositoryImpl, IGroupRepository repositoryGroupImpl) + public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl) { _repositoryUserImpl = repositoryImpl; _repositoryGroupImpl = repositoryGroupImpl; @@ -21,7 +22,7 @@ namespace Demo.Domain.UseCase private List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() .Select(it => new Group { Id = it.Id, Name = it.Name }).ToList(); - public List GetAllUsers() => _repositoryUserImpl.GetAllUsers + public List GetAllUsers() => _repositoryUserImpl.GetAllUsers() .Join(_repositoryGroupImpl.GetAllGroup(), user => user.GroupID, group => group.Id, @@ -31,22 +32,22 @@ namespace Demo.Domain.UseCase public bool RemoveUserByGuid(Guid userGuid) { - return _repositoryUserImpl.RemoveUserByGuid(userGuid); + return _repositoryUserImpl.RemoveUserById(userGuid); } - public User UpdateUser(User user) + public User UpdateUser(Guid userGuid,User user) { UserLocalEnity userLocalEnity = new UserLocalEnity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid }; - UserLocalEnity? result = _repositoryUserImpl.UpdateUser(userLocalEnity); - if (result == null) throw new Exception(""); - Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID); + bool result = _repositoryUserImpl.UpdateUserById(userGuid, userLocalEnity); + if (!result) throw new Exception(""); + Group? group = GetAllGroups().FirstOrDefault(it => it.Id == user.Group.Id); if (group == null) throw new Exception(""); return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; } public User? FindUserByGuid(Guid userGuid) { - var userLocal = _repositoryUserImpl.GetUserByGuid(userGuid); + var userLocal = _repositoryUserImpl.GetUserById(userGuid); if (userLocal == null) return null; var group = _repositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == userLocal.GroupID); diff --git a/Demo/Migrations/20241028123800_InitialCreate.Designer.cs b/Demo/Migrations/20241028123800_InitialCreate.Designer.cs new file mode 100644 index 0000000..bff793a --- /dev/null +++ b/Demo/Migrations/20241028123800_InitialCreate.Designer.cs @@ -0,0 +1,118 @@ +// +using System; +using Demo.Data.RemoteData.RemoteDataBase; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Demo.Migrations +{ + [DbContext(typeof(RemoteDatabaseContex))] + [Migration("20241028123800_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b => + { + b.Property("UserGuid") + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("IsAttedance") + .HasColumnType("boolean"); + + b.Property("LessonNumber") + .HasColumnType("integer"); + + b.Property("UserDaoGuid") + .HasColumnType("uuid"); + + b.HasKey("UserGuid", "Date", "IsAttedance", "LessonNumber"); + + b.HasIndex("UserDaoGuid"); + + b.ToTable("PresenceDaos"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b => + { + b.Property("Guid") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("F10") + .IsRequired() + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.HasKey("Guid"); + + b.HasIndex("GroupId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b => + { + b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", "UserDao") + .WithMany() + .HasForeignKey("UserDaoGuid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("UserDao"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b => + { + b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", "Group") + .WithMany("Users") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b => + { + b.Navigation("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Demo/Migrations/20241028123800_InitialCreate.cs b/Demo/Migrations/20241028123800_InitialCreate.cs new file mode 100644 index 0000000..cb9335f --- /dev/null +++ b/Demo/Migrations/20241028123800_InitialCreate.cs @@ -0,0 +1,92 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Demo.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Groups", + columns: table => new + { + 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); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Guid = table.Column(type: "uuid", nullable: false), + F10 = table.Column(type: "text", nullable: false), + GroupId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Guid); + table.ForeignKey( + name: "FK_Users_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PresenceDaos", + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_PresenceDaos", x => new { x.UserGuid, x.Date, x.IsAttedance, x.LessonNumber }); + table.ForeignKey( + name: "FK_PresenceDaos_Users_UserDaoGuid", + column: x => x.UserDaoGuid, + principalTable: "Users", + principalColumn: "Guid", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_PresenceDaos_UserDaoGuid", + table: "PresenceDaos", + column: "UserDaoGuid"); + + migrationBuilder.CreateIndex( + name: "IX_Users_GroupId", + table: "Users", + column: "GroupId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "PresenceDaos"); + + migrationBuilder.DropTable( + name: "Users"); + + migrationBuilder.DropTable( + name: "Groups"); + } + } +} diff --git a/Demo/Migrations/RemoteDatabaseContexModelSnapshot.cs b/Demo/Migrations/RemoteDatabaseContexModelSnapshot.cs new file mode 100644 index 0000000..fa613ed --- /dev/null +++ b/Demo/Migrations/RemoteDatabaseContexModelSnapshot.cs @@ -0,0 +1,115 @@ +// +using System; +using Demo.Data.RemoteData.RemoteDataBase; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Demo.Migrations +{ + [DbContext(typeof(RemoteDatabaseContex))] + partial class RemoteDatabaseContexModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b => + { + b.Property("UserGuid") + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("IsAttedance") + .HasColumnType("boolean"); + + b.Property("LessonNumber") + .HasColumnType("integer"); + + b.Property("UserDaoGuid") + .HasColumnType("uuid"); + + b.HasKey("UserGuid", "Date", "IsAttedance", "LessonNumber"); + + b.HasIndex("UserDaoGuid"); + + b.ToTable("PresenceDaos"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b => + { + b.Property("Guid") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("F10") + .IsRequired() + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.HasKey("Guid"); + + b.HasIndex("GroupId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b => + { + b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", "UserDao") + .WithMany() + .HasForeignKey("UserDaoGuid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("UserDao"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b => + { + b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", "Group") + .WithMany("Users") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b => + { + b.Navigation("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Demo/Program.cs b/Demo/Program.cs index 6fe09f9..d00b47c 100644 --- a/Demo/Program.cs +++ b/Demo/Program.cs @@ -1,17 +1,29 @@ -using Demo.Data.Repository; +using Demo.Data.RemoteData.RemoteDataBase; +using Demo.Data.Repository; using Demo.Domain.UseCase; using Demo.UI; +using Microsoft.Extensions.DependencyInjection; class Program { static void Main(string[] args) { - GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); - UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl(); - UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl); - GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl); - UseCasePresence presenceUseCase = new UseCasePresence(); - - MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase, presenceUseCase); + + IServiceCollection services = new ServiceCollection(); + services.AddDbContext() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton(); + var serviceProvaider = services.BuildServiceProvider(); + MainMenuUI mainMenuUI= serviceProvaider.GetService(); + mainMenuUI.DisplayMenu(); } } diff --git a/Demo/UI/GroupConsole.cs b/Demo/UI/GroupConsole.cs index 23a035c..e289e3e 100644 --- a/Demo/UI/GroupConsole.cs +++ b/Demo/UI/GroupConsole.cs @@ -1,4 +1,5 @@ -using Demo.Data.LocalData; +using Demo.Data.Entity; +using Demo.Data.LocalData; using Demo.domain.Models; using Demo.Domain.UseCase; using System; diff --git a/Demo/UI/MainMenu.cs b/Demo/UI/MainMenu.cs index 089190f..78c0920 100644 --- a/Demo/UI/MainMenu.cs +++ b/Demo/UI/MainMenu.cs @@ -11,17 +11,15 @@ namespace Demo.UI private UseCasePresence _presenceUseCase; private PresenceConsoleUI _presenceConsoleUI; - public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase, UseCasePresence presenceUseCase) + public MainMenuUI(UserConsoleUI userConsoleUI, GroupConsoleUI groupConsoleUI, PresenceConsoleUI presenceConsoleUI) { - _userConsoleUI = new UserConsoleUI(userUseCase); - _groupConsoleUI = new GroupConsoleUI(groupUseCase); - _presenceUseCase = presenceUseCase; - _presenceConsoleUI = new PresenceConsoleUI(presenceUseCase); - DisplayMenu(); + _userConsoleUI = userConsoleUI; + _groupConsoleUI = groupConsoleUI; + _presenceConsoleUI = presenceConsoleUI; } - private void DisplayMenu() + public void DisplayMenu() { while (true) { @@ -38,6 +36,7 @@ namespace Demo.UI Console.WriteLine("10 - Вывести посещаемость по группе и дате"); Console.WriteLine("11 - Отметить пользователя как отсутствующего"); Console.WriteLine("12 - Генерация расписания по диапозону"); + Console.WriteLine("13 - Генерация расписания по диапозону на неделю"); Console.WriteLine("0 - Выход"); var input = Console.ReadLine(); @@ -74,7 +73,7 @@ namespace Demo.UI Group = new Group { Id = newGroupId, Name = newGroupName } }; - _userConsoleUI.UpdateUser(updatedUser); + _userConsoleUI.UpdateUser(updateGuid, updatedUser); } else { @@ -151,11 +150,42 @@ namespace Demo.UI } break; case "11": - _presenceConsoleUI.MarkUserAsAbsent(); + Console.WriteLine("Введите GUID пользователя для отметки отсутствия:"); + if (Guid.TryParse(Console.ReadLine(), out var absenceUserGuid)) + { + Console.WriteLine("Введите дату (в формате ГГГГ-ММ-ДД):"); + if (DateOnly.TryParse(Console.ReadLine(), out var absenceDate)) + { + Console.WriteLine("Введите диапазон уроков (например, 2-4):"); + var lessonRange = Console.ReadLine().Split('-'); + if (lessonRange.Length == 2 && + int.TryParse(lessonRange[0], out var startLesson) && + int.TryParse(lessonRange[1], out var endLesson)) + { + // Вызов метода для отметки отсутствия + _presenceConsoleUI.MarkUserAsAbsent(absenceUserGuid, absenceDate, startLesson, endLesson); + } + else + { + Console.WriteLine("Некорректный диапазон уроков."); + } + } + else + { + Console.WriteLine("Некорректная дата."); + } + } + else + { + Console.WriteLine("Некорректный GUID."); + } break; case "12": _presenceConsoleUI.GenerateDailySchedule(); break; + case "13": + _presenceConsoleUI.GenerateWeeklySchedule(); + break; case "0": return; default: diff --git a/Demo/UI/PresenceConcole.cs b/Demo/UI/PresenceConcole.cs index ea08e58..4870011 100644 --- a/Demo/UI/PresenceConcole.cs +++ b/Demo/UI/PresenceConcole.cs @@ -1,4 +1,7 @@ -using Demo.Domain.UseCase; +using Demo.Data.Entity; +using Demo.Data.LocalData; +using Demo.domain.Models; +using Demo.Domain.UseCase; using System; namespace Demo.UI @@ -39,33 +42,21 @@ namespace Demo.UI Console.WriteLine($"User: {presence.UserGuid}, Attended: {presence.IsAttedance}, Lesson: {presence.LessonNumber}"); } } - public void MarkUserAsAbsent() + public void MarkUserAsAbsent(Guid userGuid, DateOnly date, int startLesson, int endLesson) { - Console.WriteLine("Введите GUID пользователя:"); - if (Guid.TryParse(Console.ReadLine(), out var userGuid)) + _useCasePresence.MarkUserAsAbsent(userGuid, startLesson, endLesson); + for (int lesson = startLesson; lesson <= endLesson; lesson++) { - Console.WriteLine("Введите номер первого занятия:"); - if (int.TryParse(Console.ReadLine(), out int startLesson)) + var presence = new PresenceLocalEntity { - Console.WriteLine("Введите номер последнего занятия:"); - if (int.TryParse(Console.ReadLine(), out int endLesson)) - { - _useCasePresence.MarkUserAsAbsent(userGuid, startLesson, endLesson); - Console.WriteLine("Пользователь отмечен как отсутствующий."); - } - else - { - Console.WriteLine("Некорректный номер последнего занятия."); - } - } - else - { - Console.WriteLine("Некорректный номер первого занятия."); - } - } - else - { - Console.WriteLine("Некорректный GUID."); + UserGuid = userGuid, + IsAttedance = false, + Date = date, + LessonNumber = lesson + }; + + // Вывод информации о отметке + Console.WriteLine($"User: {userGuid}, Attended: {presence.IsAttedance}, Date: {presence.Date}, Lesson: {presence.LessonNumber}"); } } public void GenerateDailySchedule() @@ -79,7 +70,35 @@ namespace Demo.UI Console.WriteLine("Введите номер последнего урока:"); if (int.TryParse(Console.ReadLine(), out int endLesson)) { - _useCasePresence.GenerateDailySchedule(groupId, startLesson, endLesson); + _useCasePresence.GenerateDailySchedule(groupId, startLesson, endLesson,DateTime.Now); + } + else + { + Console.WriteLine("Некорректный номер последнего урока."); + } + } + else + { + Console.WriteLine("Некорректный номер первого урока."); + } + } + else + { + Console.WriteLine("Некорректный ID группы."); + } + } + public void GenerateWeeklySchedule() + { + Console.WriteLine("Введите ID группы:"); + if (int.TryParse(Console.ReadLine(), out int groupId)) + { + Console.WriteLine("Введите номер первого урока:"); + if (int.TryParse(Console.ReadLine(), out int startLesson)) + { + Console.WriteLine("Введите номер последнего урока:"); + if (int.TryParse(Console.ReadLine(), out int endLesson)) + { + _useCasePresence.GenerateWeeklySchedule(groupId, startLesson, endLesson, DateTime.Now); } else { @@ -97,6 +116,5 @@ namespace Demo.UI } } - } } diff --git a/Demo/UI/UserConsole.cs b/Demo/UI/UserConsole.cs index 562b890..f3233b1 100644 --- a/Demo/UI/UserConsole.cs +++ b/Demo/UI/UserConsole.cs @@ -43,9 +43,9 @@ namespace Demo.UI } } - public void UpdateUser(User updatedUser) + public void UpdateUser(Guid userGuid, User updatedUser) { - var result = _userUseCase.UpdateUser(updatedUser); + var result = _userUseCase.UpdateUser(userGuid, updatedUser); if (result != null) { Console.WriteLine("Пользователь обновлён.");