This commit is contained in:
Class_Student 2024-10-18 12:30:44 +03:00
parent 7b40532afd
commit 5d31067f6b
23 changed files with 339 additions and 44 deletions

View File

@ -8,7 +8,7 @@ namespace _123.Data.LocalData.Entity
{
public class PresenceLocalEntity
{
public required Guid UserGuid { get; set; }
public required Guid UserGuid { get; set; }
public bool IsAttedance { get; set; } = true;
public required DateOnly Date { get; set; }

View File

@ -1,4 +1,5 @@
using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123.Data.RemoteData.RemoteDatabase.DAO
{
public class GroupDao
{
public int ID { get; set; }
public required string Name { get; set; }
public IEnumerable<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 _123.Data.RemoteData.RemoteDatabase.DAO
{
public class PresenceDao
{
public required Guid UserGuid { get; set; }
public bool IsAttedance { get; set; } = true;
public required DateOnly Date { get; set; }
public required int LessonNumber { get; set; }
public UserDao UserDao { 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 _123.Data.RemoteData.RemoteDatabase.DAO
{
public class UserDao
{
public required string UserFIO { get; set; }
public Guid UserGuid { get; set; }
public required int GroupID { get; set; }
public GroupDao Group { get; set; }
}
}

View File

@ -0,0 +1,36 @@
using _123.Data.RemoteData.RemoteDatabase.DAO;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123.Data.RemoteData.RemoteDatabase
{
internal class RemoteDatabaseContext: DbContext
{
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.UserGuid);
modelBuilder.Entity<UserDao>().Property(user => user.UserGuid).ValueGeneratedOnAdd();
modelBuilder.Entity<PresenceDao>().HasKey(presence => new
{
presence.UserGuid,
presence.Date,
presence.IsAttedance,
presence.LessonNumber
});
}
public DbSet<GroupDao> Groups { get; set; }
public DbSet<UserDao> Users { get; set; }
public DbSet<PresenceDao> PresencesDaos { get; set; }
}
}

View File

@ -1,29 +0,0 @@
using _123.Data.LocalData.Entity;
using _123.Data.LocalData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123.Data.ReportsHistory
{
public class GroupRepositoryImpl
{
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity? UpdateGroup(String name)
{
GroupLocalEntity? groupLocal = GetAllGroups()
.Where(x => x.Name == name).FirstOrDefault();
if (groupLocal == null) return null;
groupLocal.Name = name;
return groupLocal;
}
//public GroupLocalEntity AddGroup(String name, String id)
//{
// List<GroupLocalEntity> groups => new List<GroupLocalEntity>
//}
}
}

View File

@ -0,0 +1,55 @@
using _123.Data.LocalData.Entity;
using _123.Data.LocalData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using _123.Data.RemoteData.RemoteDatabase.DAO;
namespace _123.Data.Repository
{
public class GroupRepositoryImpl: IGroupRepository
{
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public bool AddGroup(String name,String Id)
{
GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault();
groupLocal.Name = name;
groupLocal.ID = int.Parse(Id);
return true;
}
public List<GroupLocalEntity> GetAllGroup()
{
return GetAllGroup();
}
public GroupLocalEntity GetGroupById(int groupID)
{
GroupLocalEntity? groupLocal = GetAllGroups()
.Where(x => x.ID == groupID).FirstOrDefault();
if (groupLocal == null) return null;
return groupLocal;
}
public bool RemoveGroupById(int groupID)
{
GroupLocalEntity? userLocal = GetAllGroups()
.Where(x => x.ID == groupID).FirstOrDefault();
if (userLocal == null) return false;
return GetAllGroups().Remove(userLocal);
}
public bool UpdateGroupById(int groupID, String name)
{
GroupLocalEntity? groupLocal = GetAllGroups()
.Where(x => x.ID == groupID).FirstOrDefault();
if (groupLocal == null) return false;
groupLocal.Name = name;
return true;
}
}
}

View File

@ -0,0 +1,19 @@
using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123.Data.Repository
{
internal interface IGroupRepository
{
List<GroupLocalEntity> GetAllGroup();
bool RemoveGroupById(int groupID);
bool UpdateGroupById(int groupID, String name);
GroupLocalEntity GetGroupById(int groupID);
bool AddGroup(String name, String id);
}
}

View File

@ -0,0 +1,19 @@
using _123.Data.LocalData.Entity;
using _123.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123.Data.Repository
{
interface IPresenceRepository
{
List<PresenceLocalEntity> GetPresenceByGroup(int groupId);
List<PresenceLocalEntity> GetPresenceByGroupAndDate(int groupId, DateOnly date);
void UnCheckAttendence (PresenceLocalEntity presence);
void AddPresence (PresenceLocalEntity presence);
}
}

View File

@ -0,0 +1,20 @@
using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123.Data.Repository
{
internal interface IUserRepository
{
public List<UserLocalEntity> GetAllUsers();
bool RemoveUserByGuid(Guid userGuid);
UserLocalEntity FindUserByGuid(Guid userGuid);
UserLocalEntity? GetUserByGuid(Guid userGuid);
UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity);
UserLocalEntity? UpdateUserByGuid(Guid userGuid);
}
}

View File

@ -0,0 +1,49 @@
using _123.Data.LocalData;
using _123.Data.LocalData.Entity;
using _123.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace _123.Data.Repository
{
public class PresenceRepositoryImpl : IPresenceRepository
{
public PresenceRepositoryImpl()
{
GetAllPresences = LocalStaticData.presences;
}
public List<PresenceLocalEntity> GetAllPresences
{ get; set; }
public void AddPresence(PresenceLocalEntity presence)
{
PresenceLocalEntity? presenceLocal = GetAllPresences.FirstOrDefault();
presenceLocal.UserGuid = presence.UserGuid;
presenceLocal.Date = presence.Date;
presenceLocal.IsAttedance = presence.IsAttedance;
presenceLocal.LessonNumber = presence.LessonNumber;
}
public List<PresenceLocalEntity> GetPresenceByGroup(int groupId)
{
}
public List<PresenceLocalEntity> GetPresenceByGroupAndDate(int groupId, DateOnly date)
{
throw new NotImplementedException();
}
public void UnCheckAttendence(Presence presence)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,5 +1,7 @@
using _123.Data.LocalData;
using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using _123.Data.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,7 +11,7 @@ using System.Xml.Linq;
namespace _123.Data.ReportsHistory
{
public class UserRepositoryImpl
public class UserRepositoryImpl: IUserRepository
{
public UserRepositoryImpl()
{
@ -64,5 +66,9 @@ namespace _123.Data.ReportsHistory
}
List<UserLocalEntity> IUserRepository.GetAllUsers()
{
throw new NotImplementedException();
}
}
}

View File

@ -9,7 +9,13 @@
</PropertyGroup>
<ItemGroup>
<Folder Include="Data\RemoteData\" />
<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>

View File

@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using _123.Domain.Models;
using _123.Data.LocalData.Entity;
using _123.Data.Repository;
namespace _123.Domain.UseCase
{
@ -19,13 +20,13 @@ namespace _123.Domain.UseCase
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new Group { ID = it.ID, Name = it.Name }).ToList();
public Group UpdateGroupName(String name, String name1)
public bool UpdateGroupName(String id, String name1)
{
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name);
if (result == null) throw new Exception("");
Group? group = GetAllGroups().FirstOrDefault(it => it.Name == result!.Name);
if (group == null) throw new Exception("");
return new Group { ID = group.ID, Name = name1 };
return _repositoryGroupImpl.UpdateGroupById(int.Parse(id), name1);
}
public bool AddGroup(String name, string id)
{
return _repositoryGroupImpl.AddGroup(name, id);
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123.Domain.UseCase
{
class PresenceUseCase
{
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123.Domain.UseCase
{
internal class UseCaseGeneratePresence
{
}
}

View File

@ -1,5 +1,7 @@
using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using _123.Data.ReportsHistory;
using _123.Data.Repository;
using _123.Domain.Models;
using System;
using System.Collections.Generic;
@ -11,8 +13,10 @@ namespace _123.Domain.UseCase
{
public class UserUseCase
{
private UserRepositoryImpl _repositoryUserImpl;
private GroupRepositoryImpl _repositoryGroupImpl;
//private readonly UserRepositoryImpl _repositoryUserImpl;
//private readonly GroupRepositoryImpl _repositoryGroupImpl;
private readonly UserRepositoryImpl _repositoryUserImpl;
private readonly IGroupRepository _repositoryGroupImpl;
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
{
@ -20,10 +24,10 @@ namespace _123.Domain.UseCase
_repositoryGroupImpl = repositoryGroupImpl;
}
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
.Select(it => new Group { ID = it.ID, Name = it.Name }).ToList();
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
.Join(_repositoryGroupImpl.GetAllGroups(),
private List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
.Join(_repositoryGroupImpl.GetAllGroup(),
user => user.GroupID,
group => group.ID,
(user, group) =>

View File

@ -1,6 +1,15 @@
using _123.Data.ReportsHistory;
using _123.Data.Repository;
using _123.Domain.UseCase;
using _123.UI;
using Microsoft.Extensions.DependencyInjection;
using System.Text.RegularExpressions;
IServiceCollection services = new ServiceCollection();
services
.AddSingleton<IGroupRepository, GroupRepositoryImpl>()
.AddSingleton<UserUseCase>();
var serviceProvider = services.BuildServiceProvider ();
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();

View File

@ -33,5 +33,15 @@ namespace _123.UI
}
Console.WriteLine(groupOutput);
}
public void AddGroup (String name, String id)
{
StringBuilder groupOutput = new StringBuilder();
var group = _groupUseCase.AddGroup(name,id);
{
groupOutput.AppendLine($"{group.Name}\t{group.ID}");
}
Console.WriteLine(groupOutput);
}
}
}

View File

@ -35,6 +35,7 @@ namespace _123.UI
case "4": _userConsoleUI.FindUserByGuid(Guid.Parse(Console.ReadLine()));break;
case "5": _userConsoleUI.UpdateUserByGuid(Guid.Parse(Console.ReadLine()),Console.ReadLine(), Console.ReadLine()); break;
case "6": _groupConsoleUI.UpdateGroupName(Console.ReadLine(),Console.ReadLine()); break;
case "7": _groupConsoleUI.AddGroup(Console.ReadLine(), Console.ReadLine());break;
default:
DisplayMenu();
break;

12
123/UI/PresenceConsole.cs Normal file
View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123.UI
{
internal class PresenceConsole
{
}
}

Binary file not shown.