This commit is contained in:
Userok 2024-11-11 14:41:23 +03:00
parent 016a872d76
commit 23b7c0caff
12 changed files with 144 additions and 49 deletions

View File

@ -1,10 +1,11 @@
using Zurnal.Date.LocalDate;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Data.Repository
namespace Zurnal.Date.Repository.SQLRepos
{
public class SQLGroupRepositoryImpl:IGroupRepository
public class SQLGroupRepositoryImpl : IGroupRepository
{
private readonly RemoteDateBaseContext _remoteDataBaseContext;
@ -14,6 +15,8 @@ namespace Data.Repository
public List<GroupDao> AllGroup => throw new NotImplementedException();
List<GroupDao> IGroupRepository.AllGroup => throw new NotImplementedException();
public bool AddGroup(GroupLocalEntity newGroup)
{
GroupDao groupDao = new GroupDao { GroupName = newGroup.Name };
@ -34,41 +37,10 @@ namespace Data.Repository
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity GetGroupById(int groupID)
List<GroupLocalEntity> IGroupRepository.GetAllGroup()
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
{
throw new NotImplementedException();
}
}
public class SQLPresenceRepositoryImpl: IPresenceRepository
{
private readonly RemoteDateBaseContext _remoteDatabaseContext;
public SQLPresenceRepositoryImpl(RemoteDateBaseContext remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
public DateOnly? GetLastDateByGroupId(int groupId)
{
var lastDate = _remoteDatabaseContext.Presence
.Where(p => p.GroupId == groupId)
.OrderByDescending(p => p.Date)
.Select(p => p.Date)
.FirstOrDefault();
return lastDate == default ? (DateOnly?)null : lastDate;
}
}
}

View File

@ -0,0 +1,49 @@
using Zurnal.Date.LocalDate;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Date.Repository.SQLRepos
{
public class SQLPresenceRepositoryImpl : IPresenceRepository
{
private readonly RemoteDateBaseContext _remoteDataBaseContext;
public SQLPresenceRepositoryImpl(RemoteDateBaseContext remoteDataBaseContext) {
_remoteDataBaseContext = remoteDataBaseContext;
}
public void AddPresence(PresnceDao presence)
{
var result = _remoteDataBaseContext.Presence.Add(presence);
if (result != null) {
_remoteDataBaseContext.SaveChanges();
}
}
public PresnceDao GetPresenceById(int id)
{
return _remoteDataBaseContext.Presence.Find(id);
}
public IEnumerable<PresnceDao> GetAllPresences()
{
return _remoteDataBaseContext.Presence.ToList();
}
public void UpdatePresence(PresnceDao presence)
{
_remoteDataBaseContext.Presence.Update(presence);
_remoteDataBaseContext.SaveChanges();
}
public void DeletePresence(int id)
{
var presence = GetPresenceById(id);
if (presence != null)
{
_remoteDataBaseContext.Presence.Remove(presence);
_remoteDataBaseContext.SaveChanges();
}
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Zurnal.Data.Repository;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Date.Repository.SQLRepos
{
public class SQLUserRepositoryImpl : IUserRepository
{
private readonly RemoteDateBaseContext _remoteDataBaseContext;
public SQLUserRepositoryImpl(RemoteDateBaseContext remoteDataBaseContext)
{
_remoteDataBaseContext = remoteDataBaseContext;
}
public List<UserDao> GetAllUsers =>
_remoteDataBaseContext.User.Select(user => new UserDao
{
UserGuid = user.UserGuid,
FIO = user.FIO,
GroupID = user.GroupID,
}).ToList();
public bool RemoveUserByGuid(Guid userGuid)
{
var user = _remoteDataBaseContext.User.Find(userGuid);
if (user == null) return false;
_remoteDataBaseContext.User.Remove(user);
_remoteDataBaseContext.SaveChanges();
return true;
}
public UserDao? GetUserByGuid(Guid userGuid)
{
var user = _remoteDataBaseContext.User.Find(userGuid);
if (user == null) return null;
return new UserDao
{
UserGuid = user.UserGuid,
FIO = user.FIO,
GroupID = user.GroupID,
};
}
public UserDao? UpdateUser(UserDao userUpdateLocalEnity)
{
var user = _remoteDataBaseContext.User.Find(userUpdateLocalEnity.UserGuid);
if (user == null) return null;
user.FIO = userUpdateLocalEnity.FIO;
user.GroupID = userUpdateLocalEnity.GroupID;
_remoteDataBaseContext.SaveChanges();
return userUpdateLocalEnity;
}
}
}

View File

@ -1,9 +1,13 @@
using Data.Repository;
using Zurnal.Data.Repository;
using Zurnal.Data.Repository;
using Zurnal.Date.Repository.SQLRepos;
using Zurnal.Domain.UseCase;
using Zurnal.Presence;
using Zurnal.UI;
class Programka
{
static void Main(string[] args)
{
IServiceCollection services = new ServiceCollection();
services
@ -20,3 +24,5 @@ var serviceProvider = services.BuildServiceProvider();
MainMenuUI mainMenuUI = serviceProvider.GetService<MainMenuUI>();
mainMenuUI.DisplayMenu();
}
}

View File

@ -6,5 +6,5 @@
public Guid UserGuid { get; set; }
public GroupDao Group { get; set; }
public required int GroupID { get; set; }
}
}
}

View File

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

View File

@ -7,9 +7,9 @@ namespace Zurnal.Data.Repository
{
public interface IUserRepository
{
List<UserLocalEnity> GetAllUsers { get; }
List<UserDao> GetAllUsers { get; }
bool RemoveUserByGuid(Guid userGuid);
UserLocalEnity? GetUserByGuid(Guid userGuid);
UserLocalEnity? UpdateUser(UserLocalEnity userUpdateLocalEnity);
UserDao? GetUserByGuid(Guid userGuid);
UserDao? UpdateUser(UserDao userUpdateLocalEnity);
}
}

View File

@ -6,7 +6,6 @@ public class RemoteDateBaseContext : DbContext
public DbSet<GroupDao> Group { get; set; }
public DbSet<UserDao> User { get; set; }
public DbSet<PresnceDao> Presence { get; set; }
public object Groups { get; internal set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{

View File

@ -13,7 +13,7 @@ namespace Zurnal.UI
}
private void DisplayMenu()
public void DisplayMenu()
{
while (true)
{
@ -26,9 +26,8 @@ namespace Zurnal.UI
DisplayMenu();
break;
}
}
}
}
}

View File

@ -1 +1 @@
e7472ea1c8f499a7ec454e6a70d834c4f0deb35d64d70c46a4cd5bc76239a16e
363301da55cc0da9a5b5db64cdaad65e5fa588627917582d0f884f0b7608c9c8

View File

@ -1,6 +1,5 @@
using Data.Repository;
using domain;
using Zurnal.Date.Repository.SQLRepos;
using Zurnal.Domain.UseCase;
public static class ServiceExtensions {
public static void ConfigurateGroup(this IServiceCollection services){

View File

@ -1 +1 @@
IServiceCollection
MainMenuUI