Compare commits

...

3 Commits

Author SHA1 Message Date
Userok
6cd68fd8f8 2024-11-07 14:31:00 +03:00
Userok
cefc9b3a85 2024-11-07 13:34:43 +03:00
Userok
979f0a84e8 2024-11-06 12:41:04 +03:00
29 changed files with 310 additions and 31 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,5 @@
using Zurnal.RemaDateBase.DateDao; using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
internal interface IGroupRepository internal interface IGroupRepository
{ {
@ -8,7 +9,7 @@ internal interface IGroupRepository
{ {
return AllGroup.Select(g => new GroupDao { GroupName = g.GroupName, Id = g.Id }); return AllGroup.Select(g => new GroupDao { GroupName = g.GroupName, Id = g.Id });
} }
List<GroupLocalEntity> GetAllGroup();
public bool RemoveGroupById(int groupId) public bool RemoveGroupById(int groupId)
{ {
var group = AllGroup.FirstOrDefault(g => g.Id == groupId); var group = AllGroup.FirstOrDefault(g => g.Id == groupId);

View File

@ -0,0 +1,52 @@
using Zurnal.Date.LocalDate;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Data.Repository
{
public class SQLGroupRepositoryImpl:IGroupRepository
{
private readonly RemoteDateBaseContext _remoteDataBaseContext;
public SQLGroupRepositoryImpl(RemoteDateBaseContext remoteDataBaseContext) {
_remoteDataBaseContext = remoteDataBaseContext;
}
public List<GroupDao> AllGroup => throw new NotImplementedException();
public bool AddGroup(GroupLocalEntity newGroup)
{
GroupDao groupDao = new GroupDao { GroupName = newGroup.Name };
var result = _remoteDataBaseContext.Group.Add(groupDao);
if (result != null) {
_remoteDataBaseContext.SaveChanges();
return true; }
return false;
}
public List<GroupLocalEntity> GetAllGroup()
{
return _remoteDataBaseContext.Group.Select(group => new GroupLocalEntity{
Id = group.Id,
Name = group.GroupName}
).ToList();
}
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity GetGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,7 @@
namespace domain.Models.RequestModels
{
public class GroupAddRequest
{
public string Name { get; set; }
}
}

View File

@ -0,0 +1,4 @@
public class GroupResponse{
public int Id {get; set;}
public string Name {get; set;}
}

View File

@ -1,9 +1,11 @@
using Zurnal.Data.Repository; using Zurnal.Data.Repository;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao; using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Domain.UseCase namespace Zurnal.Domain.UseCase
{ {
public class GroupUseCase : IGroupRepository public class GroupUseCase : IGroupRepository
{ {
private readonly IGroupRepository _repository;
private List<GroupDao> _groups = new List<GroupDao>(); private List<GroupDao> _groups = new List<GroupDao>();
public List<GroupDao> AllGroup => _groups; public List<GroupDao> AllGroup => _groups;
private UserRepositoryImpl _repositoryUserImpl; private UserRepositoryImpl _repositoryUserImpl;
@ -59,5 +61,19 @@ namespace Zurnal.Domain.UseCase
{ {
return _groups.FirstOrDefault(g => g.Id == id); return _groups.FirstOrDefault(g => g.Id == id);
} }
public List<GroupResponse> getAllGroup(){
return _repository.GetAllGroup().Select(group =>
new GroupResponse {
Id = group.Id,
Name = group.Name
}
).ToList();
} }
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
}
} }

View File

@ -1,9 +1,18 @@
using Zurnal.UI; using Zurnal.Domain.UseCase;
using Zurnal.Data.Repository; using Microsoft.Extensions.DependencyInjection;
using Zurnal.Domain.UseCase; using UI;
using Data.Repository;
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); IServiceCollection services = new ServiceCollection();
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase); services
.AddDbContext<RemoteDateBaseContext>()
.AddSingleton<IGroupRepository,SQLGroupRepositoryImpl>()
.AddSingleton<GroupUseCase>()
.AddSingleton<GroupConsol>();
var serviceProvider = services.BuildServiceProvider();
GroupConsol groupUI = serviceProvider.GetService<GroupConsol>();
groupUI.AddGroup();

View File

@ -2,7 +2,8 @@
{ {
public class PresnceDao public class PresnceDao
{ {
public Guid UserGuid { get; set; }
public Guid UserGuid { get; set; }
public bool IsAttendensy { get; set; } = true; public bool IsAttendensy { get; set; } = true;
public int LessonNumber { get; set; } public int LessonNumber { get; set; }
public DateOnly Date { get; set; } public DateOnly Date { get; set; }

View File

@ -1,17 +1,84 @@
using Zurnal.domain.Models; using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
using Group = System.Text.RegularExpressions.Group; using Group = System.Text.RegularExpressions.Group;
namespace Zurnal.RemaDateBase namespace Zurnal.RemaDateBase
{ {
public interface IGroupRepository public interface IGroupRepository
{ {
void AddGroup(Group group); List<GroupDao> AllGroup { get; }
Group GetGroupById(int id);
IEnumerable<Group> GetAllGroups(); public IEnumerable<GroupDao> AllGroups()
void UpdateGroup(Group group); {
void DeleteGroup(int id); return AllGroup.Select(g => new GroupDao { GroupName = g.GroupName, Id = g.Id });
object GetAllGroup(); }
bool RemoveGroupById(int groupID);
bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup); public bool RemoveGroupById(int groupId)
{
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
AllGroup.Remove(group);
return true;
}
return false;
}
public GroupDao FindGroupById(int groupId)
{
return AllGroup.FirstOrDefault(g => g.Id == groupId);
}
public bool UpdateGroupById(int groupId, GroupDao updatedGroup)
{
if (updatedGroup == null) throw new ArgumentNullException(nameof(updatedGroup));
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
group.GroupName = updatedGroup.GroupName;
return true;
}
return false;
}
public void DeleteGroup(int id)
{
var group = AllGroup.FirstOrDefault(g => g.Id == id);
if (group != null)
{
AllGroup.Remove(group);
}
}
public IEnumerable<GroupDao> GetAllGroups()
{
return AllGroup;
}
public void UpdateGroupName(int groupId, string name)
{
if (name == null) throw new ArgumentNullException(nameof(name));
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
group.GroupName = name;
}
}
public bool UpdateUser(Guid userGuid, UserDao updatedUser)
{
if (updatedUser == null) throw new ArgumentNullException(nameof(updatedUser));
var user = AllGroup.SelectMany(g => g.Users).FirstOrDefault(u => u.UserGuid == userGuid);
if (user != null)
{
user.FIO = updatedUser.FIO;
user.GroupID = updatedUser.GroupID;
user.Group = updatedUser.Group;
return true;
}
return false;
}
} }
} }

View File

@ -1,9 +1,10 @@
using Zurnal.domain.Models; using Zurnal.RemaDateBase.DateDao;
public interface IPresenceRepository public interface IPresenceRepository
{ {
void AddPresence(Presence presence); void AddPresence(PresnceDao presence);
Presence GetPresenceById(int id); PresnceDao GetPresenceById(int id);
IEnumerable<Presence> GetAllPresences(); IEnumerable<PresnceDao> GetAllPresences();
void UpdatePresence(Presence presence); void UpdatePresence(PresnceDao presence);
void DeletePresence(int id); void DeletePresence(int id);
} }

View File

@ -0,0 +1,80 @@
using Zurnal.RemaDateBase.DateDao;
public class PresenceRepository : IPresenceRepository
{
private List<PresnceDao> presences = new List<PresnceDao>();
public void AddPresence(PresnceDao presence)
{
presences.Add(new PresnceDao
{
UserGuid = presence.UserGuid,
IsAttendensy = presence.IsAttendensy,
LessonNumber = presence.LessonNumber,
Date = presence.Date,
userDao = new UserDao
{
FIO = presence.userDao.FIO,
UserGuid = presence.userDao.UserGuid,
GroupID = presence.userDao.GroupID,
Group = new GroupDao { Id = presence.userDao.Group.Id, GroupName = presence.userDao.Group.GroupName }
}
});
}
public PresnceDao GetPresenceById(int id)
{
var presence = presences.FirstOrDefault(p => p.LessonNumber == id);
return presence != null ? new PresnceDao
{
UserGuid = presence.UserGuid,
IsAttendensy = presence.IsAttendensy,
LessonNumber = presence.LessonNumber,
Date = presence.Date,
userDao = new UserDao
{
FIO = presence.userDao.FIO,
GroupID = presence.userDao.GroupID,
Group = presence.userDao.Group
}
} : null;
}
public IEnumerable<PresnceDao> GetAllPresences()
{
return presences.Select(p => new PresnceDao
{
UserGuid = p.UserGuid,
IsAttendensy = p.IsAttendensy,
LessonNumber = p.LessonNumber,
Date = p.Date,
userDao = new UserDao
{
FIO = p.userDao.FIO,
GroupID = p.userDao.GroupID,
Group = p.userDao.Group
}
}).ToList();
}
public void UpdatePresence(PresnceDao presence)
{
var existingPresence = presences.FirstOrDefault(p => p.LessonNumber == presence.LessonNumber);
if (existingPresence != null)
{
existingPresence.IsAttendensy = presence.IsAttendensy;
existingPresence.Date = presence.Date;
existingPresence.userDao.FIO = presence.userDao.FIO;
existingPresence.userDao.GroupID = presence.userDao.GroupID;
existingPresence.userDao.Group.GroupName = presence.userDao.Group.GroupName;
}
}
public void DeletePresence(int id)
{
var presence = presences.FirstOrDefault(p => p.LessonNumber == id);
if (presence != null)
{
presences.Remove(presence);
}
}
}

View File

@ -3,8 +3,6 @@ using Zurnal.RemaDateBase.DateDao;
public class RemoteDateBaseContext : DbContext public class RemoteDateBaseContext : DbContext
{ {
public RemoteDateBaseContext() { }
public DbSet<GroupDao> Group { get; set; } public DbSet<GroupDao> Group { get; set; }
public DbSet<UserDao> User { get; set; } public DbSet<UserDao> User { get; set; }
public DbSet<PresnceDao> Presence { get; set; } public DbSet<PresnceDao> Presence { get; set; }

33
Zurnal/UI/GroupConsol.cs Normal file
View File

@ -0,0 +1,33 @@
using domain;
using domain.Models.RequestModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zurnal.Domain.UseCase;
using Zurnal.RemaDateBase.DateDao;
namespace UI
{
public class GroupConsol
{
private readonly GroupUseCase _groupUseCase;
public GroupConsol(GroupUseCase groupUseCase) {
_groupUseCase = groupUseCase;
}
public void AddGroup() {
Console.WriteLine("Введите название группы: ");
string groupName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(groupName)) {
Console.WriteLine("Название группы не может быть пустым. Пожалуйста, введите корректное название.");
return;
}
GroupDao groupDao = new GroupDao { GroupName = groupName };
_groupUseCase.AddGroup(groupDao);
}
}
}

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Zurnal")] [assembly: System.Reflection.AssemblyCompanyAttribute("Zurnal")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e86bec8a7f833b7d641968f35cc2ebce20da3dc8")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+cefc9b3a85c12cb82d7e543ab8d2eb025849b9ec")]
[assembly: System.Reflection.AssemblyProductAttribute("Zurnal")] [assembly: System.Reflection.AssemblyProductAttribute("Zurnal")]
[assembly: System.Reflection.AssemblyTitleAttribute("Zurnal")] [assembly: System.Reflection.AssemblyTitleAttribute("Zurnal")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
91af4bd6b85cc028ddbbf62d14f2f440aae593b748896e98c6bba89005927b76 e861d9be05b9445b3ebef44d26117a8c4b30fb141208d42302beba8abc1372c1

View File

@ -1 +1 @@
132477173c8f0b9bd98b70bc6d28240502a0a14c41a11367b550c5913679e10c e818c2582926724344d87f9300781db10e3c61b91dde2011ab5210bca4cb8741

View File

@ -13,8 +13,12 @@
"packagesPath": "C:\\Users\\profi\\.nuget\\packages\\", "packagesPath": "C:\\Users\\profi\\.nuget\\packages\\",
"outputPath": "C:\\Users\\profi\\source\\repos\\Zurnal\\Zurnal\\obj\\", "outputPath": "C:\\Users\\profi\\source\\repos\\Zurnal\\Zurnal\\obj\\",
"projectStyle": "PackageReference", "projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [ "configFilePaths": [
"C:\\Users\\profi\\AppData\\Roaming\\NuGet\\NuGet.Config", "C:\\Users\\profi\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
], ],
"originalTargetFrameworks": [ "originalTargetFrameworks": [

View File

@ -5,12 +5,13 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool> <RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile> <ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot> <NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\profi\.nuget\packages\</NuGetPackageFolders> <NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\profi\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle> <NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.11.1</NuGetToolVersion> <NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.11.1</NuGetToolVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' "> <ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\profi\.nuget\packages\" /> <SourceRoot Include="C:\Users\profi\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup> </ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' "> <ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.entityframeworkcore\8.0.10\buildTransitive\net8.0\Microsoft.EntityFrameworkCore.props" Condition="Exists('$(NuGetPackageRoot)microsoft.entityframeworkcore\8.0.10\buildTransitive\net8.0\Microsoft.EntityFrameworkCore.props')" /> <Import Project="$(NuGetPackageRoot)microsoft.entityframeworkcore\8.0.10\buildTransitive\net8.0\Microsoft.EntityFrameworkCore.props" Condition="Exists('$(NuGetPackageRoot)microsoft.entityframeworkcore\8.0.10\buildTransitive\net8.0\Microsoft.EntityFrameworkCore.props')" />

View File

@ -2112,7 +2112,8 @@
] ]
}, },
"packageFolders": { "packageFolders": {
"C:\\Users\\profi\\.nuget\\packages\\": {} "C:\\Users\\profi\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
}, },
"project": { "project": {
"version": "1.0.0", "version": "1.0.0",
@ -2123,8 +2124,12 @@
"packagesPath": "C:\\Users\\profi\\.nuget\\packages\\", "packagesPath": "C:\\Users\\profi\\.nuget\\packages\\",
"outputPath": "C:\\Users\\profi\\source\\repos\\Zurnal\\Zurnal\\obj\\", "outputPath": "C:\\Users\\profi\\source\\repos\\Zurnal\\Zurnal\\obj\\",
"projectStyle": "PackageReference", "projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [ "configFilePaths": [
"C:\\Users\\profi\\AppData\\Roaming\\NuGet\\NuGet.Config", "C:\\Users\\profi\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
], ],
"originalTargetFrameworks": [ "originalTargetFrameworks": [

View File

@ -1,6 +1,6 @@
{ {
"version": 2, "version": 2,
"dgSpecHash": "BG9wtY8hZA8=", "dgSpecHash": "/Ii72Vl1qzo=",
"success": true, "success": true,
"projectFilePath": "C:\\Users\\profi\\source\\repos\\Zurnal\\Zurnal\\Zurnal.csproj", "projectFilePath": "C:\\Users\\profi\\source\\repos\\Zurnal\\Zurnal\\Zurnal.csproj",
"expectedPackageFiles": [ "expectedPackageFiles": [