bello with presence

This commit is contained in:
Your Name 2024-10-22 21:51:54 +03:00
parent 62cf71e080
commit fdad32d8d0
16 changed files with 192 additions and 5 deletions

View File

@ -0,0 +1,12 @@
using Demo.Domain.Models;
namespace Demo.Data.Repository
{
public interface IPresenceRepository
{
List<PresenceLocalEntity> GetAllPresences();
List<PresenceLocalEntity>? GetPresenceByGroup();
List<PresenceLocalEntity> GetPresenceByGroupDate();
List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities);
}
}

View File

@ -0,0 +1,27 @@
using Demo.Data.LocalData;
using Demo.Domain.Models;
namespace Demo.Data.Repository
{
public class PresenceRepositoryImpl : IPresenceRepository
{
public List<PresenceLocalEntity> GetAllPresence = new List<PresenceLocalEntity>{};
public List<PresenceLocalEntity> GetAllPresences(){
return GetAllPresence;
}
public List<PresenceLocalEntity>? GetPresenceByGroup(){
return GetAllPresence;
}
public List<PresenceLocalEntity> GetPresenceByGroupDate(){
return GetAllPresence;
}
public List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities){
GetAllPresence.AddRange(presenceLocalEntities);
return presenceLocalEntities;
}
}
}

View File

@ -0,0 +1,11 @@
using Demo.Domain.Models;
namespace Demo.Domain.UseCase
{
public interface IPresenceUseCase
{
List<Presence> GetPresenceByGroup(int groupID);
List<Presence> GetPresenceByGroupByTime(int groupID, DateOnly date);
bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date);
}
}

View File

@ -0,0 +1,98 @@
using System.Security.Cryptography.X509Certificates;
using Demo.Data.Repository;
using Demo.Domain.Models;
namespace Demo.Domain.UseCase
{
public class PresenceUseCase : IPresenceUseCase
{
private readonly IUserRepository _repositoryUserImpl;
private readonly IPresenceRepository _repositoryPresenceImpl;
private readonly IGroupRepository _repositoryGroupImpl;
public PresenceUseCase(IPresenceRepository repositoryPresenceImpl, IUserRepository repositoryUserImpl, IGroupRepository repositoryGroupImpl)
{
_repositoryPresenceImpl = repositoryPresenceImpl;
_repositoryUserImpl = repositoryUserImpl;
_repositoryGroupImpl = repositoryGroupImpl;
}
public List<Presence> GetPresenceByGroup(int groupID){
var usersByGroup = _repositoryUserImpl.GetAllUser()
.Where(user => user.GroupID == groupID).ToList();
var presenceByGroup = _repositoryPresenceImpl.GetPresenceByGroup()
.Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid))
.Select(presence => new Presence{
User = new User{
Guid = presence.UserGuid,
Group = new Group{
ID = groupID,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
},
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
},
LessonNumber = presence.LessonNumber,
Date = presence.Date,
IsAttedance = presence.IsAttedance
}).ToList();
return presenceByGroup;
}
public List<Presence> GetPresenceByGroupByTime(int groupID, DateOnly date){
var usersByGroup = _repositoryUserImpl.GetAllUser()
.Where(user => user.GroupID == groupID).ToList();
var presenceByGroup = _repositoryPresenceImpl.GetPresenceByGroup()
.Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid && x.Date == date))
.Select(presence => new Presence{
User = new User{
Guid = presence.UserGuid,
Group = new Group{
ID = groupID,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
},
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
},
LessonNumber = presence.LessonNumber,
Date = presence.Date,
IsAttedance = presence.IsAttedance
}).ToList();
return presenceByGroup;
}
public bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date){
List<Presence> presenceList = new List<Presence>{};
var usersByGroup = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupID);
for (int i = firstLesson; i <= lastLesson; i++){
foreach(UserLocalEntity user in usersByGroup){
presenceList.Add(new Presence{
User = new User{
Group = new Group{
ID = groupID,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
},
FIO = usersByGroup.First(user2 => user2.Guid == user.Guid).FIO,
Guid = user.Guid
},
IsAttedance = true,
Date = date,
LessonNumber = i});
}
}
var presenceLocalEntity = presenceList.Select(x => new PresenceLocalEntity{
UserGuid = x.User.Guid,
IsAttedance = x.IsAttedance,
LessonNumber = x.LessonNumber,
Date = x.Date
}).ToList();
_repositoryPresenceImpl.GeneratePresence(presenceLocalEntity);
return true;
}
}
}

View File

@ -8,8 +8,10 @@ IServiceCollection services = new ServiceCollection();
services
.AddSingleton<IGroupRepository, GroupRepositoryImpl>()
.AddSingleton<IUserRepository, UserRepositoryImpl>()
.AddSingleton<IPresenceRepository, PresenceRepositoryImpl>()
.AddSingleton<IGroupUseCase, GroupUseCase>()
.AddSingleton<IUserUseCase, UserUseCase>()
.AddSingleton<IPresenceUseCase, PresenceUseCase>()
.AddSingleton<UserConsoleUI>()
.AddSingleton<MainMenuUI>();

View File

@ -8,10 +8,12 @@ namespace Demo.UI
UserConsoleUI _userConsoleUI;
GroupConsoleUI _groupConsoleUI;
PresenceConsoleUI _presenceConsoleUI;
public MainMenuUI(IUserUseCase userUseCase, IGroupUseCase groupUseCase) {
public MainMenuUI(IUserUseCase userUseCase, IGroupUseCase groupUseCase, IPresenceUseCase presenceUseCase) {
_userConsoleUI = new UserConsoleUI(userUseCase);
_groupConsoleUI = new GroupConsoleUI(groupUseCase);
_presenceConsoleUI = new PresenceConsoleUI(presenceUseCase);
DisplayMenu();
}
@ -28,6 +30,12 @@ namespace Demo.UI
case "5": _groupConsoleUI.DisplayAllGroups(); break;
case "6": _groupConsoleUI.CreateNewGroup(Group.Parse(Console.ReadLine())); break;
case "7": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break; //todo
case "10": Console.WriteLine("писяпопакака"); break;
case "777": _presenceConsoleUI.DisplayPresenceByGroup(Convert.ToInt32(Console.ReadLine())); break;
case "888": _presenceConsoleUI.DisplayPresenceByGroupByTime(Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
case "999": _presenceConsoleUI.GeneratePresence(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
default: DisplayMenu();
break;

View File

@ -67,7 +67,8 @@ namespace Demo.UI
}
public void CreateNewGroup(Group group){
string output = _groupUseCase.CreateGroup(group) ? "Пользователь создан" : "Пользователь не создан";
string output = _groupUseCase.CreateGroup(group) ? "Группа создана" : "Группа не создана";
Console.WriteLine(output);
}
public void UpdateGroupName(Group group)
@ -85,4 +86,32 @@ namespace Demo.UI
}
}
}
public class PresenceConsoleUI{
IPresenceUseCase _presenceUseCase;
public PresenceConsoleUI (IPresenceUseCase presenceUseCase){
_presenceUseCase = presenceUseCase;
}
public void DisplayPresenceByGroup(int groupID){
StringBuilder stringBuilder = new StringBuilder();
foreach(Presence presence in _presenceUseCase.GetPresenceByGroup(groupID)){
stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}");
}
Console.WriteLine(stringBuilder);
}
public void DisplayPresenceByGroupByTime(int groupID, DateOnly date){
StringBuilder stringBuilder = new StringBuilder();
foreach(Presence presence in _presenceUseCase.GetPresenceByGroupByTime(groupID, date)){
stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}");
}
Console.WriteLine(stringBuilder);
}
public void GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date){
string output = _presenceUseCase.GeneratePresence(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно";
Console.WriteLine(output);
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,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+efdaa788226f9fa951e2ae58165ff21fe7ad3343")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+62cf71e0807e9e3240bed91fc96a70ca85f326da")]
[assembly: System.Reflection.AssemblyProductAttribute("Demo")]
[assembly: System.Reflection.AssemblyTitleAttribute("Demo")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
48f599dad06dd9ec07676f26c2418560d03b7411954018e21ccf3036a6416f34
a01cfb167fed9f2405a5e73c2f292e1435aae3d26590e7f2368a0b28d9d0813e

View File

@ -1 +1 @@
73b1ce81cd1614d1fb79d966e9c834dbbfe2456209fddcd2419a154a7bcb8cef
09be6b06af3e5ac830f9b11348702d6b725bd1a0b9782c4a38dcd83e5849bf9b

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.