Compare commits

..

4 Commits

Author SHA1 Message Date
Class_Student
8ba9a00ccc qwer 2024-11-15 12:30:35 +03:00
Class_Student
14271607f2 jhg 2024-11-08 10:51:01 +03:00
Class_Student
ab637e3bbc hello 2024-11-08 10:47:20 +03:00
Class_Student
5d31067f6b hello 2024-10-28 11:07:28 +03:00
25 changed files with 212 additions and 230 deletions

View File

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

View File

@ -6,12 +6,16 @@ using System.Threading.Tasks;
namespace _123.Data.LocalData.Entity namespace _123.Data.LocalData.Entity
{ {
public class UserLocalEntity public class UserLocalEntity : IEquatable<UserLocalEntity>
{ {
public required string UserFIO { get; set; } public required string UserFIO { get; set; }
public int UserId { get; set; } public Guid UserGuid { get; set; }
public required int GroupID { get; set; } public required int GroupID { get; set; }
public bool Equals(UserLocalEntity? other)
{
if (other == null) return false;
return this.UserGuid.Equals(other.UserGuid);
}
} }
} }

View File

@ -18,12 +18,12 @@ namespace _123.Data.LocalData
}; };
public static List<UserLocalEntity> users => new List<UserLocalEntity> public static List<UserLocalEntity> users => new List<UserLocalEntity>
{ {
new UserLocalEntity{UserId = 1, UserFIO = "RandomFio", GroupID = 1 }, new UserLocalEntity{UserGuid=Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), UserFIO = "RandomFio", GroupID = 1 },
new UserLocalEntity{UserId = 2, UserFIO = "RandomFio1", GroupID = 2 }, new UserLocalEntity{UserGuid=Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), UserFIO = "RandomFio1", GroupID = 2 },
new UserLocalEntity{UserId = 3, UserFIO = "RandomFio2", GroupID = 3 }, new UserLocalEntity{UserGuid=Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), UserFIO = "RandomFio2", GroupID = 3 },
new UserLocalEntity{UserId = 4, UserFIO = "RandomFio3", GroupID = 1 }, new UserLocalEntity{UserGuid=Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), UserFIO = "RandomFio3", GroupID = 1 },
new UserLocalEntity{UserId = 5, UserFIO = "RandomFio4", GroupID = 2 }, new UserLocalEntity{UserGuid=Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), UserFIO = "RandomFio4", GroupID = 2 },
new UserLocalEntity{UserId = 6, UserFIO = "RandomFio5", GroupID = 3 }, new UserLocalEntity{UserGuid=Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), UserFIO = "RandomFio5", GroupID = 3 },
}; };
public static List<PresenceLocalEntity> presences => new List<PresenceLocalEntity> public static List<PresenceLocalEntity> presences => new List<PresenceLocalEntity>
{ {

View File

@ -13,7 +13,7 @@ namespace _123.Data.RemoteData.RemoteDatabase.DAO
public required int LessonNumber { get; set; } public required int LessonNumber { get; set; }
public UserDao UserDao { get; set; } public UserDao UserDao { get; set; }
public int UserID { get; set; } public int UserId { get; set; }
public int GroupId { get; set; } public int GroupId { get; set; }
} }
} }

View File

@ -12,17 +12,17 @@ namespace _123.Data.RemoteData.RemoteDatabase
{ {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseNpgsql("Host = 45.67.56.214; Port = 5421; Username = user3; Database = user3; Password = VOTfZ8PQ"); optionsBuilder.UseNpgsql();
} }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<GroupDao>().HasKey(group => group.ID); modelBuilder.Entity<GroupDao>().HasKey(group => group.ID);
modelBuilder.Entity<GroupDao>().Property(group => group.ID).ValueGeneratedOnAdd(); modelBuilder.Entity<GroupDao>().Property(group => group.ID).ValueGeneratedOnAdd();
modelBuilder.Entity<UserDao>().HasKey(user => user.UserID); modelBuilder.Entity<UserDao>().HasKey(user => user.UserGuid);
modelBuilder.Entity<UserDao>().Property(user => user.UserID).ValueGeneratedOnAdd(); modelBuilder.Entity<UserDao>().Property(user => user.UserGuid).ValueGeneratedOnAdd();
modelBuilder.Entity<PresenceDao>().HasKey(presence => new modelBuilder.Entity<PresenceDao>().HasKey(presence => new
{ {
presence.UserID, presence.UserGuid,
presence.Date, presence.Date,
presence.IsAttedance, presence.IsAttedance,
presence.LessonNumber presence.LessonNumber

View File

@ -0,0 +1,33 @@
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)
{
GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault();
groupLocal.Name = name;
groupLocal.ID = int.Parse(id);
return groupLocal;
}
}
}

View File

@ -50,16 +50,6 @@ namespace _123.Data.Repository
groupLocal.Name = name; groupLocal.Name = name;
return true; return true;
} }
List<GroupDao> IGroupRepository.GetAllGroup()
{
throw new NotImplementedException();
}
GroupDao IGroupRepository.GetGroupById(int groupID)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace _123.Data.Repository namespace _123.Data.Repository
{ {
public interface IGroupRepository internal interface IGroupRepository
{ {
List<GroupDao> GetAllGroup(); List<GroupDao> GetAllGroup();
bool RemoveGroupById(int groupID); bool RemoveGroupById(int groupID);

View File

@ -1,5 +1,4 @@
using _123.Data.LocalData.Entity; using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using _123.Domain.Models; using _123.Domain.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -9,11 +8,11 @@ using System.Threading.Tasks;
namespace _123.Data.Repository namespace _123.Data.Repository
{ {
public interface IPresenceRepository internal interface IPresenceRepository
{ {
List<PresenceDao> GetPresenceByGroup(int groupId); List<PresenceDao> GetPresenceByGroup(int groupId);
List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date); List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date);
bool UnCheckAttendence (int firstClass, int lastClass, DateOnly date, int UserId); bool UnCheckAttendence (int firstClass, int lastClass, DateOnly date, Guid userGuid);
void AddPresence (PresenceDao presence); void AddPresence (PresenceDao presence);
} }

View File

@ -8,13 +8,13 @@ using System.Threading.Tasks;
namespace _123.Data.Repository namespace _123.Data.Repository
{ {
public interface IUserRepository internal interface IUserRepository
{ {
List<UserDao> GetAllUser(); List<UserDao> GetAllUser();
bool RemoveUserById(int userId); bool RemoveUserByGuid(int userId);
UserDao FindUserById(int userId); UserDao FindUserByGuid(Guid userGuid);
UserDao? GetUserById(int userId); UserDao? GetUserByGuid(int userId);
UserDao? UpdateUser(UserDao userUpdate); UserDao? UpdateUser(UserDao userUpdate);
UserDao? UpdateUserById(int userId); UserDao? UpdateUserByGuid(int userId);
} }
} }

View File

@ -1,6 +1,5 @@
using _123.Data.LocalData; using _123.Data.LocalData;
using _123.Data.LocalData.Entity; using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using _123.Domain.Models; using _123.Domain.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,33 +14,37 @@ namespace _123.Data.Repository
public class PresenceRepositoryImpl : IPresenceRepository public class PresenceRepositoryImpl : IPresenceRepository
{ {
public List<PresenceDao> GetAllPresences public PresenceRepositoryImpl()
{
GetAllPresences = LocalStaticData.presences;
}
public List<PresenceLocalEntity> GetAllPresences
{ get; set; } { get; set; }
public void AddPresence(PresenceDao presence) public void AddPresence(PresenceLocalEntity presence)
{ {
PresenceDao? presenceLocal = GetAllPresences.FirstOrDefault(); PresenceLocalEntity? presenceLocal = GetAllPresences.FirstOrDefault();
presenceLocal.UserID = presence.UserID; presenceLocal.UserGuid = presence.UserGuid;
presenceLocal.Date = presence.Date; presenceLocal.Date = presence.Date;
presenceLocal.IsAttedance = presence.IsAttedance; presenceLocal.IsAttedance = presence.IsAttedance;
presenceLocal.LessonNumber = presence.LessonNumber; presenceLocal.LessonNumber = presence.LessonNumber;
} }
public List<PresenceDao> GetPresenceByGroup(int groupId) public List<PresenceLocalEntity> GetPresenceByGroup(int groupId)
{ {
return GetAllPresences; return GetAllPresences;
} }
public List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date) public List<PresenceLocalEntity> GetPresenceByGroupAndDate(int groupId, DateOnly date)
{ {
return GetAllPresences; return GetAllPresences;
} }
public bool UnCheckAttendence(int firstClass, int lastClass, DateOnly date, int userId) public bool UnCheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid)
{ {
var presToUpdate = GetAllPresences var presToUpdate = GetAllPresences
.Where(x => x.UserID == userId && x.LessonNumber >= firstClass .Where(x => x.UserGuid == userGuid && x.LessonNumber >= firstClass
&& x.LessonNumber <= lastClass && x.Date == date).ToList(); && x.LessonNumber <= lastClass && x.Date == date).ToList();
foreach (var presence in presToUpdate) foreach (var presence in presToUpdate)
{ {

View File

@ -1,13 +1,11 @@
using _123.Data.LocalData; using _123.Data.LocalData;
using _123.Data.LocalData.Entity; using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase; using _123.Data.RemoteData.RemoteDatabase;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
namespace _123.Data.Repository namespace _123.Data.Repository
{ {
@ -23,8 +21,8 @@ namespace _123.Data.Repository
public List<GroupDao> GetAllGroups() public List<GroupDao> GetAllGroups()
{ {
var groups = _remoteDatabaseContext.Groups var groups = _remoteDatabaseContext.Groups
.Select(g => new GroupDao .Select(g => new GroupDao
{ {
ID = g.ID, ID = g.ID,
Name = g.Name Name = g.Name
}) })
@ -61,19 +59,13 @@ namespace _123.Data.Repository
{ {
var group = _remoteDatabaseContext.Groups var group = _remoteDatabaseContext.Groups
.FirstOrDefault(x => x.ID == groupID); .FirstOrDefault(x => x.ID == groupID);
if (group == null) return null; if (group == null) return null;
return new GroupDao return new GroupDao
{ {
ID = group.ID, ID = group.ID,
Name = group.Name, Name = group.Name
Users = group.Users?.Select(u => new UserDao
{
UserID = u.UserID,
UserFIO = u.UserFIO,
GroupID = group.ID
}).ToList() ?? new List<UserDao>()
}; };
} }
@ -84,12 +76,13 @@ namespace _123.Data.Repository
var group = _remoteDatabaseContext.Groups var group = _remoteDatabaseContext.Groups
.FirstOrDefault(x => x.ID == groupID); .FirstOrDefault(x => x.ID == groupID);
if (group == null) return false; if (group == null) return false;
// Проверяем, есть ли связанные пользователи
if (group.Users != null && group.Users.Any()) if (group.Users != null && group.Users.Any())
{ {
return false; return false; // Нельзя удалить группу с пользователями
} }
_remoteDatabaseContext.Groups.Remove(group); _remoteDatabaseContext.Groups.Remove(group);
_remoteDatabaseContext.SaveChanges(); _remoteDatabaseContext.SaveChanges();
return true; return true;

View File

@ -1,7 +1,6 @@
using _123.Data.LocalData; using _123.Data.LocalData;
using _123.Data.LocalData.Entity; using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase; using _123.Data.RemoteData.RemoteDatabase;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -21,28 +20,28 @@ namespace _123.Data.Repository
public void AddPresence(PresenceDao presence) public void AddPresence(PresenceDao presence)
{ {
_remoteDatabaseContext.PresencesDaos.Add(presence); _remoteDatabaseContext.Presences.Add(presence);
_remoteDatabaseContext.SaveChanges(); _remoteDatabaseContext.SaveChanges();
} }
public List<PresenceDao> GetPresenceByGroup(int groupId) public List<PresenceDao> GetPresenceByGroup(int groupId)
{ {
return _remoteDatabaseContext.PresencesDaos return _remoteDatabaseContext.Presences
.Where(p => p.GroupId == groupId) .Where(p => p.GroupId == groupId)
.ToList(); .ToList();
} }
public List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date) public List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date)
{ {
return _remoteDatabaseContext.PresencesDaos return _remoteDatabaseContext.Presences
.Where(p => p.GroupId == groupId && p.Date == date) .Where(p => p.GroupId == groupId && p.Date == date)
.ToList(); .ToList();
} }
public bool UnCheckAttendence(int firstClass, int lastClass, DateOnly date, int userId) public bool UnCheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid)
{ {
var presToUpdate = _remoteDatabaseContext.PresencesDaos var presToUpdate = _remoteDatabaseContext.Presences
.Where(x => x.UserID == userId && x.LessonNumber >= firstClass .Where(x => x.UserGuid == userGuid && x.LessonNumber >= firstClass
&& x.LessonNumber <= lastClass && x.Date == date).ToList(); && x.LessonNumber <= lastClass && x.Date == date).ToList();
foreach (var presence in presToUpdate) foreach (var presence in presToUpdate)

View File

@ -1,7 +1,6 @@
using _123.Data.LocalData; using _123.Data.LocalData;
using _123.Data.LocalData.Entity; using _123.Data.LocalData.Entity;
using _123.Data.RemoteData.RemoteDatabase; using _123.Data.RemoteData.RemoteDatabase;
using _123.Data.RemoteData.RemoteDatabase.DAO;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -19,14 +18,14 @@ namespace _123.Data.Repository
_remoteDatabaseContext = remoteDatabaseContext; _remoteDatabaseContext = remoteDatabaseContext;
} }
public UserDao FindUserById(int userId) public UserDao FindUserByGuid(Guid userGuid)
{ {
var user = _remoteDatabaseContext.Users var user = _remoteDatabaseContext.Users
.FirstOrDefault(x => x.UserID == userId); .FirstOrDefault(x => x.UserID == userGuid);
if (user == null) throw new Exception("Пользователь не найден"); if (user == null) throw new Exception("Пользователь не найден");
return user; return user;
} }
public List<UserDao> GetAllUser() public List<UserDao> GetAllUser()
{ {
return _remoteDatabaseContext.Users return _remoteDatabaseContext.Users
@ -40,13 +39,13 @@ namespace _123.Data.Repository
.ToList(); .ToList();
} }
public UserDao? GetUserById(int userId) public UserDao? GetUserByGuid(int userId)
{ {
return _remoteDatabaseContext.Users return _remoteDatabaseContext.Users
.FirstOrDefault(x => x.UserID == userId); .FirstOrDefault(x => x.UserID == userId);
} }
public bool RemoveUserById(int userId) public bool RemoveUserByGuid(int userId)
{ {
try try
{ {
@ -84,7 +83,7 @@ namespace _123.Data.Repository
} }
} }
public UserDao? UpdateUserById(int userId) public UserDao? UpdateUserByGuid(int userId)
{ {
return _remoteDatabaseContext.Users return _remoteDatabaseContext.Users
.FirstOrDefault(x => x.UserID == userId); .FirstOrDefault(x => x.UserID == userId);

View File

@ -16,55 +16,55 @@ namespace _123.Data.ReportsHistory
public UserRepositoryImpl() public UserRepositoryImpl()
{ {
GetAllUsers = LocalStaticData.users.Select(it => new UserDao { GroupID = it.GroupID, UserFIO = it.UserFIO, UserID = it.UserId}).ToList(); GetAllUsers = LocalStaticData.users;
} }
public List<UserDao> GetAllUsers public List<UserLocalEntity> GetAllUsers
{ get; set; } { get; set; }
public List<UserDao> GetAllUser() public List<UserLocalEntity> GetAllUser()
{ {
return GetAllUsers; return GetAllUsers;
} }
public bool RemoveUserById(int userId) public bool RemoveUserByGuid(Guid userGuid)
{ {
UserDao? userLocal = GetAllUsers UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.UserID == userId).FirstOrDefault(); .Where(x => x.UserGuid == userGuid).FirstOrDefault();
if (userLocal == null) return false; if (userLocal == null) return false;
return GetAllUsers.Remove(userLocal); return GetAllUsers.Remove(userLocal);
} }
public UserDao FindUserById(int userId) public UserLocalEntity FindUserByGuid(Guid userGuid)
{ {
UserDao? userLocal = GetAllUsers UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.UserID == userId).FirstOrDefault(); .Where(x => x.UserGuid == userGuid).FirstOrDefault();
if (userLocal == null) throw new Exception("Пользователь не найден"); if (userLocal == null) throw new Exception("Пользователь не найден");
return userLocal; return userLocal;
} }
public UserDao? GetUserById(int userId) public UserLocalEntity? GetUserByGuid(Guid userGuid)
{ {
UserDao? userLocal = GetAllUsers UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.UserID == userId).FirstOrDefault(); .Where(x => x.UserGuid == userGuid).FirstOrDefault();
if (userLocal == null) return null; if (userLocal == null) return null;
return userLocal; return userLocal;
} }
public UserDao? UpdateUser(UserDao userUpdateDao) public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity)
{ {
UserDao? userLocal = GetAllUsers UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.UserID == userUpdateDao.UserID).FirstOrDefault(); .Where(x => x.UserGuid == userUpdateLocalEnity.UserGuid).FirstOrDefault();
if (userLocal == null) return null; if (userLocal == null) return null;
userLocal.UserFIO = userUpdateDao.UserFIO; userLocal.UserFIO = userUpdateLocalEnity.UserFIO;
userLocal.GroupID = userUpdateDao.GroupID; userLocal.GroupID = userUpdateLocalEnity.GroupID;
return userLocal; return userLocal;
} }
public UserDao? UpdateUserById(int userId) public UserLocalEntity? UpdateUserByGuid(Guid userGuid)
{ {
UserDao? userLocal = GetAllUsers UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.UserID == userId).FirstOrDefault(); .Where(x => x.UserGuid == userGuid).FirstOrDefault();
if (userLocal == null) return null; if (userLocal == null) return null;
return userLocal; return userLocal;

View File

@ -9,7 +9,7 @@ namespace _123.Domain.Models
public class User public class User
{ {
public required string UserFIO { get; set; } public required string UserFIO { get; set; }
public int UserID { get; set; } public Guid UserGuid { get; set; }
public required Group UserGroup { get; set; } public required Group UserGroup { get; set; }
} }

View File

@ -12,13 +12,13 @@ namespace _123.Domain.UseCase
{ {
public class GroupUseCase public class GroupUseCase
{ {
private readonly IGroupRepository _repositoryGroupImpl; private readonly SQLGroupRepositoryImpl _repositoryGroupImpl;
public GroupUseCase(IGroupRepository repositoryGroupImpl) public GroupUseCase(SQLGroupRepositoryImpl repositoryGroupImpl)
{ {
_repositoryGroupImpl = repositoryGroupImpl; _repositoryGroupImpl = repositoryGroupImpl;
} }
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup() public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new Group { ID = it.ID, Name = it.Name }).ToList(); .Select(it => new Group { ID = it.ID, Name = it.Name }).ToList();
public bool UpdateGroupName(string id, string name) public bool UpdateGroupName(string id, string name)
@ -42,5 +42,9 @@ namespace _123.Domain.UseCase
{ {
return _repositoryGroupImpl.RemoveGroupById(id); return _repositoryGroupImpl.RemoveGroupById(id);
} }
public GroupLocalEntity AddGroup(String name, string id)
{
return _repositoryGroupImpl.AddGroup(name, id);
}
} }
} }

View File

@ -13,50 +13,26 @@ namespace _123.Domain.UseCase
{ {
public class PresenceUseCase public class PresenceUseCase
{ {
private readonly IPresenceRepository _presenceRepositoryImpl; private readonly SQLPresenceRepositoryImpl _presenceRepositoryImpl;
private readonly IGroupRepository _groupRepositoryImpl; private readonly SQLGroupRepositoryImpl _groupRepositoryImpl;
private readonly IUserRepository _userRepositoryImpl; private readonly SQLUserRepositoryImpl _userRepositoryImpl;
public List<Presence> GetPresenceByGroup(int groupId) public List<Presence> GetPresenceByGroup(int groupId)
{ {
var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList(); var users = _userRepositoryImpl.GetAllUsers.Where(x => x.GroupID == groupId).ToList();
var presenceByGroup = _presenceRepositoryImpl.GetPresenceByGroup(groupId) var presenceByGroup = _presenceRepositoryImpl.GetPresenceByGroup(groupId)
.Where(x => users.Any(user => user.UserID == x.UserID)) .Where(x => users.Any(user => user.UserGuid == x.UserGuid))
.Select(presence => new Presence .Select(presence => new Presence
{ {
User = new User User = new User
{ {
UserID = presence.UserID, UserGuid = presence.UserGuid,
UserGroup = new Group UserGroup = new Group
{ {
ID = groupId, ID = groupId,
Name = _groupRepositoryImpl.GetAllGroup().First(group => group.ID == groupId).Name Name = _groupRepositoryImpl.GetAllGroups().First(group => group.ID == groupId).Name
}, },
UserFIO = users.First(user => user.UserID == presence.UserID).UserFIO, UserFIO = users.First(user => user.UserGuid == presence.UserGuid).UserFIO,
},
ClassNum = presence.LessonNumber,
Date = presence.Date,
IsAttedance = presence.IsAttedance,
}).ToList();
return (List<Presence>)presenceByGroup;
}
public List<Presence> GetPresenceByGroupAndDate(int groupId, DateOnly date)
{
var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList();
var presenceByGroup = _presenceRepositoryImpl.GetPresenceByGroup(groupId)
.Where(x => users.Any(user => user.UserID == x.UserID && x.Date == date))
.Select(presence => new Presence
{
User = new User
{
UserID = presence.UserID,
UserGroup = new Group
{
ID = groupId,
Name = _groupRepositoryImpl.GetAllGroup().First(group => group.ID == groupId).Name
},
UserFIO = users.First(user => user.UserID == presence.UserID).UserFIO,
}, },
ClassNum = presence.LessonNumber, ClassNum = presence.LessonNumber,
Date = presence.Date, Date = presence.Date,
@ -64,44 +40,34 @@ namespace _123.Domain.UseCase
}).ToList(); }).ToList();
return presenceByGroup; return presenceByGroup;
} }
public bool UnCheckAttendance(int firstClass, int lastClass, DateOnly date, int userID) public List<Presence> GetPresenceByGroupAndDate(int groupId, DateOnly date)
{ {
return _presenceRepositoryImpl.UnCheckAttendence(firstClass, lastClass, date, userID); var users = _userRepositoryImpl.GetAllUsers.Where(x => x.GroupID == groupId).ToList();
}
public Dictionary<string, int> GetPresenceStatsByGroup(int groupId) var presenceByGroup = _presenceRepositoryImpl.GetPresenceByGroup(groupId)
.Where(x => users.Any(user => user.UserGuid == x.UserGuid && x.Date == date))
.Select(presence => new Presence
{
User = new User
{
UserGuid = presence.UserGuid,
UserGroup = new Group
{
ID = groupId,
Name = _groupRepositoryImpl.GetAllGroups().First(group => group.ID == groupId).Name
},
UserFIO = users.First(user => user.UserGuid == presence.UserGuid).UserFIO,
},
ClassNum = presence.LessonNumber,
Date = presence.Date,
IsAttedance = presence.IsAttedance,
}).ToList();
return presenceByGroup;
}
public bool UnCheckAttendance(int firstClass, int lastClass, DateOnly date, Guid userGuid)
{ {
var stats = new Dictionary<string, int>(); return _presenceRepositoryImpl.UnCheckAttendence(firstClass, lastClass, date, userGuid);
// Получаем всех студентов группы
var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList();
stats["Количество студентов"] = users.Count;
// Получаем все записи посещаемости для группы
var presences = _presenceRepositoryImpl.GetPresenceByGroup(groupId);
// Считаем количество уникальных занятий
var uniqueLessons = presences
.Select(p => new { p.Date, p.LessonNumber })
.Distinct()
.Count();
stats["Количество занятий"] = uniqueLessons;
// Считаем общую посещаемость
var totalAttendances = presences.Count(p => p.IsAttedance);
var totalPossibleAttendances = users.Count * uniqueLessons;
if (totalPossibleAttendances > 0)
{
var attendancePercentage = (totalAttendances * 100) / totalPossibleAttendances;
stats["Процент посещаемости"] = attendancePercentage;
}
else
{
stats["Процент посещаемости"] = 0;
}
return stats;
} }
} }
} }

View File

@ -32,7 +32,7 @@ namespace _123.Domain.UseCase
{ {
foreach (var user in users) foreach (var user in users)
{ {
PresenceLocalEntity pres = new PresenceLocalEntity { LessonNumber = i, UserID = user.UserID, Date = date }; PresenceLocalEntity pres = new PresenceLocalEntity { LessonNumber = i, UserGuid = user.UserGuid, Date = date };
} }
} }
} }
@ -53,7 +53,7 @@ namespace _123.Domain.UseCase
PresenceLocalEntity pres = new PresenceLocalEntity PresenceLocalEntity pres = new PresenceLocalEntity
{ {
LessonNumber = i, LessonNumber = i,
UserID = user.UserID, UserGuid = user.UserGuid,
Date = date Date = date
}; };
presence.Add(pres); presence.Add(pres);

View File

@ -13,34 +13,34 @@ namespace _123.Domain.UseCase
{ {
public class UserUseCase public class UserUseCase
{ {
private readonly IUserRepository _repositoryUserImpl; private readonly SQLUserRepositoryImpl _repositoryUserImpl;
private readonly IGroupRepository _repositoryGroupImpl; private readonly SQLGroupRepositoryImpl _repositoryGroupImpl;
public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl) public UserUseCase(SQLUserRepositoryImpl repositoryImpl, SQLGroupRepositoryImpl repositoryGroupImpl)
{ {
_repositoryUserImpl = repositoryImpl; _repositoryUserImpl = repositoryImpl;
_repositoryGroupImpl = repositoryGroupImpl; _repositoryGroupImpl = repositoryGroupImpl;
} }
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup() public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.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() public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser()
.Join(_repositoryGroupImpl.GetAllGroup(), .Join(_repositoryGroupImpl.GetAllGroups(),
user => user.GroupID, user => user.GroupID,
group => group.ID, group => group.ID,
(user, group) => (user, group) =>
new User new User
{ {
UserFIO = user.UserFIO, UserFIO = user.UserFIO,
UserID = user.UserID, UserGuid = user.UserID,
UserGroup = new Group { ID = group.ID, Name = group.Name } UserGroup = new Group { ID = group.ID, Name = group.Name }
} }
).ToList(); ).ToList();
public bool RemoveUserByGuid(int userId) public bool RemoveUserByGuid(int userId)
{ {
return _repositoryUserImpl.RemoveUserById(userId); return _repositoryUserImpl.RemoveUserByGuid(userId);
} }
public User UpdateUser(User user) public User UpdateUser(User user)
@ -48,29 +48,23 @@ namespace _123.Domain.UseCase
UserDao userDao = new UserDao { UserDao userDao = new UserDao {
UserFIO = user.UserFIO, UserFIO = user.UserFIO,
GroupID = user.UserGroup.ID, GroupID = user.UserGroup.ID,
UserID = user.UserID UserID = user.UserGuid
}; };
UserDao? result = _repositoryUserImpl.UpdateUser(userDao); UserDao? result = _repositoryUserImpl.UpdateUser(userDao);
if (result == null) throw new Exception("Не удалось обновить пользователя"); if (result == null) throw new Exception("Не удалось обновить пользователя");
Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result.GroupID); Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result.GroupID);
if (group == null) throw new Exception("Группа не найдена"); if (group == null) throw new Exception("Группа не найдена");
return new User { UserFIO = user.UserFIO, UserID = user.UserID, UserGroup = group }; return new User { UserFIO = user.UserFIO, UserGuid = user.UserGuid, UserGroup = group };
} }
public User FindUserByGuid(int userId) public UserDao FindUserByGuid(int userId)
{ {
var userDao = _repositoryUserImpl.FindUserById(userId); return _repositoryUserImpl.FindUserByGuid(userId);
return new User
{
UserID = userDao.UserID,
UserFIO = userDao.UserFIO,
UserGroup = GetAllGroups().FirstOrDefault(g => g.ID == userDao.GroupID)
};
} }
public UserDao UpdateUserByGuid(int userId, string name, string groupId) public UserDao UpdateUserByGuid(int userId, string name, string groupId)
{ {
UserDao? result = _repositoryUserImpl.UpdateUserById(userId); UserDao? result = _repositoryUserImpl.UpdateUserByGuid(userId);
if (result == null) throw new Exception("Пользователь не найден"); if (result == null) throw new Exception("Пользователь не найден");
Group? group = GetAllGroups().FirstOrDefault(it => it.ID == int.Parse(groupId)); Group? group = GetAllGroups().FirstOrDefault(it => it.ID == int.Parse(groupId));
if (group == null) throw new Exception("Группа не найдена"); if (group == null) throw new Exception("Группа не найдена");

View File

@ -15,8 +15,15 @@ services
.AddDbContext<RemoteDatabaseContext>() .AddDbContext<RemoteDatabaseContext>()
.AddSingleton<IPresenceRepository, SQLPresenceRepositoryImpl>() .AddSingleton<IPresenceRepository, SQLPresenceRepositoryImpl>()
.AddSingleton<IUserRepository, SQLUserRepositoryImpl>() .AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
.AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>(); .AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>()
var serviceProvider = services.BuildServiceProvider (); var serviceProvider = services.BuildServiceProvider ();
var mainMenuUI = serviceProvider.GetRequiredService<MainMenuUI>(); GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);
GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl);
PresenceRepositoryImpl presenceRepositoryImpl = new PresenceRepositoryImpl();
PresenceUseCase presenceUseCase = new PresenceUseCase();
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase, presenceUseCase);

View File

@ -31,10 +31,16 @@ namespace _123.UI
} }
public void AddGroup (String name, String id) public void AddGroup (String name, String id)
{ {
string output = _groupUseCase.AddGroup(name , id) ? "Группа добавлена" : "Группа не добавлена"; StringBuilder groupOutput = new StringBuilder();
Console.WriteLine(output); var group = _groupUseCase.AddGroup(name,id);
<<<<<<< HEAD
=======
{
groupOutput.AppendLine($"{group.Name}\t{group.ID}");
}
Console.WriteLine(groupOutput);
>>>>>>> b274d8f88d0df85505fa497de11d07625bde956d
} }
} }
} }

View File

@ -33,7 +33,7 @@ namespace _123.UI
switch (Console.ReadLine()) switch (Console.ReadLine())
{ {
case "1": _userConsoleUI.DisplayAllUsers(); break; case "1": _userConsoleUI.DisplayAllUsers(); break;
case "2": _userConsoleUI.RemoveUserById(int.Parse(Console.ReadLine())); break; case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "3": _groupConsoleUI.DisplayAllGroups(); break; case "3": _groupConsoleUI.DisplayAllGroups(); break;
case "4": _userConsoleUI.FindUserById(int.Parse(Console.ReadLine())); break; case "4": _userConsoleUI.FindUserById(int.Parse(Console.ReadLine())); break;
case "5": _userConsoleUI.UpdateUserById(int.Parse(Console.ReadLine()), Console.ReadLine(), Console.ReadLine()); break; case "5": _userConsoleUI.UpdateUserById(int.Parse(Console.ReadLine()), Console.ReadLine(), Console.ReadLine()); break;
@ -41,7 +41,7 @@ namespace _123.UI
case "7": _groupConsoleUI.AddGroup(Console.ReadLine(), Console.ReadLine()); break; case "7": _groupConsoleUI.AddGroup(Console.ReadLine(), Console.ReadLine()); break;
case "8": _presenceConsoleUI.GetPresenceByGroup(int.Parse(Console.ReadLine())); break; case "8": _presenceConsoleUI.GetPresenceByGroup(int.Parse(Console.ReadLine())); break;
case "9": _presenceConsoleUI.GetPresenceByGroupAndDAte(int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine())); break; case "9": _presenceConsoleUI.GetPresenceByGroupAndDAte(int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine())); break;
case "10": _presenceConsoleUI.UnCheckAttendence(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine()), int.Parse(Console.ReadLine())); break; case "10": _presenceConsoleUI.UnCheckAttendence(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine()), Guid.Parse(Console.ReadLine())); break;
case "11": _presenceConsoleUI.AddPresence(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine())); break; case "11": _presenceConsoleUI.AddPresence(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine())); break;
default: default:

View File

@ -11,7 +11,6 @@ namespace _123.UI
{ {
PresenceUseCase _presenceUseCase; PresenceUseCase _presenceUseCase;
UseCaseGeneratePresence _useCaseGeneratePresence; UseCaseGeneratePresence _useCaseGeneratePresence;
private PresenceUseCase presenceUseCase;
public PresenceConsoleUI(PresenceUseCase presenceUseCase, UseCaseGeneratePresence useCaseGeneratePresence) public PresenceConsoleUI(PresenceUseCase presenceUseCase, UseCaseGeneratePresence useCaseGeneratePresence)
{ {
@ -19,18 +18,13 @@ namespace _123.UI
_useCaseGeneratePresence = useCaseGeneratePresence; _useCaseGeneratePresence = useCaseGeneratePresence;
} }
public PresenceConsoleUI(PresenceUseCase presenceUseCase)
{
this.presenceUseCase = presenceUseCase;
}
public void GetPresenceByGroup(int groupId) public void GetPresenceByGroup(int groupId)
{ {
StringBuilder presenceOutput = new StringBuilder(); StringBuilder presenceOutput = new StringBuilder();
var presence = _presenceUseCase.GetPresenceByGroup(groupId); var presence = _presenceUseCase.GetPresenceByGroup(groupId);
foreach (var p in presence) foreach (var p in presence)
{ {
presenceOutput.AppendLine($"{p.ClassNum}\t{p.User}\t{p.Date}"); presenceOutput.AppendLine($"{p.LessonNumber}\t{p.UserGuid}\t{p.Date}");
} }
Console.WriteLine(presenceOutput); Console.WriteLine(presenceOutput);
} }
@ -41,14 +35,14 @@ namespace _123.UI
var presence = _presenceUseCase.GetPresenceByGroupAndDate(groupId, date); var presence = _presenceUseCase.GetPresenceByGroupAndDate(groupId, date);
foreach (var p in presence) foreach (var p in presence)
{ {
presenceOutput.AppendLine($"{p.ClassNum}\t{p.User}\t{p.Date}"); presenceOutput.AppendLine($"{p.LessonNumber}\t{p.UserGuid}\t{p.Date}");
} }
Console.WriteLine(presenceOutput); Console.WriteLine(presenceOutput);
} }
public void UnCheckAttendence(int firstClass, int lastClass, DateOnly date, int userId) public void UnCheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid)
{ {
var result = _presenceUseCase.UnCheckAttendance(firstClass, lastClass, date, userId); var result = _presenceUseCase.UnCheckAttendance(firstClass, lastClass, date, userGuid);
Console.WriteLine(result ? "Посещаемость успешно обновлена" : "Ошибка при обновлении посещаемости"); Console.WriteLine(result ? "Посещаемость успешно обновлена" : "Ошибка при обновлении посещаемости");
} }
@ -64,36 +58,27 @@ namespace _123.UI
Console.WriteLine($"Ошибка при добавлении посещаемости: {ex.Message}"); Console.WriteLine($"Ошибка при добавлении посещаемости: {ex.Message}");
} }
} }
public void GetPresenceStatsByGroup(int groupId) public void GetGroupAttendanceStats(int groupId)
{ {
var stats = _presenceUseCase.GetPresenceStatsByGroup(groupId); StringBuilder statsOutput = new StringBuilder();
StringBuilder output = new StringBuilder(); var groupStats = _presenceUseCase.GetGroupStats(groupId);
output.AppendLine($"Информация о группе {groupId}:"); statsOutput.AppendLine($"Информация о группе {groupStats.GroupName}:");
output.AppendLine($"Количество студентов: {stats["Количество студентов"]}"); statsOutput.AppendLine($"Количество студентов: {groupStats.StudentsCount}");
output.AppendLine($"Количество занятий: {stats["Количество занятий"]}"); statsOutput.AppendLine($"Количество проведенных занятий: {groupStats.TotalLessons}");
output.AppendLine($"Общий процент посещаемости: {stats["Процент посещаемости"]}%"); statsOutput.AppendLine($"Общий процент посещаемости: {groupStats.TotalAttendancePercent:F1}%");
output.AppendLine("\nСтатистика по студентам:"); statsOutput.AppendLine("\nСтатистика по студентам:");
statsOutput.AppendLine("ФИО\tПосещено\tПропущено\tПроцент посещаемости");
var presence = _presenceUseCase.GetPresenceByGroup(groupId);
var students = presence.GroupBy(p => p.User) foreach(var student in groupStats.StudentStats)
.Select(g => new {
Student = g.Key,
Total = stats["Количество занятий"],
Attended = g.Count(p => p.IsAttedance),
Missed = stats["Количество занятий"] - g.Count(p => p.IsAttedance),
Percentage = (g.Count(p => p.IsAttedance) * 100) / stats["Количество занятий"]
});
foreach (var student in students)
{ {
output.AppendLine($"\nСтудент: {student.Student.UserFIO}"); statsOutput.AppendLine(
output.AppendLine($"Посещено занятий: {student.Attended}"); $"{student.StudentName}\t{student.AttendedLessons}\t" +
output.AppendLine($"Пропущено занятий: {student.Missed}"); $"{student.MissedLessons}\t{student.AttendancePercent:F1}%"
output.AppendLine($"Процент посещаемости: {student.Percentage}%"); );
} }
Console.WriteLine(output.ToString()); Console.WriteLine(statsOutput.ToString());
} }
} }

View File

@ -37,7 +37,7 @@ namespace _123.UI
{ {
StringBuilder userOutput = new StringBuilder(); StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.FindUserByGuid(userId); var user = _userUseCase.FindUserByGuid(userId);
userOutput.AppendLine($"{user.UserID}\t{user.UserFIO}\t{user.UserGroup}"); userOutput.AppendLine($"{user.UserID}\t{user.UserFIO}\t{user.GroupID}");
Console.WriteLine(userOutput); Console.WriteLine(userOutput);
} }