This commit is contained in:
1billy17 2024-10-24 23:41:31 +03:00
parent cd64ec54de
commit 48479e25a5
24 changed files with 591 additions and 113 deletions

View File

@ -0,0 +1,10 @@
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
{
public class GroupDao {
public int Id { get; set; }
public string Name { get; set; }
public IEnumerable<UserDao> User { get; set; }
}
}

View File

@ -0,0 +1,12 @@
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; }
}
}

View File

@ -0,0 +1,12 @@
using System.Text.RegularExpressions;
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
{
public class UserDao
{
public string FIO { get; set; }
public Guid Guid {get; set; }
public int GroupID {get; set;}
public GroupDao Group {get; set; }
}
}

View File

@ -0,0 +1,35 @@
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Microsoft.EntityFrameworkCore;
namespace Data.RemoteData.RemoteDataBase.DAO
{
public class RemoteDatabaseContext: DbContext {
public DbSet<GroupDao> Groups { get; set; }
public DbSet<UserDao> Users { get; set; }
public DbSet<PresenceDao> PresenceDaos { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;" +
"Port=5432;" +
"Username=postgres;" +
"Password=1234;" +
"Database=postgres");
}
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.Entity<GroupDao>().HasKey(group => group.Id);
modelBuilder.Entity<GroupDao>().Property(group => group.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<UserDao>().HasKey(user => user.Guid);
modelBuilder.Entity<UserDao>().Property(user => user.Guid).ValueGeneratedOnAdd();
modelBuilder.Entity<PresenceDao>().HasKey(presence => new {
presence.UserGuid,
presence.Date,
presence.IsAttedance,
presence.LessonNumber
});
}
}
}

View File

@ -5,54 +5,60 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.RemoteData.RemoteDataBase.DAO;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
namespace Demo.Data.Repository namespace Demo.Data.Repository
{ {
public class GroupRepositoryImpl:IGroupRepository public class SQLGroupRepositoryImpl : IGroupRepository
{ {
public GroupRepositoryImpl() {
GetAllGroups = LocalStaticData.groups; private readonly RemoteDatabaseContext _remoteDatabaseContext;
public SQLGroupRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) {
_remoteDatabaseContext = remoteDatabaseContext;
GetAllGroups = _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, Id = x.Id}).ToList();
} }
public List<GroupLocalEntity> GetAllGroups public List<GroupLocalEntity> GetAllGroups
{ get; set; } { get; set; }
public List<GroupLocalEntity> GetAllGroup() public List<GroupLocalEntity> GetAllGroup()
{ {
return GetAllGroups; return _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, Id = x.Id}).ToList();
} }
public GroupLocalEntity? UpdateGroupName(GroupLocalEntity groupUpdateLocalEntity) { public GroupLocalEntity? UpdateGroupName(GroupLocalEntity groupUpdateLocalEntity) {
int index = GetAllGroups.FindIndex(x => x.Id == groupUpdateLocalEntity.Id); var group = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupUpdateLocalEntity.Id);
if (index == -1) return null; if (group == null){
GetAllGroups[index].Name = groupUpdateLocalEntity.Name; return null;
return GetAllGroups[index]; }
group.Name = groupUpdateLocalEntity.Name;
_remoteDatabaseContext.SaveChanges();
return new GroupLocalEntity{Name = group.Name, Id = group.Id};
} }
public GroupLocalEntity? CreateGroup(GroupLocalEntity groupCreateLocalEntity) { public GroupLocalEntity? CreateGroup(string Name) {
if (GetAllGroups.Any(x => x.Id == groupCreateLocalEntity.Id)) return null; GroupDao groupDAO = new GroupDao{Name = Name};
var result = _remoteDatabaseContext.Groups.Add(groupDAO);
GetAllGroups.Add(groupCreateLocalEntity); _remoteDatabaseContext.SaveChanges();
return groupCreateLocalEntity; return new GroupLocalEntity{Name = groupDAO.Name, Id = groupDAO.Id};
} }
public bool RemoveGroupById(int groupID) public bool RemoveGroupById(int groupID)
{ {
GroupLocalEntity? groupLocal = GetAllGroups var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupID);
.Where(x => x.Id == groupID).FirstOrDefault(); _remoteDatabaseContext.Groups.Remove(groupDao);
if (groupLocal == null) return false; _remoteDatabaseContext.SaveChanges();
return true;
return GetAllGroups.Remove(groupLocal);
} }
public GroupLocalEntity? GetGroupById(int groupID) { public GroupLocalEntity? GetGroupById(int groupId) {
GroupLocalEntity? groupLocal = GetAllGroups var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupId);
.Where(x => x.Id == groupID).FirstOrDefault(); return new GroupLocalEntity{Name = groupDao.Name, Id = groupDao.Id};
if (groupLocal == null) return null;
return groupLocal;
} }
} }
} }

View File

@ -13,6 +13,6 @@ namespace Demo.Data.Repository
bool RemoveGroupById(int groupID); bool RemoveGroupById(int groupID);
GroupLocalEntity? UpdateGroupName(GroupLocalEntity updatedGroup); GroupLocalEntity? UpdateGroupName(GroupLocalEntity updatedGroup);
GroupLocalEntity? GetGroupById(int groupID); GroupLocalEntity? GetGroupById(int groupID);
GroupLocalEntity? CreateGroup(GroupLocalEntity newGroup); GroupLocalEntity? CreateGroup(string Name);
} }
} }

View File

@ -7,7 +7,7 @@ namespace Demo.Data.Repository
List<PresenceLocalEntity> GetPresences(); List<PresenceLocalEntity> GetPresences();
List<PresenceLocalEntity> GetPresencesByGroup(); List<PresenceLocalEntity> GetPresencesByGroup();
List<PresenceLocalEntity> GetPresencesByGroupAndDate(); List<PresenceLocalEntity> GetPresencesByGroupAndDate();
public List<PresenceLocalEntity> SavePresence(List<PresenceLocalEntity> presenceLocalEntities); List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities);
void UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid); void UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid);
} }
} }

View File

@ -1,37 +1,66 @@
using Data.RemoteData.RemoteDataBase.DAO;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models; using Demo.domain.Models;
namespace Demo.Data.Repository namespace Demo.Data.Repository
{ {
public class PresenceRepositoryImpl : IPresenceRepository public class SQLPresenceRepositoryImpl : IPresenceRepository
{ {
public List<PresenceLocalEntity> GetAllPresences = new List<PresenceLocalEntity>();
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<PresenceLocalEntity> GetAllPresence = new List<PresenceLocalEntity>{};
public List<PresenceLocalEntity> GetPresences() public List<PresenceLocalEntity> GetPresences()
{ {
return GetAllPresences; return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
} }
public List<PresenceLocalEntity> GetPresencesByGroup() public List<PresenceLocalEntity> GetPresencesByGroup()
{ {
return GetAllPresences; return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
} }
public List<PresenceLocalEntity> GetPresencesByGroupAndDate() public List<PresenceLocalEntity> GetPresencesByGroupAndDate()
{ {
return GetAllPresences; return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
} }
public List<PresenceLocalEntity> SavePresence(List<PresenceLocalEntity> presenceLocalEntities){ public List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities)
GetAllPresences.AddRange(presenceLocalEntities); {
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)
}).ToList();
_remoteDatabaseContext.PresenceDaos.AddRange(presences);
_remoteDatabaseContext.SaveChanges();
return presenceLocalEntities; return presenceLocalEntities;
} }
public void UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ public void UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
foreach(PresenceLocalEntity presence in GetAllPresences.Where(x => x.LessonNumber >= firstLesson && x.LessonNumber <= lastLesson && x.Date == date)){ var presencesToUpdate = _remoteDatabaseContext.PresenceDaos
if (presence.UserGuid == UserGuid){ .Where(x => x.LessonNumber >= firstLesson
presence.IsAttedance = false; && x.LessonNumber <= lastLesson
} && x.Date == date
&& x.UserGuid == UserGuid)
.ToList();
foreach(var presence in presencesToUpdate){
presence.IsAttedance = false;
} }
_remoteDatabaseContext.SaveChanges();
} }
} }
} }

View File

@ -1,3 +1,4 @@
using Data.RemoteData.RemoteDataBase.DAO;
using Demo.Data.LocalData; using Demo.Data.LocalData;
using Demo.domain.Models; using Demo.domain.Models;
using System; using System;
@ -8,43 +9,46 @@ using System.Threading.Tasks;
namespace Demo.Data.Repository namespace Demo.Data.Repository
{ {
public class UserRepositoryImpl:IUserRepository public class SQLUserRepositoryImpl:IUserRepository
{ {
public UserRepositoryImpl() {
GetAllUsers = LocalStaticData.users; private readonly 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<UserLocalEntity> GetAllUsers public List<UserLocalEntity> GetAllUsers
{ get; set; } { get; set; }
public List<UserLocalEntity> GetAllUser() public List<UserLocalEntity> GetAllUser()
{ {
return GetAllUsers; return _remoteDatabaseContext.Users.Select(x => new UserLocalEntity{FIO = x.FIO, Guid = x.Guid, GroupID = x.GroupID}).ToList();
} }
public bool RemoveUserByGuid(Guid userGuid) public bool RemoveUserByGuid(Guid userGuid)
{ {
UserLocalEntity? userLocal = GetAllUsers var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid);
.Where(x => x.Guid == userGuid).FirstOrDefault(); _remoteDatabaseContext.Users.Remove(userDAO);
if (userLocal == null) return false; _remoteDatabaseContext.SaveChanges();
return true;
return GetAllUsers.Remove(userLocal);
} }
public UserLocalEntity? GetUserByGuid(Guid userGuid) { public UserLocalEntity? GetUserByGuid(Guid userGuid) {
UserLocalEntity? userLocal = GetAllUsers var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid);
.Where(x => x.Guid == userGuid).FirstOrDefault(); return new UserLocalEntity{FIO = userDAO.FIO, GroupID = userDAO.GroupID, Guid = userGuid};
if (userLocal == null) return null;
return userLocal;
} }
public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEntity) { public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEntity) {
int index = GetAllUsers.FindIndex(x => x.Guid == userUpdateLocalEntity.Guid); var user = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userUpdateLocalEntity.Guid);
if (index == -1) return null; if (user == null){
GetAllUsers[index].FIO = userUpdateLocalEntity.FIO; return null;
GetAllUsers[index].GroupID = userUpdateLocalEntity.GroupID; }
return GetAllUsers[index];
user.FIO = userUpdateLocalEntity.FIO;
user.GroupID = userUpdateLocalEntity.GroupID;
_remoteDatabaseContext.SaveChanges();
return new UserLocalEntity{FIO = user.FIO, Guid = user.Guid, GroupID = user.GroupID};
} }
} }
} }

View File

@ -1,18 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Data\RemoteData\" /> <Folder Include="Data\RemoteData\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -11,9 +11,9 @@ namespace Demo.Domain.UseCase
public class GroupUseCase:IGroupUseCase public class GroupUseCase:IGroupUseCase
{ {
private IGroupRepository _repositoryGroupImpl; private readonly IGroupRepository _repositoryGroupImpl;
public GroupUseCase(IGroupRepository groupRepository) public GroupUseCase(IGroupRepository groupRepository, IUserRepository repositoryUserImpl)
{ {
_repositoryGroupImpl = groupRepository; _repositoryGroupImpl = groupRepository;
} }
@ -46,19 +46,17 @@ namespace Demo.Domain.UseCase
return _repositoryGroupImpl.RemoveGroupById(groupId); return _repositoryGroupImpl.RemoveGroupById(groupId);
} }
public bool CreateGroup(Group group) { public bool CreateGroup(string Name) {
GroupLocalEntity? groupLocalEntity = new GroupLocalEntity{Id = group.Id, Name = group.Name}; _repositoryGroupImpl.CreateGroup(Name);
_repositoryGroupImpl.CreateGroup(groupLocalEntity);
if (groupLocalEntity != null) return false;
return true; return true;
} }
public Group GetGroupById(int groupId) { public Group GetGroupById(int groupId) {
GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupId); GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupId);
if (groupLocalEntity == null) throw new Exception(""); if (groupLocalEntity == null) throw new Exception("bello");
return new Group { Id = groupLocalEntity.Id, Name = groupLocalEntity.Name }; return new Group{Id = groupId, Name = groupLocalEntity.Name};
} }
} }
} }

View File

@ -10,9 +10,9 @@ namespace Demo.Domain.UseCase
public interface IGroupUseCase public interface IGroupUseCase
{ {
List<Group> GetAllGroups(); List<Group> GetAllGroups();
bool RemoveGroupById(int groupID); bool RemoveGroupById(int groupId);
Group UpdateGroupName(Group group); Group UpdateGroupName(Group group);
Group GetGroupById(int groupID); Group GetGroupById(int groupID);
bool CreateGroup(Group group); bool CreateGroup(string Name);
} }
} }

View File

@ -96,7 +96,7 @@ namespace Demo.Domain.UseCase
Date = x.Date Date = x.Date
}).ToList(); }).ToList();
_repositoryPresenceImpl.SavePresence(presenceLocalEntity); _repositoryPresenceImpl.GeneratePresence(presenceLocalEntity);
return true; return true;
} }

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Demo.Domain.UseCase namespace Demo.Domain.UseCase
{ {
public class UserUseCase:IUserUseCase public class UserUseCase : IUserUseCase
{ {
private readonly IUserRepository _repositoryUserImpl; private readonly IUserRepository _repositoryUserImpl;
private readonly IGroupRepository _repositoryGroupImpl; private readonly IGroupRepository _repositoryGroupImpl;
@ -20,36 +20,61 @@ namespace Demo.Domain.UseCase
} }
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup() public List<Group> 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<User> GetAllUsers() => _repositoryUserImpl.GetAllUser() public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser()
.Join(_repositoryGroupImpl.GetAllGroup(), .Join(_repositoryGroupImpl.GetAllGroup(),
user => user.GroupID, user => user.GroupID,
group => group.Id, group => group.Id,
(user, group) => (user, group) => new User{
new User { FIO = user.FIO, FIO = user.FIO,
Guid = user.Guid, Guid = user.Guid,
Group = new Group {Id = group.Id, Name = group.Name } } Group = new Group{
).ToList(); Id = group.Id,
Name = group.Name}
}
).ToList();
public User GetUserByGuid(Guid userGuid) { public User GetUserByGuid(Guid userGuid) {
UserLocalEntity? userLocalEntity = _repositoryUserImpl.GetUserByGuid(userGuid); UserLocalEntity? userLocalEntity = _repositoryUserImpl.GetUserByGuid(userGuid);
if (userLocalEntity == null) throw new Exception(""); if (userLocalEntity == null) throw new Exception("bello");
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == userLocalEntity!.GroupID); Group? group = GetAllGroups().FirstOrDefault(it => userLocalEntity.GroupID == it.Id);
if (group == null) throw new Exception(""); if (group == null) throw new Exception("bello");
return new User { FIO = userLocalEntity.FIO, Guid = userLocalEntity.Guid, Group = new Group { Id = group.Id, Name = group.Name }}; return new User{
FIO = userLocalEntity.FIO,
Guid = userLocalEntity.Guid,
Group = new Group{
Id = group.Id,
Name = group.Name}
};
} }
public bool RemoveUserByGuid(Guid userGuid) { public bool RemoveUserByGuid(Guid userGuid) {
return _repositoryUserImpl.RemoveUserByGuid(userGuid); return _repositoryUserImpl.RemoveUserByGuid(userGuid);
} }
public User UpdateUser(User user) { public User UpdateUser(User user) {
UserLocalEntity userLocalEnity = new UserLocalEntity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid }; UserLocalEntity userLocalEntity = new UserLocalEntity
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEnity); {
if (result == null) throw new Exception(""); FIO = user.FIO,
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID); Guid = user.Guid,
if (group == null) throw new Exception(""); GroupID = user.Group.Id
return new User { FIO = user.FIO, Guid = user.Guid, Group = group}; };
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEntity);
if (result == null)
{
throw new Exception("");
}
Group? group = GetAllGroups().FirstOrDefault(it => result.GroupID == it.Id);
if (group == null)
{
throw new Exception("");
}
return new User
{
FIO = result.FIO,
Guid = result.Guid,
Group = group
};
} }
} }
} }

View File

@ -0,0 +1,118 @@
// <auto-generated />
using System;
using Data.RemoteData.RemoteDataBase.DAO;
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(RemoteDatabaseContext))]
[Migration("20241024202926_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Groups");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
{
b.Property<Guid>("UserGuid")
.HasColumnType("uuid");
b.Property<DateOnly>("Date")
.HasColumnType("date");
b.Property<bool>("IsAttedance")
.HasColumnType("boolean");
b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<Guid>("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>("Guid")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<int>("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("User")
.HasForeignKey("GroupID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b =>
{
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,92 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Guid = table.Column<Guid>(type: "uuid", nullable: false),
FIO = table.Column<string>(type: "text", nullable: false),
GroupID = table.Column<int>(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<Guid>(type: "uuid", nullable: false),
IsAttedance = table.Column<bool>(type: "boolean", nullable: false),
Date = table.Column<DateOnly>(type: "date", nullable: false),
LessonNumber = table.Column<int>(type: "integer", nullable: false),
userDaoGuid = table.Column<Guid>(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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PresenceDaos");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Groups");
}
}
}

View File

@ -0,0 +1,115 @@
// <auto-generated />
using System;
using Data.RemoteData.RemoteDataBase.DAO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo.Migrations
{
[DbContext(typeof(RemoteDatabaseContext))]
partial class RemoteDatabaseContextModelSnapshot : 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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Groups");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
{
b.Property<Guid>("UserGuid")
.HasColumnType("uuid");
b.Property<DateOnly>("Date")
.HasColumnType("date");
b.Property<bool>("IsAttedance")
.HasColumnType("boolean");
b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<Guid>("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>("Guid")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<int>("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("User")
.HasForeignKey("GroupID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b =>
{
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,4 +1,5 @@
using Data.RemoteData.RemoteDataBase.DAO;
using Demo.Data.Repository; using Demo.Data.Repository;
using Demo.Domain.UseCase; using Demo.Domain.UseCase;
using Demo.UI; using Demo.UI;
@ -7,17 +8,16 @@ using Microsoft.Extensions.DependencyInjection;
IServiceCollection services = new ServiceCollection(); IServiceCollection services = new ServiceCollection();
services services
.AddSingleton<IGroupRepository, GroupRepositoryImpl>() .AddDbContext<RemoteDatabaseContext>()
.AddSingleton<IUserRepository, UserRepositoryImpl>() .AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>()
.AddSingleton<IPresenceRepository, PresenceRepositoryImpl>() .AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
.AddSingleton<IPresenceRepository, SQLPresenceRepositoryImpl>()
.AddSingleton<IGroupUseCase, GroupUseCase>() .AddSingleton<IGroupUseCase, GroupUseCase>()
.AddSingleton<IUserUseCase, UserUseCase>() .AddSingleton<IUserUseCase, UserUseCase>()
.AddSingleton<IPresenceUseCase, PresenceUseCase>() .AddSingleton<IPresenceUseCase, PresenceUseCase>()
.AddSingleton<UserConsoleUI>() .AddSingleton<UserConsoleUI>()
.AddSingleton<GroupConsoleUI>()
.AddSingleton<PresenceConsoleUI>()
.AddSingleton<MainMenuUI>(); .AddSingleton<MainMenuUI>();
var serviceProvider = services.BuildServiceProvider(); var serviceProvider = services.BuildServiceProvider();
MainMenuUI mainMenuUI = serviceProvider.GetService<MainMenuUI>(); MainMenuUI? mainMenuUI = serviceProvider.GetService<MainMenuUI>();

View File

@ -28,19 +28,33 @@ namespace Demo.UI
} }
} }
public void CreateNewGroup(Group group){ public void CreateNewGroup(string Name){
string output = _groupUseCase.CreateGroup(group) ? "Пользователь создан" : "Пользователь не создан"; string output = _groupUseCase.CreateGroup(Name) ? "Группа создана" : "Группа не создана";
Console.WriteLine(output);
} }
public void DisplayAllGroups() public void DisplayAllGroups()
{ {
StringBuilder groupOutput = new StringBuilder(); StringBuilder userOutput = new StringBuilder();
foreach (var group in _groupUseCase.GetAllGroups()) foreach (var group in _groupUseCase.GetAllGroups())
{ {
groupOutput.AppendLine($"{group.Id}\t {group.Name}\t"); userOutput.AppendLine($"{group.Id}\t{group.Name}");
} }
Console.WriteLine(groupOutput); 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);
} }
} }
} }

View File

@ -28,18 +28,24 @@ namespace Demo.UI
{ {
switch (Console.ReadLine()) switch (Console.ReadLine())
{ {
case "1": _userConsoleUI.DisplayAllUsers(); break; case "1": _userConsoleUI.DisplayAllUsers(); break;
case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; case "2": _userConsoleUI.GetUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "3": _userConsoleUI.UpdateUser(User.Parse(Console.ReadLine())); break; case "3": _userConsoleUI.UpdateUser(User.Parse(Console.ReadLine())); break;
case "4": _userConsoleUI.GetUserByGuid(Guid.Parse(Console.ReadLine())); break; case "4": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "5": _groupConsoleUI.DisplayAllGroups(); break; case "5": _groupConsoleUI.DisplayAllGroups(); break;
case "6": _groupConsoleUI.CreateNewGroup(Group.Parse(Console.ReadLine())); break; case "6": _groupConsoleUI.CreateNewGroup(Console.ReadLine()); break;
case "7": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break; case "7": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break;
case "8": _presenceConsoleUI.DisplayPresenceByGroup(Convert.ToInt32(Console.ReadLine())); break; case "8": _groupConsoleUI.DisplayGroupByID(Convert.ToInt32(Console.ReadLine())); break;
case "9": _presenceConsoleUI.DisplayPresenceByGroupByTime(Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break; case "9": _groupConsoleUI.RemoveGroupById(Convert.ToInt32(Console.ReadLine())); break;
case "10": _presenceConsoleUI.GeneratePresence(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
case "11": _presenceConsoleUI.GeneratePresenceWeek(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
case "12": _presenceConsoleUI.IsAttedance(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine())), Guid.Parse(Console.ReadLine())); 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;
default: DisplayMenu(); default: DisplayMenu();
break; break;

View File

@ -20,7 +20,7 @@ namespace Demo.UI
Console.WriteLine(stringBuilder); Console.WriteLine(stringBuilder);
} }
public void DisplayPresenceByGroupByTime(int groupID, DateOnly date){ public void DisplayPresenceByGroupAndDate(int groupID, DateOnly date){
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
foreach(Presence presence in _presenceUseCase.GetPresencesByGroupAndDate(groupID, date)){ foreach(Presence presence in _presenceUseCase.GetPresencesByGroupAndDate(groupID, date)){
stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}"); stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}");