Db
This commit is contained in:
parent
cd64ec54de
commit
48479e25a5
10
Data/RemoteData/RemoteDataBase/DAO/Group.cs
Normal file
10
Data/RemoteData/RemoteDataBase/DAO/Group.cs
Normal 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; }
|
||||
}
|
||||
}
|
12
Data/RemoteData/RemoteDataBase/DAO/Presence.cs
Normal file
12
Data/RemoteData/RemoteDataBase/DAO/Presence.cs
Normal 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; }
|
||||
}
|
||||
}
|
12
Data/RemoteData/RemoteDataBase/DAO/User.cs
Normal file
12
Data/RemoteData/RemoteDataBase/DAO/User.cs
Normal 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; }
|
||||
}
|
||||
}
|
35
Data/RemoteData/RemoteDataBase/RemoteDatabaseContext.cs
Normal file
35
Data/RemoteData/RemoteDataBase/RemoteDatabaseContext.cs
Normal 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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -5,54 +5,60 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
|
||||
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
|
||||
{ get; set; }
|
||||
|
||||
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) {
|
||||
|
||||
int index = GetAllGroups.FindIndex(x => x.Id == groupUpdateLocalEntity.Id);
|
||||
if (index == -1) return null;
|
||||
GetAllGroups[index].Name = groupUpdateLocalEntity.Name;
|
||||
return GetAllGroups[index];
|
||||
var group = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupUpdateLocalEntity.Id);
|
||||
if (group == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
GetAllGroups.Add(groupCreateLocalEntity);
|
||||
return groupCreateLocalEntity;
|
||||
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)
|
||||
{
|
||||
GroupLocalEntity? groupLocal = GetAllGroups
|
||||
.Where(x => x.Id == groupID).FirstOrDefault();
|
||||
if (groupLocal == null) return false;
|
||||
|
||||
return GetAllGroups.Remove(groupLocal);
|
||||
var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupID);
|
||||
_remoteDatabaseContext.Groups.Remove(groupDao);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
public GroupLocalEntity? GetGroupById(int groupID) {
|
||||
GroupLocalEntity? groupLocal = GetAllGroups
|
||||
.Where(x => x.Id == groupID).FirstOrDefault();
|
||||
if (groupLocal == null) return null;
|
||||
|
||||
return groupLocal;
|
||||
public GroupLocalEntity? GetGroupById(int groupId) {
|
||||
var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupId);
|
||||
return new GroupLocalEntity{Name = groupDao.Name, Id = groupDao.Id};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ namespace Demo.Data.Repository
|
||||
bool RemoveGroupById(int groupID);
|
||||
GroupLocalEntity? UpdateGroupName(GroupLocalEntity updatedGroup);
|
||||
GroupLocalEntity? GetGroupById(int groupID);
|
||||
GroupLocalEntity? CreateGroup(GroupLocalEntity newGroup);
|
||||
GroupLocalEntity? CreateGroup(string Name);
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ namespace Demo.Data.Repository
|
||||
List<PresenceLocalEntity> GetPresences();
|
||||
List<PresenceLocalEntity> GetPresencesByGroup();
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,37 +1,66 @@
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.domain.Models;
|
||||
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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){
|
||||
GetAllPresences.AddRange(presenceLocalEntities);
|
||||
public List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> 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;
|
||||
}
|
||||
|
||||
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)){
|
||||
if (presence.UserGuid == UserGuid){
|
||||
presence.IsAttedance = false;
|
||||
}
|
||||
var presencesToUpdate = _remoteDatabaseContext.PresenceDaos
|
||||
.Where(x => x.LessonNumber >= firstLesson
|
||||
&& x.LessonNumber <= lastLesson
|
||||
&& x.Date == date
|
||||
&& x.UserGuid == UserGuid)
|
||||
.ToList();
|
||||
|
||||
foreach(var presence in presencesToUpdate){
|
||||
presence.IsAttedance = false;
|
||||
}
|
||||
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
@ -8,43 +9,46 @@ using System.Threading.Tasks;
|
||||
|
||||
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
|
||||
{ get; set; }
|
||||
|
||||
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)
|
||||
{
|
||||
UserLocalEntity? userLocal = GetAllUsers
|
||||
.Where(x => x.Guid == userGuid).FirstOrDefault();
|
||||
if (userLocal == null) return false;
|
||||
|
||||
return GetAllUsers.Remove(userLocal);
|
||||
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid);
|
||||
_remoteDatabaseContext.Users.Remove(userDAO);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
public UserLocalEntity? GetUserByGuid(Guid userGuid) {
|
||||
UserLocalEntity? userLocal = GetAllUsers
|
||||
.Where(x => x.Guid == userGuid).FirstOrDefault();
|
||||
if (userLocal == null) return null;
|
||||
|
||||
return userLocal;
|
||||
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) {
|
||||
int index = GetAllUsers.FindIndex(x => x.Guid == userUpdateLocalEntity.Guid);
|
||||
if (index == -1) return null;
|
||||
GetAllUsers[index].FIO = userUpdateLocalEntity.FIO;
|
||||
GetAllUsers[index].GroupID = userUpdateLocalEntity.GroupID;
|
||||
return GetAllUsers[index];
|
||||
var user = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userUpdateLocalEntity.Guid);
|
||||
if (user == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
user.FIO = userUpdateLocalEntity.FIO;
|
||||
user.GroupID = userUpdateLocalEntity.GroupID;
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return new UserLocalEntity{FIO = user.FIO, Guid = user.Guid, GroupID = user.GroupID};
|
||||
}
|
||||
}
|
||||
}
|
10
Demo.csproj
10
Demo.csproj
@ -1,18 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Data\RemoteData\" />
|
||||
</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="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -11,9 +11,9 @@ namespace Demo.Domain.UseCase
|
||||
public class GroupUseCase:IGroupUseCase
|
||||
{
|
||||
|
||||
private IGroupRepository _repositoryGroupImpl;
|
||||
private readonly IGroupRepository _repositoryGroupImpl;
|
||||
|
||||
public GroupUseCase(IGroupRepository groupRepository)
|
||||
public GroupUseCase(IGroupRepository groupRepository, IUserRepository repositoryUserImpl)
|
||||
{
|
||||
_repositoryGroupImpl = groupRepository;
|
||||
}
|
||||
@ -46,19 +46,17 @@ namespace Demo.Domain.UseCase
|
||||
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(groupLocalEntity);
|
||||
if (groupLocalEntity != null) return false;
|
||||
_repositoryGroupImpl.CreateGroup(Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Group GetGroupById(int groupId) {
|
||||
|
||||
GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupId);
|
||||
if (groupLocalEntity == null) throw new Exception("");
|
||||
return new Group { Id = groupLocalEntity.Id, Name = groupLocalEntity.Name };
|
||||
if (groupLocalEntity == null) throw new Exception("bello");
|
||||
return new Group{Id = groupId, Name = groupLocalEntity.Name};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ namespace Demo.Domain.UseCase
|
||||
public interface IGroupUseCase
|
||||
{
|
||||
List<Group> GetAllGroups();
|
||||
bool RemoveGroupById(int groupID);
|
||||
bool RemoveGroupById(int groupId);
|
||||
Group UpdateGroupName(Group group);
|
||||
Group GetGroupById(int groupID);
|
||||
bool CreateGroup(Group group);
|
||||
bool CreateGroup(string Name);
|
||||
}
|
||||
}
|
@ -96,7 +96,7 @@ namespace Demo.Domain.UseCase
|
||||
Date = x.Date
|
||||
}).ToList();
|
||||
|
||||
_repositoryPresenceImpl.SavePresence(presenceLocalEntity);
|
||||
_repositoryPresenceImpl.GeneratePresence(presenceLocalEntity);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class UserUseCase:IUserUseCase
|
||||
public class UserUseCase : IUserUseCase
|
||||
{
|
||||
private readonly IUserRepository _repositoryUserImpl;
|
||||
private readonly IGroupRepository _repositoryGroupImpl;
|
||||
@ -20,36 +20,61 @@ namespace Demo.Domain.UseCase
|
||||
}
|
||||
|
||||
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()
|
||||
.Join(_repositoryGroupImpl.GetAllGroup(),
|
||||
user => user.GroupID,
|
||||
group => group.Id,
|
||||
(user, group) =>
|
||||
new User { FIO = user.FIO,
|
||||
Guid = user.Guid,
|
||||
Group = new Group {Id = group.Id, Name = group.Name } }
|
||||
).ToList();
|
||||
.Join(_repositoryGroupImpl.GetAllGroup(),
|
||||
user => user.GroupID,
|
||||
group => group.Id,
|
||||
(user, group) => new User{
|
||||
FIO = user.FIO,
|
||||
Guid = user.Guid,
|
||||
Group = new Group{
|
||||
Id = group.Id,
|
||||
Name = group.Name}
|
||||
}
|
||||
).ToList();
|
||||
|
||||
public User GetUserByGuid(Guid userGuid) {
|
||||
UserLocalEntity? userLocalEntity = _repositoryUserImpl.GetUserByGuid(userGuid);
|
||||
if (userLocalEntity == null) throw new Exception("");
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == userLocalEntity!.GroupID);
|
||||
if (group == null) throw new Exception("");
|
||||
return new User { FIO = userLocalEntity.FIO, Guid = userLocalEntity.Guid, Group = new Group { Id = group.Id, Name = group.Name }};
|
||||
|
||||
if (userLocalEntity == null) throw new Exception("bello");
|
||||
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,
|
||||
Name = group.Name}
|
||||
};
|
||||
}
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid) {
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||
}
|
||||
public User UpdateUser(User user) {
|
||||
UserLocalEntity userLocalEnity = new UserLocalEntity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid };
|
||||
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEnity);
|
||||
if (result == null) throw new Exception("");
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID);
|
||||
if (group == null) throw new Exception("");
|
||||
return new User { FIO = user.FIO, Guid = user.Guid, Group = group};
|
||||
UserLocalEntity userLocalEntity = new UserLocalEntity
|
||||
{
|
||||
FIO = user.FIO,
|
||||
Guid = user.Guid,
|
||||
GroupID = user.Group.Id
|
||||
};
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
118
Migrations/20241024202926_InitialCreate.Designer.cs
generated
Normal file
118
Migrations/20241024202926_InitialCreate.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
92
Migrations/20241024202926_InitialCreate.cs
Normal file
92
Migrations/20241024202926_InitialCreate.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
115
Migrations/RemoteDatabaseContextModelSnapshot.cs
Normal file
115
Migrations/RemoteDatabaseContextModelSnapshot.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
12
Program.cs
12
Program.cs
@ -1,4 +1,5 @@
|
||||
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.UI;
|
||||
@ -7,17 +8,16 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
IServiceCollection services = new ServiceCollection();
|
||||
|
||||
services
|
||||
.AddSingleton<IGroupRepository, GroupRepositoryImpl>()
|
||||
.AddSingleton<IUserRepository, UserRepositoryImpl>()
|
||||
.AddSingleton<IPresenceRepository, PresenceRepositoryImpl>()
|
||||
.AddDbContext<RemoteDatabaseContext>()
|
||||
.AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>()
|
||||
.AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
|
||||
.AddSingleton<IPresenceRepository, SQLPresenceRepositoryImpl>()
|
||||
.AddSingleton<IGroupUseCase, GroupUseCase>()
|
||||
.AddSingleton<IUserUseCase, UserUseCase>()
|
||||
.AddSingleton<IPresenceUseCase, PresenceUseCase>()
|
||||
.AddSingleton<UserConsoleUI>()
|
||||
.AddSingleton<GroupConsoleUI>()
|
||||
.AddSingleton<PresenceConsoleUI>()
|
||||
.AddSingleton<MainMenuUI>();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
MainMenuUI mainMenuUI = serviceProvider.GetService<MainMenuUI>();
|
||||
MainMenuUI? mainMenuUI = serviceProvider.GetService<MainMenuUI>();
|
||||
|
@ -28,19 +28,33 @@ namespace Demo.UI
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateNewGroup(Group group){
|
||||
string output = _groupUseCase.CreateGroup(group) ? "Пользователь создан" : "Пользователь не создан";
|
||||
public void CreateNewGroup(string Name){
|
||||
string output = _groupUseCase.CreateGroup(Name) ? "Группа создана" : "Группа не создана";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void DisplayAllGroups()
|
||||
{
|
||||
StringBuilder groupOutput = new StringBuilder();
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,18 +28,24 @@ namespace Demo.UI
|
||||
{
|
||||
switch (Console.ReadLine())
|
||||
{
|
||||
|
||||
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 "4": _userConsoleUI.GetUserByGuid(Guid.Parse(Console.ReadLine())); break;
|
||||
case "4": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); 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 "8": _presenceConsoleUI.DisplayPresenceByGroup(Convert.ToInt32(Console.ReadLine())); break;
|
||||
case "9": _presenceConsoleUI.DisplayPresenceByGroupByTime(Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(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 "8": _groupConsoleUI.DisplayGroupByID(Convert.ToInt32(Console.ReadLine())); break;
|
||||
case "9": _groupConsoleUI.RemoveGroupById(Convert.ToInt32(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();
|
||||
break;
|
||||
|
@ -20,7 +20,7 @@ namespace Demo.UI
|
||||
Console.WriteLine(stringBuilder);
|
||||
}
|
||||
|
||||
public void DisplayPresenceByGroupByTime(int groupID, DateOnly date){
|
||||
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}");
|
||||
|
Loading…
Reference in New Issue
Block a user