This commit is contained in:
adm 2024-10-25 11:47:11 +03:00
parent 0e15fc7d62
commit f7d51508b5
33 changed files with 517 additions and 32 deletions

View File

@ -11,5 +11,7 @@ namespace Demo.domain.Models
public required int Id { get; set; }
public required string Name { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
{
public class GroupDao
{
public int Id { get; set; }
public required string Name { get; set; }
public List<UserDao> Users { get; set; }
}
}

View File

@ -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 int UserId { get; set; }
public bool IsAttedance { get; set; } = true;
public DateOnly Date { get; set; }
public int LessonNumber { get; set; }
public UserDao UserDao { get; set; }
public int GroupId { get; set; }
}
}

View File

@ -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 FIO { get; set; }
public int UserId { get; set; }
public required int GroupId { get; set; }
public GroupDao Group { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.Data.RemoteData.RemoteDataBase
{
internal class RemoteDatabase
{
}
}

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Demo.Data.RemoteData.RemoteDataBase
{
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();
}
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.UserId);
modelBuilder.Entity<UserDao>().Property(user=>user.UserId).ValueGeneratedOnAdd();
modelBuilder.Entity<PresenceDao>().HasKey(presence => new
{
presence.UserId,
presence.Date,
presence.IsAttedance,
presence.LessonNumber
});
}
}
}

View File

@ -1,10 +1,12 @@
using Demo.Data.Exceptions;
using Demo.Data.LocalData;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.Data.Repository;
using Demo.domain.Models;
using System.Collections.Generic;
using System.Linq;
public class GroupRepositoryImpl
public class GroupRepositoryImpl: IGroupRepository
{
private List<GroupLocalEntity> _groups = LocalStaticData.groups;
@ -50,4 +52,59 @@ public class GroupRepositoryImpl
_groups.Remove(existingGroup);
}
}
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
{
throw new NotImplementedException();
}
bool IGroupRepository.AddGroup(GroupLocalEntity newGroup)
{
throw new NotImplementedException();
}
public List<GroupDao> GetAllGroupDao()
{
throw new NotImplementedException();
}
public bool RemoveGroupByIdDao(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupDao updatedGroup)
{
throw new NotImplementedException();
}
public GroupDao GetGroupByIdDao(int groupID)
{
throw new NotImplementedException();
}
public bool AddGroup(GroupDao newGroup)
{
throw new NotImplementedException();
}
public bool UpdateGroupByIdDao(int groupID, GroupDao updatedGroup)
{
throw new NotImplementedException();
}
public bool AddGroupDao(GroupDao newGroup)
{
throw new NotImplementedException();
}
}

View File

@ -1,4 +1,5 @@
using Demo.domain.Models;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -14,5 +15,13 @@ namespace Demo.Data.Repository
bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup);
GroupLocalEntity GetGroupById(int groupID);
bool AddGroup(GroupLocalEntity newGroup);
List<GroupDao> GetAllGroupDao();
bool RemoveGroupByIdDao(int groupID);
bool UpdateGroupByIdDao(int groupID, GroupDao updatedGroup);
GroupDao GetGroupByIdDao(int groupID);
bool AddGroupDao(GroupDao newGroup);
}
}

View File

@ -1,4 +1,5 @@

using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using Demo.Domain.UseCase;
using System;
@ -15,5 +16,12 @@ namespace Demo.Data.Repository
List<PresenceLocalEntity> GetPresenceByDateAndGroup(DateTime date, int groupId);
void SavePresence(List<PresenceLocalEntity> presences);
List<PresenceLocalEntity> GetPresenceByGroup(int groupId);
List<PresenceDao> GetPresenceByDateAndGroupDao(DateTime date, int groupId);
void SavePresenceDao(List<PresenceDao> presences);
List<PresenceDao> GetPresenceByGroupDao(int groupId);
}
}

View File

@ -0,0 +1,20 @@
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using System.Collections.Generic;
namespace Demo.Data.Repository
{
public interface IUserRepository
{
IEnumerable<UserLocalEnity> GetAllUsers { get; }
bool RemoveUserById(int userId);
UserLocalEnity? UpdateUser(UserLocalEnity user);
IEnumerable<UserDao> GetAllUsersDao { get; }
bool RemoveUserByIdDao(int userId);
UserDao? UpdateUserDao(UserDao user);
}
}

View File

@ -1,4 +1,6 @@
using Demo.Data.LocalData;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
@ -41,21 +43,24 @@ namespace Demo.Data.Repository
LocalStaticData.users.Any(u => u.GroupID == groupId && u.ID == p.UserId)).ToList();
}
// Реализация метода для получения всех данных по группе
public List<PresenceLocalEntity> GetAllPresenceByGroup(int groupId)
{
return _presences
.Where(p => LocalStaticData.users.Any(u => u.GroupID == groupId && u.ID == p.UserId))
.OrderBy(p => p.Date)
.ThenBy(p => p.LessonNumber)
.ToList();
}
public List<PresenceLocalEntity> GetPresenceByGroup(int groupId)
{
return _presences.Where(p => p.GroupId == groupId).ToList();
}
public List<PresenceDao> GetPresenceByDateAndGroupDao(DateTime date, int groupId)
{
throw new NotImplementedException();
}
public void SavePresenceDao(List<PresenceDao> presences)
{
throw new NotImplementedException();
}
public List<PresenceDao> GetPresenceByGroupDao(int groupId)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,129 @@
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Demo.Data.Repository
{
public class SQLGroupRepositoryImpl : IGroupRepository
{
private readonly RemoteDatabaseContext _remoteDatabaseContext;
public SQLGroupRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
// Метод для добавления новой группы
public bool AddGroupDao(GroupDao newGroup)
{
var groupDao = new GroupDao
{
Name = newGroup.Name
};
_remoteDatabaseContext.Groups.Add(groupDao);
_remoteDatabaseContext.SaveChanges();
return true;
}
// Метод для получения группы по ID
public GroupDao GetGroupByIdDao(int groupId)
{
var groupDao = _remoteDatabaseContext.Groups
.Include(g => g.Users)
.FirstOrDefault(g => g.Id == groupId);
if (groupDao == null) return null;
return new GroupDao
{
Id = groupDao.Id,
Name = groupDao.Name,
Users = groupDao.Users.Select(u => new UserDao
{
UserId = u.UserId,
FIO = u.FIO,
GroupId = u.GroupId
}).ToList()
};
}
// Метод для получения всех групп
public List<GroupDao> GetAllGroupDao()
{
return _remoteDatabaseContext.Groups
.Include(g => g.Users)
.Select(g => new GroupDao
{
Id = g.Id,
Name = g.Name,
Users = g.Users.Select(u => new UserDao
{
UserId = u.UserId,
FIO = u.FIO,
GroupId = u.GroupId
}).ToList()
})
.ToList();
}
// Метод для обновления группы по ID
public bool UpdateGroupByIdDao(int groupId, GroupDao updatedGroup)
{
var groupDao = _remoteDatabaseContext.Groups
.Include(g => g.Users)
.FirstOrDefault(g => g.Id == groupId);
if (groupDao == null) return false;
groupDao.Name = updatedGroup.Name;
// Пример обновления списка пользователей
groupDao.Users = updatedGroup.Users.Select(user => new UserDao
{
UserId = user.UserId,
FIO = user.FIO,
GroupId = user.GroupId
}).ToList();
_remoteDatabaseContext.SaveChanges();
return true;
}
// Метод для удаления группы по ID
public bool RemoveGroupByIdDao(int groupId)
{
var groupDao = _remoteDatabaseContext.Groups.Find(groupId);
if (groupDao == null) return false;
_remoteDatabaseContext.Groups.Remove(groupDao);
_remoteDatabaseContext.SaveChanges();
return true;
}
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
{
throw new NotImplementedException();
}
public GroupLocalEntity GetGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool AddGroup(GroupLocalEntity newGroup)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,69 @@
using Demo.Data.LocalData;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.Data.Repository
{
public class SQLPresenceRepositoryImpl : IPresenceRepository
{
private readonly RemoteDatabaseContext _remoteDatabaseContext;
public SQLPresenceRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
public List<PresenceLocalEntity> GetPresenceByDateAndGroup(DateTime date, int groupId)
{
throw new NotImplementedException();
}
public List<PresenceDao> GetPresenceByDateAndGroupDao(DateTime date, int groupId)
{
return _remoteDatabaseContext.PresenceDaos.Where(p => p.Date == DateOnly.FromDateTime(date) &&
LocalStaticData.users.Any(u => u.GroupID == groupId && u.ID == p.UserId)).ToList();
}
public List<PresenceLocalEntity> GetPresenceByGroup(int groupId)
{
throw new NotImplementedException();
}
// Реализация метода для получения всех данных по группе
public List<PresenceDao> GetPresenceByGroupDao(int groupId)
{
return _remoteDatabaseContext.PresenceDaos.Where(p => p.GroupId == groupId).ToList();
}
public void SavePresence(List<PresenceLocalEntity> presences)
{
throw new NotImplementedException();
}
public void SavePresenceDao(List<PresenceDao> presences)
{
foreach (var presence in presences)
{
var existingPresence = _remoteDatabaseContext.PresenceDaos.FirstOrDefault(p =>
p.Date == presence.Date &&
p.UserId == presence.UserId &&
p.LessonNumber == presence.LessonNumber);
if (existingPresence == null)
{
_remoteDatabaseContext.PresenceDaos.Add(presence);
}
else
{
existingPresence.IsAttedance = presence.IsAttedance;
}
}
}
}
}

View File

@ -0,0 +1,60 @@
using Demo.Data.Exceptions;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Demo.Data.Repository
{
public class SQLUserRepositoryImpl : IUserRepository
{
private readonly RemoteDatabaseContext _remoteDatabaseContext;
public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
public IEnumerable<UserDao> GetAllUsersDao => _remoteDatabaseContext.Users;
public bool RemoveUserByIdDao(int userId)
{
var user = _remoteDatabaseContext.Users.FirstOrDefault(u => u.UserId == userId);
if (user == null) throw new UserNotFoundException(userId);
_remoteDatabaseContext.Users.Remove(user);
return true;
}
public UserDao? UpdateUserDao(UserDao user)
{
var existingUser = _remoteDatabaseContext.Users.FirstOrDefault(u => u.UserId == user.UserId);
if (existingUser == null) throw new UserNotFoundException(user.UserId);
existingUser.FIO = user.FIO;
existingUser.GroupId = user.GroupId;
return existingUser;
}
public IEnumerable<UserLocalEnity> GetAllUsers => throw new NotImplementedException();
public bool RemoveUserById(int userId)
{
throw new NotImplementedException();
}
public UserLocalEnity? UpdateUser(UserLocalEnity user)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,5 +1,6 @@
using Demo.Data.Exceptions;
using Demo.Data.LocalData;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
@ -7,7 +8,7 @@ using System.Linq;
namespace Demo.Data.Repository
{
public class UserRepositoryImpl
public class UserRepositoryImpl: IUserRepository
{
private List<UserLocalEnity> _users;
@ -18,6 +19,8 @@ namespace Demo.Data.Repository
public IEnumerable<UserLocalEnity> GetAllUsers => _users;
public IEnumerable<UserDao> GetAllUsersDao => throw new NotImplementedException();
public bool RemoveUserById(int userId)
{
var user = _users.FirstOrDefault(u => u.ID == userId);
@ -27,6 +30,11 @@ namespace Demo.Data.Repository
return true;
}
public bool RemoveUserByIdDao(int userId)
{
throw new NotImplementedException();
}
public UserLocalEnity? UpdateUser(UserLocalEnity user)
{
var existingUser = _users.FirstOrDefault(u => u.Guid == user.Guid);
@ -37,5 +45,10 @@ namespace Demo.Data.Repository
return existingUser;
}
public UserDao? UpdateUserDao(UserDao user)
{
throw new NotImplementedException();
}
}
}

View File

@ -7,10 +7,6 @@
<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">
@ -21,4 +17,8 @@
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
</ItemGroup>
<ItemGroup>
<Folder Include="Data\RemoteData\RemoteApi\" />
</ItemGroup>
</Project>

View File

@ -1,11 +1,22 @@
using Demo.Data.Repository;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.Repository;
using Demo.Domain.UseCase;
using Demo.UI;
using Microsoft.Extensions.DependencyInjection;
// Создаем экземпляр репозиториев
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();
PresenceRepositoryImpl presenceRepositoryImpl = new PresenceRepositoryImpl(); // Создаем экземпляр PresenceRepositoryImpl
PresenceRepositoryImpl presenceRepositoryImpl = new PresenceRepositoryImpl();
IServiceCollection services = new ServiceCollection();
services.AddDbContext<RemoteDatabaseContext>().
AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>();
services.AddDbContext<RemoteDatabaseContext>().
AddSingleton<IUserRepository, SQLUserRepositoryImpl>();
services.AddDbContext<RemoteDatabaseContext>().
AddSingleton<IPresenceRepository, SQLPresenceRepositoryImpl>();
// Создаем UseCase для пользователей и групп
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Demo")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+bdcbb230221dd6b16c8afe4eecbf5e82d3dd453f")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0e15fc7d62cdcd2ecc8853e551035e8a3737aee9")]
[assembly: System.Reflection.AssemblyProductAttribute("Demo")]
[assembly: System.Reflection.AssemblyTitleAttribute("Demo")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
8d3243526905ae765e6daa2b1e2144f748b500ab06dd8d82a753e36b69dd0434
4ece56c2162fd488c720e2f84da208a216fb7d2f8a4132ee7289842b3b121377

View File

@ -8,6 +8,6 @@ build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = Demo
build_property.ProjectDir = C:\Users\adm\source\repos\presence1\Demo\
build_property.ProjectDir = C:\Users\adm\Source\Repos\presence1\Demo\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View File

@ -1 +1 @@
f332ef5a930fab54749fbe5329497cc560cebacd091081c9fb4dc676cfcfd95f
d802b7b93a990c8713727f8364fc47b1846b2dbf47bb30c6359a4f9f360292fb

Binary file not shown.

View File

@ -1 +1 @@
d5eb5cfbfe9d110c04bac2d0bacec315a054499e2bed6b39e50a2c77268548e7
bfad4a74ba74f7b6af7182a47faf922142f10d24ecb4676d49fb56abebdc3e22

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,17 +1,17 @@
{
"format": 1,
"restore": {
"C:\\Users\\adm\\source\\repos\\presence1\\Demo\\Demo.csproj": {}
"C:\\Users\\adm\\Source\\Repos\\presence1\\Demo\\Demo.csproj": {}
},
"projects": {
"C:\\Users\\adm\\source\\repos\\presence1\\Demo\\Demo.csproj": {
"C:\\Users\\adm\\Source\\Repos\\presence1\\Demo\\Demo.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\adm\\source\\repos\\presence1\\Demo\\Demo.csproj",
"projectUniqueName": "C:\\Users\\adm\\Source\\Repos\\presence1\\Demo\\Demo.csproj",
"projectName": "Demo",
"projectPath": "C:\\Users\\adm\\source\\repos\\presence1\\Demo\\Demo.csproj",
"projectPath": "C:\\Users\\adm\\Source\\Repos\\presence1\\Demo\\Demo.csproj",
"packagesPath": "C:\\Users\\adm\\.nuget\\packages\\",
"outputPath": "C:\\Users\\adm\\source\\repos\\presence1\\Demo\\obj\\",
"outputPath": "C:\\Users\\adm\\Source\\Repos\\presence1\\Demo\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\adm\\AppData\\Roaming\\NuGet\\NuGet.Config",

View File

@ -1,8 +1,8 @@
{
"version": 2,
"dgSpecHash": "u1UuBtFmr6Y=",
"dgSpecHash": "O3GkfNM2ZvQ=",
"success": true,
"projectFilePath": "C:\\Users\\adm\\source\\repos\\presence1\\Demo\\Demo.csproj",
"projectFilePath": "C:\\Users\\adm\\Source\\Repos\\presence1\\Demo\\Demo.csproj",
"expectedPackageFiles": [
"C:\\Users\\adm\\.nuget\\packages\\humanizer.core\\2.14.1\\humanizer.core.2.14.1.nupkg.sha512",
"C:\\Users\\adm\\.nuget\\packages\\microsoft.bcl.asyncinterfaces\\6.0.0\\microsoft.bcl.asyncinterfaces.6.0.0.nupkg.sha512",