This commit is contained in:
Userok 2024-11-06 12:41:04 +03:00
parent 4f7ef7ffb2
commit 979f0a84e8
6 changed files with 165 additions and 16 deletions

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

@ -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+4f7ef7ffb28283c7077607579022f64cf7ddd780")]
[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 0c70dc958a2438c97ce99e147330083f09b6a5a64e1928d9238f0aae829439d3