Compare commits
3 Commits
b274d8f88d
...
14271607f2
Author | SHA1 | Date | |
---|---|---|---|
|
14271607f2 | ||
|
ab637e3bbc | ||
|
5d31067f6b |
@ -1,4 +1,5 @@
|
||||
using _123.Data.LocalData.Entity;
|
||||
using _123.Data.RemoteData.RemoteDatabase.DAO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
15
123/Data/RemoteData/RemoteDatabase/DAO/Group.cs
Normal file
15
123/Data/RemoteData/RemoteDatabase/DAO/Group.cs
Normal 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; }
|
||||
}
|
||||
}
|
19
123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs
Normal file
19
123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs
Normal file
@ -0,0 +1,19 @@
|
||||
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 bool IsAttedance { get; set; } = true;
|
||||
public required DateOnly Date { get; set; }
|
||||
|
||||
public required int LessonNumber { get; set; }
|
||||
public UserDao UserDao { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public int GroupId { get; set; }
|
||||
}
|
||||
}
|
18
123/Data/RemoteData/RemoteDatabase/DAO/User.cs
Normal file
18
123/Data/RemoteData/RemoteDatabase/DAO/User.cs
Normal 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 int UserID { get; set; }
|
||||
|
||||
public required int GroupID { get; set; }
|
||||
|
||||
public GroupDao Group { get; set; }
|
||||
}
|
||||
}
|
36
123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs
Normal file
36
123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs
Normal 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
|
||||
{
|
||||
public 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; }
|
||||
}
|
||||
}
|
||||
|
55
123/Data/Repository/GroupRepositoty.cs
Normal file
55
123/Data/Repository/GroupRepositoty.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
19
123/Data/Repository/IGroupRepository.cs
Normal file
19
123/Data/Repository/IGroupRepository.cs
Normal 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<GroupDao> GetAllGroup();
|
||||
bool RemoveGroupById(int groupID);
|
||||
bool UpdateGroupById(int groupID, String name);
|
||||
GroupDao GetGroupById(int groupID);
|
||||
bool AddGroup(String name, String id);
|
||||
}
|
||||
}
|
19
123/Data/Repository/IPresenceRepository.cs
Normal file
19
123/Data/Repository/IPresenceRepository.cs
Normal 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
|
||||
{
|
||||
internal interface IPresenceRepository
|
||||
{
|
||||
List<PresenceDao> GetPresenceByGroup(int groupId);
|
||||
List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date);
|
||||
bool UnCheckAttendence (int firstClass, int lastClass, DateOnly date, Guid userGuid);
|
||||
void AddPresence (PresenceDao presence);
|
||||
|
||||
}
|
||||
}
|
20
123/Data/Repository/IUserRepository.cs
Normal file
20
123/Data/Repository/IUserRepository.cs
Normal 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
|
||||
{
|
||||
List<UserDao> GetAllUser();
|
||||
bool RemoveUserByGuid(int userId);
|
||||
UserDao FindUserByGuid(Guid userGuid);
|
||||
UserDao? GetUserByGuid(int userId);
|
||||
UserDao? UpdateUser(UserDao userUpdate);
|
||||
UserDao? UpdateUserByGuid(int userId);
|
||||
}
|
||||
}
|
57
123/Data/Repository/PresenceRepository.cs
Normal file
57
123/Data/Repository/PresenceRepository.cs
Normal file
@ -0,0 +1,57 @@
|
||||
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.Text.RegularExpressions;
|
||||
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)
|
||||
{
|
||||
return GetAllPresences;
|
||||
}
|
||||
|
||||
public List<PresenceLocalEntity> GetPresenceByGroupAndDate(int groupId, DateOnly date)
|
||||
{
|
||||
return GetAllPresences;
|
||||
}
|
||||
|
||||
public bool UnCheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid)
|
||||
{
|
||||
var presToUpdate = GetAllPresences
|
||||
.Where(x => x.UserGuid == userGuid && x.LessonNumber >= firstClass
|
||||
&& x.LessonNumber <= lastClass && x.Date == date).ToList();
|
||||
foreach (var presence in presToUpdate)
|
||||
{
|
||||
presence.IsAttedance = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
114
123/Data/Repository/SQLGroupRepository.cs
Normal file
114
123/Data/Repository/SQLGroupRepository.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using _123.Data.LocalData;
|
||||
using _123.Data.LocalData.Entity;
|
||||
using _123.Data.RemoteData.RemoteDatabase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.Data.Repository
|
||||
{
|
||||
public class SQLGroupRepositoryImpl : IGroupRepository
|
||||
{
|
||||
private readonly RemoteDatabaseContext _remoteDatabaseContext;
|
||||
|
||||
public SQLGroupRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext)
|
||||
{
|
||||
_remoteDatabaseContext = remoteDatabaseContext;
|
||||
}
|
||||
|
||||
public List<GroupDao> GetAllGroups()
|
||||
{
|
||||
var groups = _remoteDatabaseContext.Groups
|
||||
.Select(g => new GroupDao
|
||||
{
|
||||
ID = g.ID,
|
||||
Name = g.Name
|
||||
})
|
||||
.ToList();
|
||||
return groups;
|
||||
}
|
||||
|
||||
public bool AddGroup(string name, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var groupDao = new GroupDao
|
||||
{
|
||||
ID = int.Parse(id),
|
||||
Name = name,
|
||||
Users = new List<UserDao>()
|
||||
};
|
||||
_remoteDatabaseContext.Groups.Add(groupDao);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<GroupDao> GetAllGroup()
|
||||
{
|
||||
return GetAllGroups();
|
||||
}
|
||||
|
||||
public GroupDao GetGroupById(int groupID)
|
||||
{
|
||||
var group = _remoteDatabaseContext.Groups
|
||||
.FirstOrDefault(x => x.ID == groupID);
|
||||
|
||||
if (group == null) return null;
|
||||
|
||||
return new GroupDao
|
||||
{
|
||||
ID = group.ID,
|
||||
Name = group.Name
|
||||
};
|
||||
}
|
||||
|
||||
public bool RemoveGroupById(int groupID)
|
||||
{
|
||||
try
|
||||
{
|
||||
var group = _remoteDatabaseContext.Groups
|
||||
.FirstOrDefault(x => x.ID == groupID);
|
||||
if (group == null) return false;
|
||||
|
||||
// Проверяем, есть ли связанные пользователи
|
||||
if (group.Users != null && group.Users.Any())
|
||||
{
|
||||
return false; // Нельзя удалить группу с пользователями
|
||||
}
|
||||
|
||||
_remoteDatabaseContext.Groups.Remove(group);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateGroupById(int groupID, string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
var group = _remoteDatabaseContext.Groups
|
||||
.FirstOrDefault(x => x.ID == groupID);
|
||||
if (group == null) return false;
|
||||
|
||||
group.Name = name;
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
123/Data/Repository/SQLPresenceRepository.cs
Normal file
56
123/Data/Repository/SQLPresenceRepository.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using _123.Data.LocalData;
|
||||
using _123.Data.LocalData.Entity;
|
||||
using _123.Data.RemoteData.RemoteDatabase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.Data.Repository
|
||||
{
|
||||
public class SQLPresenceRepositoryImpl : IPresenceRepository
|
||||
{
|
||||
private readonly RemoteDatabaseContext _remoteDatabaseContext;
|
||||
|
||||
public SQLPresenceRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext)
|
||||
{
|
||||
_remoteDatabaseContext = remoteDatabaseContext;
|
||||
}
|
||||
|
||||
public void AddPresence(PresenceDao presence)
|
||||
{
|
||||
_remoteDatabaseContext.Presences.Add(presence);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
}
|
||||
|
||||
public List<PresenceDao> GetPresenceByGroup(int groupId)
|
||||
{
|
||||
return _remoteDatabaseContext.Presences
|
||||
.Where(p => p.GroupId == groupId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date)
|
||||
{
|
||||
return _remoteDatabaseContext.Presences
|
||||
.Where(p => p.GroupId == groupId && p.Date == date)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool UnCheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid)
|
||||
{
|
||||
var presToUpdate = _remoteDatabaseContext.Presences
|
||||
.Where(x => x.UserGuid == userGuid && x.LessonNumber >= firstClass
|
||||
&& x.LessonNumber <= lastClass && x.Date == date).ToList();
|
||||
|
||||
foreach (var presence in presToUpdate)
|
||||
{
|
||||
presence.IsAttedance = false;
|
||||
}
|
||||
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
92
123/Data/Repository/SQLUserRepository.cs
Normal file
92
123/Data/Repository/SQLUserRepository.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using _123.Data.LocalData;
|
||||
using _123.Data.LocalData.Entity;
|
||||
using _123.Data.RemoteData.RemoteDatabase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.Data.Repository
|
||||
{
|
||||
public class SQLUserRepositoryImpl : IUserRepository
|
||||
{
|
||||
private readonly RemoteDatabaseContext _remoteDatabaseContext;
|
||||
|
||||
public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext)
|
||||
{
|
||||
_remoteDatabaseContext = remoteDatabaseContext;
|
||||
}
|
||||
|
||||
public UserDao FindUserByGuid(Guid userGuid)
|
||||
{
|
||||
var user = _remoteDatabaseContext.Users
|
||||
.FirstOrDefault(x => x.UserID == userGuid);
|
||||
if (user == null) throw new Exception("Пользователь не найден");
|
||||
return user;
|
||||
}
|
||||
|
||||
public List<UserDao> GetAllUser()
|
||||
{
|
||||
return _remoteDatabaseContext.Users
|
||||
.Select(u => new UserDao
|
||||
{
|
||||
UserID = u.UserID,
|
||||
UserFIO = u.UserFIO,
|
||||
GroupID = u.GroupID,
|
||||
Group = u.Group
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public UserDao? GetUserByGuid(int userId)
|
||||
{
|
||||
return _remoteDatabaseContext.Users
|
||||
.FirstOrDefault(x => x.UserID == userId);
|
||||
}
|
||||
|
||||
public bool RemoveUserByGuid(int userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = _remoteDatabaseContext.Users
|
||||
.FirstOrDefault(x => x.UserID == userId);
|
||||
if (user == null) return false;
|
||||
|
||||
_remoteDatabaseContext.Users.Remove(user);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public UserDao? UpdateUser(UserDao userUpdate)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = _remoteDatabaseContext.Users
|
||||
.FirstOrDefault(x => x.UserID == userUpdate.UserID);
|
||||
if (user == null) return null;
|
||||
|
||||
user.UserFIO = userUpdate.UserFIO;
|
||||
user.GroupID = userUpdate.GroupID;
|
||||
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return user;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public UserDao? UpdateUserByGuid(int userId)
|
||||
{
|
||||
return _remoteDatabaseContext.Users
|
||||
.FirstOrDefault(x => x.UserID == userId);
|
||||
}
|
||||
}
|
||||
}
|
@ -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()
|
||||
{
|
||||
@ -19,6 +21,10 @@ namespace _123.Data.ReportsHistory
|
||||
public List<UserLocalEntity> GetAllUsers
|
||||
{ get; set; }
|
||||
|
||||
public List<UserLocalEntity> GetAllUser()
|
||||
{
|
||||
return GetAllUsers;
|
||||
}
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
UserLocalEntity? userLocal = GetAllUsers
|
||||
@ -63,6 +69,5 @@ namespace _123.Data.ReportsHistory
|
||||
return userLocal;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
@ -6,31 +6,45 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using _123.Domain.Models;
|
||||
using _123.Data.LocalData.Entity;
|
||||
using _123.Data.Repository;
|
||||
|
||||
namespace _123.Domain.UseCase
|
||||
{
|
||||
public class GroupUseCase
|
||||
{
|
||||
private GroupRepositoryImpl _repositoryGroupImpl;
|
||||
public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl)
|
||||
private readonly SQLGroupRepositoryImpl _repositoryGroupImpl;
|
||||
public GroupUseCase(SQLGroupRepositoryImpl repositoryGroupImpl)
|
||||
{
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
}
|
||||
|
||||
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 name)
|
||||
{
|
||||
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), name);
|
||||
}
|
||||
|
||||
public bool AddGroup(string name, string id)
|
||||
{
|
||||
return _repositoryGroupImpl.AddGroup(name, id);
|
||||
}
|
||||
|
||||
public Group GetGroupById(int id)
|
||||
{
|
||||
var group = _repositoryGroupImpl.GetGroupById(id);
|
||||
if (group == null) return null;
|
||||
return new Group { ID = group.ID, Name = group.Name };
|
||||
}
|
||||
|
||||
public bool RemoveGroupById(int id)
|
||||
{
|
||||
return _repositoryGroupImpl.RemoveGroupById(id);
|
||||
}
|
||||
public GroupLocalEntity AddGroup(String name, string id)
|
||||
{
|
||||
return _repositoryGroupImpl.AddGroup(name, id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
73
123/Domain/UseCase/PresenceUseCase.cs
Normal file
73
123/Domain/UseCase/PresenceUseCase.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using _123.Data.LocalData.Entity;
|
||||
using _123.Data.ReportsHistory;
|
||||
using _123.Data.Repository;
|
||||
using _123.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.Domain.UseCase
|
||||
{
|
||||
public class PresenceUseCase
|
||||
{
|
||||
private readonly SQLPresenceRepositoryImpl _presenceRepositoryImpl;
|
||||
private readonly SQLGroupRepositoryImpl _groupRepositoryImpl;
|
||||
private readonly SQLUserRepositoryImpl _userRepositoryImpl;
|
||||
public List<Presence> GetPresenceByGroup(int groupId)
|
||||
{
|
||||
var users = _userRepositoryImpl.GetAllUsers.Where(x => x.GroupID == groupId).ToList();
|
||||
|
||||
var presenceByGroup = _presenceRepositoryImpl.GetPresenceByGroup(groupId)
|
||||
.Where(x => users.Any(user => user.UserGuid == x.UserGuid))
|
||||
.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 List<Presence> GetPresenceByGroupAndDate(int groupId, DateOnly date)
|
||||
{
|
||||
var users = _userRepositoryImpl.GetAllUsers.Where(x => x.GroupID == groupId).ToList();
|
||||
|
||||
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)
|
||||
{
|
||||
return _presenceRepositoryImpl.UnCheckAttendence(firstClass, lastClass, date, userGuid);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
67
123/Domain/UseCase/UseCaseGeneratePresence.cs
Normal file
67
123/Domain/UseCase/UseCaseGeneratePresence.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using _123.Data.LocalData.Entity;
|
||||
using _123.Data.ReportsHistory;
|
||||
using _123.Data.Repository;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.Domain.UseCase
|
||||
{
|
||||
public class UseCaseGeneratePresence
|
||||
{
|
||||
private readonly PresenceRepositoryImpl _presenceRepositoryImpl;
|
||||
private readonly GroupRepositoryImpl _groupRepositoryImpl;
|
||||
private readonly UserRepositoryImpl _userRepositoryImpl;
|
||||
|
||||
public UseCaseGeneratePresence(PresenceRepositoryImpl repositoryImpl,
|
||||
UserRepositoryImpl userRepositoryImpl,
|
||||
GroupRepositoryImpl groupRepositoryImpl)
|
||||
{
|
||||
_presenceRepositoryImpl = repositoryImpl;
|
||||
_userRepositoryImpl = userRepositoryImpl;
|
||||
_groupRepositoryImpl = groupRepositoryImpl;
|
||||
}
|
||||
|
||||
public void AddPrecence(int firstClass, int lastClass, int groupId, DateOnly date)
|
||||
{
|
||||
var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList();
|
||||
List<PresenceLocalEntity> presence = new List<PresenceLocalEntity>();
|
||||
for (int i = firstClass; i < lastClass; i++)
|
||||
{
|
||||
foreach (var user in users)
|
||||
{
|
||||
PresenceLocalEntity pres = new PresenceLocalEntity { LessonNumber = i, UserGuid = user.UserGuid, Date = date };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPresenceForWeek(int firstClass, int lastClass, int groupId, DateOnly startDate)
|
||||
{
|
||||
var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList();
|
||||
List<PresenceLocalEntity> presence = new List<PresenceLocalEntity>();
|
||||
|
||||
for (int dayOffset = 0; dayOffset < 7; dayOffset++)
|
||||
{
|
||||
DateOnly date = startDate.AddDays(dayOffset);
|
||||
|
||||
for (int i = firstClass; i < lastClass; i++)
|
||||
{
|
||||
foreach (var user in users)
|
||||
{
|
||||
PresenceLocalEntity pres = new PresenceLocalEntity
|
||||
{
|
||||
LessonNumber = i,
|
||||
UserGuid = user.UserGuid,
|
||||
Date = date
|
||||
};
|
||||
presence.Add(pres);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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,10 +13,10 @@ namespace _123.Domain.UseCase
|
||||
{
|
||||
public class UserUseCase
|
||||
{
|
||||
private UserRepositoryImpl _repositoryUserImpl;
|
||||
private GroupRepositoryImpl _repositoryGroupImpl;
|
||||
private readonly SQLUserRepositoryImpl _repositoryUserImpl;
|
||||
private readonly SQLGroupRepositoryImpl _repositoryGroupImpl;
|
||||
|
||||
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
|
||||
public UserUseCase(SQLUserRepositoryImpl repositoryImpl, SQLGroupRepositoryImpl repositoryGroupImpl)
|
||||
{
|
||||
_repositoryUserImpl = repositoryImpl;
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
@ -22,7 +24,8 @@ namespace _123.Domain.UseCase
|
||||
|
||||
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
|
||||
.Select(it => new Group { ID = it.ID, Name = it.Name }).ToList();
|
||||
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
|
||||
|
||||
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser()
|
||||
.Join(_repositoryGroupImpl.GetAllGroups(),
|
||||
user => user.GroupID,
|
||||
group => group.ID,
|
||||
@ -30,35 +33,42 @@ namespace _123.Domain.UseCase
|
||||
new User
|
||||
{
|
||||
UserFIO = user.UserFIO,
|
||||
UserGuid = user.UserGuid,
|
||||
UserGuid = user.UserID,
|
||||
UserGroup = new Group { ID = group.ID, Name = group.Name }
|
||||
}
|
||||
).ToList();
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
public bool RemoveUserByGuid(int userId)
|
||||
{
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userId);
|
||||
}
|
||||
|
||||
public User UpdateUser(User user)
|
||||
{
|
||||
UserLocalEntity userLocalEnity = new UserLocalEntity { UserFIO = user.UserFIO, GroupID = user.UserGroup.ID, UserGuid = user.UserGuid };
|
||||
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEnity);
|
||||
if (result == null) throw new Exception("");
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result!.GroupID);
|
||||
if (group == null) throw new Exception("");
|
||||
UserDao userDao = new UserDao {
|
||||
UserFIO = user.UserFIO,
|
||||
GroupID = user.UserGroup.ID,
|
||||
UserID = user.UserGuid
|
||||
};
|
||||
UserDao? result = _repositoryUserImpl.UpdateUser(userDao);
|
||||
if (result == null) throw new Exception("Не удалось обновить пользователя");
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result.GroupID);
|
||||
if (group == null) throw new Exception("Группа не найдена");
|
||||
return new User { UserFIO = user.UserFIO, UserGuid = user.UserGuid, UserGroup = group };
|
||||
}
|
||||
public UserLocalEntity FindUserByGuid(Guid userGuid)
|
||||
|
||||
public UserDao FindUserByGuid(int userId)
|
||||
{
|
||||
return _repositoryUserImpl.FindUserByGuid(userGuid);
|
||||
return _repositoryUserImpl.FindUserByGuid(userId);
|
||||
}
|
||||
public UserLocalEntity UpdateUserByGuid(Guid userGuid, String name, String gro)
|
||||
|
||||
public UserDao UpdateUserByGuid(int userId, string name, string groupId)
|
||||
{
|
||||
UserLocalEntity? result = _repositoryUserImpl.UpdateUserByGuid(userGuid);
|
||||
if (result == null) throw new Exception("");
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => it.ID == int.Parse(gro));
|
||||
if (group == null) throw new Exception("");
|
||||
return new UserLocalEntity { UserFIO = name, GroupID = int.Parse(gro), UserGuid = userGuid};
|
||||
UserDao? result = _repositoryUserImpl.UpdateUserByGuid(userId);
|
||||
if (result == null) throw new Exception("Пользователь не найден");
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => it.ID == int.Parse(groupId));
|
||||
if (group == null) throw new Exception("Группа не найдена");
|
||||
return new UserDao { UserFIO = name, GroupID = int.Parse(groupId), UserID = userId };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,29 @@
|
||||
using _123.Data.ReportsHistory;
|
||||
using _123.Data.RemoteData.RemoteDatabase;
|
||||
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<UserUseCase>()
|
||||
.AddSingleton<GroupUseCase>()
|
||||
.AddSingleton<PresenceUseCase>()
|
||||
.AddSingleton<MainMenuUI>()
|
||||
.AddDbContext<RemoteDatabaseContext>()
|
||||
.AddSingleton<IPresenceRepository, SQLPresenceRepositoryImpl>()
|
||||
.AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
|
||||
.AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>()
|
||||
var serviceProvider = services.BuildServiceProvider ();
|
||||
|
||||
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);
|
||||
|
||||
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase);
|
@ -28,19 +28,18 @@ namespace _123.UI
|
||||
{
|
||||
StringBuilder groupOutput = new StringBuilder();
|
||||
var group = _groupUseCase.UpdateGroupName(name,name1);
|
||||
{
|
||||
groupOutput.AppendLine($"{group.Name}\t{group.ID}");
|
||||
}
|
||||
Console.WriteLine(groupOutput);
|
||||
}
|
||||
public void AddGroup (String name, String id)
|
||||
{
|
||||
StringBuilder groupOutput = new StringBuilder();
|
||||
var group = _groupUseCase.AddGroup(name,id);
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
{
|
||||
groupOutput.AppendLine($"{group.Name}\t{group.ID}");
|
||||
}
|
||||
Console.WriteLine(groupOutput);
|
||||
>>>>>>> b274d8f88d0df85505fa497de11d07625bde956d
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,10 +14,13 @@ namespace _123.UI
|
||||
|
||||
GroupConsoleUI _groupConsoleUI;
|
||||
|
||||
public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase)
|
||||
PresenceConsoleUI _presenceConsoleUI;
|
||||
|
||||
public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase, PresenceUseCase presenceUseCase)
|
||||
{
|
||||
_userConsoleUI = new UserConsoleUI(userUseCase);
|
||||
_groupConsoleUI = new GroupConsoleUI(groupUseCase);
|
||||
_presenceConsoleUI = new PresenceConsoleUI(presenceUseCase);
|
||||
|
||||
DisplayMenu();
|
||||
|
||||
@ -32,10 +35,22 @@ namespace _123.UI
|
||||
case "1": _userConsoleUI.DisplayAllUsers(); break;
|
||||
case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
|
||||
case "3": _groupConsoleUI.DisplayAllGroups(); break;
|
||||
<<<<<<< HEAD
|
||||
case "4": _userConsoleUI.FindUserById(int.Parse(Console.ReadLine())); break;
|
||||
case "5": _userConsoleUI.UpdateUserById(int.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;
|
||||
case "8": _presenceConsoleUI.GetPresenceByGroup(int.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()), 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 "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;
|
||||
>>>>>>> b274d8f88d0df85505fa497de11d07625bde956d
|
||||
default:
|
||||
DisplayMenu();
|
||||
break;
|
||||
|
85
123/UI/PresenceConsole.cs
Normal file
85
123/UI/PresenceConsole.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using _123.Domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.UI
|
||||
{
|
||||
public class PresenceConsoleUI
|
||||
{
|
||||
PresenceUseCase _presenceUseCase;
|
||||
UseCaseGeneratePresence _useCaseGeneratePresence;
|
||||
|
||||
public PresenceConsoleUI(PresenceUseCase presenceUseCase, UseCaseGeneratePresence useCaseGeneratePresence)
|
||||
{
|
||||
_presenceUseCase = presenceUseCase;
|
||||
_useCaseGeneratePresence = useCaseGeneratePresence;
|
||||
}
|
||||
|
||||
public void GetPresenceByGroup(int groupId)
|
||||
{
|
||||
StringBuilder presenceOutput = new StringBuilder();
|
||||
var presence = _presenceUseCase.GetPresenceByGroup(groupId);
|
||||
foreach (var p in presence)
|
||||
{
|
||||
presenceOutput.AppendLine($"{p.LessonNumber}\t{p.UserGuid}\t{p.Date}");
|
||||
}
|
||||
Console.WriteLine(presenceOutput);
|
||||
}
|
||||
|
||||
public void GetPresenceByGroupAndDAte(int groupId, DateOnly date)
|
||||
{
|
||||
StringBuilder presenceOutput = new StringBuilder();
|
||||
var presence = _presenceUseCase.GetPresenceByGroupAndDate(groupId, date);
|
||||
foreach (var p in presence)
|
||||
{
|
||||
presenceOutput.AppendLine($"{p.LessonNumber}\t{p.UserGuid}\t{p.Date}");
|
||||
}
|
||||
Console.WriteLine(presenceOutput);
|
||||
}
|
||||
|
||||
public void UnCheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid)
|
||||
{
|
||||
var result = _presenceUseCase.UnCheckAttendance(firstClass, lastClass, date, userGuid);
|
||||
Console.WriteLine(result ? "Посещаемость успешно обновлена" : "Ошибка при обновлении посещаемости");
|
||||
}
|
||||
|
||||
public void AddPresence(int firstClass, int lastClass, int groupId, DateOnly date)
|
||||
{
|
||||
try
|
||||
{
|
||||
_useCaseGeneratePresence.AddPrecence(firstClass, lastClass, groupId, date);
|
||||
Console.WriteLine("Посещаемость успешно добавлена");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка при добавлении посещаемости: {ex.Message}");
|
||||
}
|
||||
}
|
||||
public void GetGroupAttendanceStats(int groupId)
|
||||
{
|
||||
StringBuilder statsOutput = new StringBuilder();
|
||||
var groupStats = _presenceUseCase.GetGroupStats(groupId);
|
||||
|
||||
statsOutput.AppendLine($"Информация о группе {groupStats.GroupName}:");
|
||||
statsOutput.AppendLine($"Количество студентов: {groupStats.StudentsCount}");
|
||||
statsOutput.AppendLine($"Количество проведенных занятий: {groupStats.TotalLessons}");
|
||||
statsOutput.AppendLine($"Общий процент посещаемости: {groupStats.TotalAttendancePercent:F1}%");
|
||||
statsOutput.AppendLine("\nСтатистика по студентам:");
|
||||
statsOutput.AppendLine("ФИО\tПосещено\tПропущено\tПроцент посещаемости");
|
||||
|
||||
foreach(var student in groupStats.StudentStats)
|
||||
{
|
||||
statsOutput.AppendLine(
|
||||
$"{student.StudentName}\t{student.AttendedLessons}\t" +
|
||||
$"{student.MissedLessons}\t{student.AttendancePercent:F1}%"
|
||||
);
|
||||
}
|
||||
|
||||
Console.WriteLine(statsOutput.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -17,10 +17,9 @@ namespace _123.UI
|
||||
_userUseCase = userUseCase;
|
||||
}
|
||||
|
||||
public void RemoveUserByGuid(Guid guidUser)
|
||||
public void RemoveUserById(int userId)
|
||||
{
|
||||
|
||||
string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален";
|
||||
string output = _userUseCase.RemoveUserByGuid(userId) ? "Пользователь удален" : "Пользователь не удален";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
@ -29,27 +28,43 @@ namespace _123.UI
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
foreach (var user in _userUseCase.GetAllUsers())
|
||||
{
|
||||
userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.UserGroup.Name}");
|
||||
userOutput.AppendLine($"{user.UserID}\t{user.UserFIO}\t{user.UserGroup.Name}");
|
||||
}
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
public void FindUserByGuid (Guid guidUser)
|
||||
|
||||
public void FindUserById(int userId)
|
||||
{
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
var user = _userUseCase.FindUserByGuid(guidUser);
|
||||
{
|
||||
userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.GroupID}");
|
||||
}
|
||||
var user = _userUseCase.FindUserByGuid(userId);
|
||||
userOutput.AppendLine($"{user.UserID}\t{user.UserFIO}\t{user.GroupID}");
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
public void UpdateUserByGuid(Guid userGuid,String name,String group)
|
||||
|
||||
public void UpdateUserById(int userId, String name, String groupId)
|
||||
{
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
var user = _userUseCase.UpdateUserByGuid(userGuid,name,group);
|
||||
try
|
||||
{
|
||||
userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.GroupID}");
|
||||
var group = _userUseCase.GetAllGroups().FirstOrDefault(g => g.ID == int.Parse(groupId));
|
||||
if (group == null)
|
||||
{
|
||||
Console.WriteLine("Группа не найдена");
|
||||
return;
|
||||
}
|
||||
|
||||
var updatedUser = _userUseCase.UpdateUser(new User
|
||||
{
|
||||
UserID = userId,
|
||||
UserFIO = name,
|
||||
UserGroup = group
|
||||
});
|
||||
|
||||
Console.WriteLine($"Пользователь обновлен: {updatedUser.UserID}\t{updatedUser.UserFIO}\t{updatedUser.UserGroup.Name}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка при обновлении пользователя: {ex.Message}");
|
||||
}
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
Загрузки - Ярлык.lnk
Normal file
BIN
Загрузки - Ярлык.lnk
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user