Pravki
This commit is contained in:
parent
1b2b3fc51b
commit
ac0c8401da
@ -6,9 +6,7 @@ namespace Zurnal.Data.Repository
|
||||
{
|
||||
public class UserRepositoryImpl : IGroupRepository
|
||||
{
|
||||
public UserRepositoryImpl() {
|
||||
GetAllUsers = LocalStaticData.users;
|
||||
}
|
||||
public UserRepositoryImpl() => GetAllUsers = LocalStaticData.users;
|
||||
|
||||
public List<UserLocalEnity> GetAllUsers
|
||||
{ get; set; }
|
||||
@ -16,7 +14,8 @@ namespace Zurnal.Data.Repository
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
UserLocalEnity? userLocal = GetAllUsers
|
||||
.Where(x => x.Guid == userGuid).FirstOrDefault();
|
||||
.Where(x => x.Guid == userGuid)
|
||||
.FirstOrDefault();
|
||||
if (userLocal == null) return false;
|
||||
|
||||
return GetAllUsers.Remove(userLocal);
|
||||
@ -40,10 +39,10 @@ namespace Zurnal.Data.Repository
|
||||
}
|
||||
public List<UserLocalEnity> GetAllUsersList()
|
||||
{
|
||||
return GetAllUsers;
|
||||
return GetAllUsersList;
|
||||
}
|
||||
|
||||
List<GroupLocalEntity> IGroupRepository.GetAllGroup()
|
||||
List<GroupLocalEntity> IGroupRepository.GetAllGroups()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@ -67,6 +66,41 @@ namespace Zurnal.Data.Repository
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal object GetAllUsers()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void AddGroup(System.Text.RegularExpressions.Group group)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public System.Text.RegularExpressions.Group GetGroupById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<System.Text.RegularExpressions.Group> GetAllGroups()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UpdateGroup(System.Text.RegularExpressions.Group group)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DeleteGroup(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public object GetAllGroup()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +1,63 @@
|
||||
using Zurnal.Data.Repository;
|
||||
using Zurnal.domain.Models;
|
||||
using Zurnal.Date.Repository;
|
||||
|
||||
namespace Zurnal.Domain.UseCase
|
||||
{
|
||||
public class UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
|
||||
public class UserUseCase
|
||||
{
|
||||
private UserRepositoryImpl _repositoryUserImpl = repositoryImpl;
|
||||
private readonly UserRepositoryImpl _repositoryUserImpl;
|
||||
internal IGroupRepository RepositoryGroupImpl { get; }
|
||||
|
||||
internal IGroupRepository RepositoryGroupImpl { get; } = (IGroupRepository?)repositoryGroupImpl;
|
||||
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
|
||||
{
|
||||
_repositoryUserImpl = repositoryImpl;
|
||||
RepositoryGroupImpl = repositoryGroupImpl;
|
||||
}
|
||||
|
||||
public List<Group> GetAllGroups() => RepositoryGroupImpl.GetAllGroup()
|
||||
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
|
||||
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
|
||||
public List<Group> GetAllGroups()
|
||||
{
|
||||
return RepositoryGroupImpl.GetAllGroup()
|
||||
.Select(it => new Group { Id = it.Id, Name = it.Name }).ToList();
|
||||
}
|
||||
|
||||
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers()
|
||||
.Join(RepositoryGroupImpl.GetAllGroup(),
|
||||
user => user.GroupID,
|
||||
group => group.Id,
|
||||
(user, group) =>
|
||||
new User { FIO = user.FIO,
|
||||
Guid = user.Guid,
|
||||
Group = new Group {Id = group.Id, Name = group.Name } }
|
||||
).ToList();
|
||||
Group = new Group { Id = group.Id, Name = group.Name } }
|
||||
).ToList();
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid) {
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||
}
|
||||
public User UpdateUser(User user) {
|
||||
UserLocalEnity userLocalEnity = new UserLocalEnity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid };
|
||||
UserLocalEnity? 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("Группа не найдена");
|
||||
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
|
||||
}
|
||||
|
||||
public User FindUserByGuid(Guid userGuid)
|
||||
{
|
||||
var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid);
|
||||
if (user == null) throw new Exception("Нет такого пользователя");
|
||||
var group = RepositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == user.GroupID);
|
||||
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
|
||||
}
|
||||
public User UpdateUser(User user)
|
||||
{
|
||||
UserLocalEnity userLocalEntity = new UserLocalEntity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid };
|
||||
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEntity);
|
||||
if (result == null) throw new Exception("User update failed.");
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => it.Id = result.GroupID);
|
||||
if (group == null) throw new Exception("Group not found.");
|
||||
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
|
||||
}
|
||||
|
||||
public User FindUserByGuid(Guid userGuid)
|
||||
{
|
||||
var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid);
|
||||
if (user == null) throw new Exception("User not found.");
|
||||
var group = RepositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == user.GroupID);
|
||||
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
|
||||
}
|
||||
}
|
||||
|
||||
internal class UserLocalEntity
|
||||
{
|
||||
public string FIO { get; set; }
|
||||
public Guid GroupID { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
}
|
||||
}
|
@ -11,22 +11,7 @@ public interface IGroupRepository
|
||||
void UpdateGroup(Group group);
|
||||
void DeleteGroup(int id);
|
||||
object GetAllGroup();
|
||||
bool RemoveGroupById(int groupID);
|
||||
bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup);
|
||||
}
|
||||
|
||||
public interface IUserRepository
|
||||
{
|
||||
void AddUser(User user);
|
||||
User GetUserById(int id);
|
||||
IEnumerable<User> GetAllUsers();
|
||||
void UpdateUser(User user);
|
||||
void DeleteUser(int id);
|
||||
}
|
||||
|
||||
public interface IPresenceRepository
|
||||
{
|
||||
void AddPresence(Presence presence);
|
||||
Presence GetPresenceById(int id);
|
||||
IEnumerable<Presence> GetAllPresences();
|
||||
void UpdatePresence(Presence presence);
|
||||
void DeletePresence(int id);
|
||||
}
|
9
Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs
Normal file
9
Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Zurnal.domain.Models;
|
||||
public interface IPresenceRepository
|
||||
{
|
||||
void AddPresence(Presence presence);
|
||||
Presence GetPresenceById(int id);
|
||||
IEnumerable<Presence> GetAllPresences();
|
||||
void UpdatePresence(Presence presence);
|
||||
void DeletePresence(int id);
|
||||
}
|
10
Zurnal/RemaDateBase/Interfase/IUserRepository.cs
Normal file
10
Zurnal/RemaDateBase/Interfase/IUserRepository.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Zurnal.domain.Models;
|
||||
|
||||
public interface IUserRepository
|
||||
{
|
||||
void AddUser(User user);
|
||||
User GetUserById(int id);
|
||||
IEnumerable<User> GetAllUsers();
|
||||
void UpdateUser(User user);
|
||||
void DeleteUser(int id);
|
||||
}
|
@ -11,7 +11,7 @@ public class RemoteDateBaseContext : DbContext
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Username=postgres;Password=123;Database=postgres");
|
||||
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5432;Username=postgres;Password= ;Database=user1");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
|
@ -1,10 +1,9 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -14,10 +13,10 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Zurnal")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3c2a052a46be0d31bde662e889b1125d89b34ddf")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1b2b3fc51b8e6c70458156ed95a4cc212f9e51a9")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Zurnal")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Zurnal")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Создано классом WriteCodeFragment MSBuild.
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
|
||||
|
@ -1 +1 @@
|
||||
c93eabaca987d32605ba5a086a447483e47422719e2959ace2200ffe485e77e0
|
||||
e6b6f9e54fa4ba82e681a5a3ba9349d7912311711fddca257c129394bd4b3c36
|
||||
|
Loading…
Reference in New Issue
Block a user