This commit is contained in:
Userok 2024-11-01 10:49:39 +03:00
parent faeb43b8c2
commit 10d049c46b
6 changed files with 84 additions and 52 deletions

View File

@ -40,10 +40,7 @@ namespace Zurnal.Data.Repository
throw new NotImplementedException();
}
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
public List<GroupLocalEntity> AllGroup => throw new NotImplementedException();
public bool RemoveGroupById(int groupID)
{
@ -59,5 +56,30 @@ namespace Zurnal.Data.Repository
{
throw new NotImplementedException();
}
public void AddGroupFromRegex(System.Text.RegularExpressions.Group group)
{
throw new NotImplementedException();
}
System.Text.RegularExpressions.Group IGroupRepository.GetGroupById(int id)
{
throw new NotImplementedException();
}
IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.GetAllGroups()
{
throw new NotImplementedException();
}
public void UpdateGroup(System.Text.RegularExpressions.Group group)
{
throw new NotImplementedException();
}
public void DeleteGroup(int id)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,4 +1,4 @@
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
using Microsoft.Extensions.DependencyInjection;
using Zurnal.Data.Repository;
using Group = System.Text.RegularExpressions.Group;
@ -7,14 +7,16 @@ namespace Zurnal.Date.Repository
{
internal interface IGroupRepository
{
List<GroupLocalEntity> GetAllGroup();
List<GroupDao> AllGroup { get; }
IEnumerable<Group> AllGroups();
bool RemoveGroupById(int groupID);
bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup);
bool AddGroup(GroupLocalEntity newGroup);
bool UpdateGroupById(int groupID, GroupDao updatedGroup);
bool AddGroup(GroupDao newGroup);
void AddGroupFromRegex(Group group);
Group GetGroupById(int id);
IEnumerable<Group> GetAllGroups();
void UpdateGroup(Group group);
GroupDao GetGroupById(int id);
IEnumerable<GroupDao> GetAllGroups();
void UpdateGroup(GroupDao group);
void DeleteGroup(int id);
}

View File

@ -68,10 +68,7 @@ namespace Zurnal.Data.Repository
throw new NotImplementedException();
}
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
public List<GroupLocalEntity> AllGroup => throw new NotImplementedException();
internal UserUseCase.UserLocalEntity? UpdateUser(UserUseCase.UserLocalEntity userLocalEntity)
{

View File

@ -1,14 +1,25 @@
namespace Zurnal.domain.Models
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.domain.Models
{
public class Group
{
public required int Id { get; set; }
public required string Name { get; set; }
public static implicit operator Group(GroupLocalEntity v)
public static implicit operator Group?(GroupLocalEntity? v)
{
throw new NotImplementedException();
}
public static implicit operator Guid(Group v)
{
throw new NotImplementedException();
}
public static implicit operator Group?(GroupDao? v)
{
throw new NotImplementedException();
}
}
}

View File

@ -2,6 +2,8 @@
{
public class User
{
internal int Id;
public required string FIO { get; set; }
public Guid Guid { get; set; }

View File

@ -1,7 +1,7 @@
using Zurnal.Data.Repository;
using Zurnal.Date.Repository;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Domain.UseCase
{
@ -15,20 +15,15 @@ namespace Zurnal.Domain.UseCase
_repositoryUserImpl = repositoryImpl;
RepositoryGroupImpl = (IGroupRepository?)(repositoryGroupImpl ?? throw new ArgumentNullException(nameof(repositoryGroupImpl)));
}
private object NewMethod()
{
return RepositoryGroupImpl.GetAllGroup()
.Select(it => new Group { Id = it.Id, Name = it.Name });
}
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsersList()
.Join(RepositoryGroupImpl.GetAllGroup(),
.Join(RepositoryGroupImpl.AllGroup,
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 } }
Group = new Group { Id = group.Id, Name = group.GroupName } }
).ToList();
public bool RemoveUserByGuid(Guid userGuid)
@ -36,37 +31,40 @@ namespace Zurnal.Domain.UseCase
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
}
public User UpdateUser(User user, Guid id)
public User UpdateUser(User user, Group id)
{
UserLocalEntity userLocalEntity = new UserLocalEntity { FIO = user.FIO, GroupID = 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.ToString());
if (group == null) throw new Exception("Group not found.");
if (result == null) throw new Exception("Пользователь не обновлен.");
Group? group = GetAllGroups().FirstOrDefault(it =>
{
bool v = it.Id == result.GroupID.ToString();
return v;
});
if (group == null) throw new Exception("Группа не обновлена.");
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
}
private static UserLocalEntity GetUserLocalEntity(UserLocalEntity userLocalEntity)
private List<Group> GetAllGroups()
{
return userLocalEntity;
return new List<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);
if (user == null) throw new Exception("Пользователь не найден.");
var group = RepositoryGroupImpl.AllGroup.FirstOrDefault(g => g.Id == user.GroupID);
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
}
public List<Group> GetAllGroup()
{
return new List<Group>();
}
public List<Group> AllGroup => new List<Group>();
List<GroupDao> IGroupRepository.AllGroup => throw new NotImplementedException();
List<GroupLocalEntity> IGroupRepository.GetAllGroup()
IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.AllGroups()
{
throw new NotImplementedException();
return (IEnumerable<System.Text.RegularExpressions.Group>)((IGroupRepository)_repositoryUserImpl).GetAllGroups();
}
public bool RemoveGroupById(int groupID)
@ -74,12 +72,12 @@ namespace Zurnal.Domain.UseCase
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
public bool UpdateGroupById(int groupID, GroupDao updatedGroup)
{
throw new NotImplementedException();
}
public bool AddGroup(GroupLocalEntity newGroup)
public bool AddGroup(GroupDao newGroup)
{
throw new NotImplementedException();
}
@ -89,17 +87,17 @@ namespace Zurnal.Domain.UseCase
throw new NotImplementedException();
}
public System.Text.RegularExpressions.Group GetGroupById(int id)
public GroupDao GetGroupById(int id)
{
throw new NotImplementedException();
}
public IEnumerable<System.Text.RegularExpressions.Group> GetAllGroups()
IEnumerable<GroupDao> IGroupRepository.GetAllGroups()
{
throw new NotImplementedException();
}
public void UpdateGroup(System.Text.RegularExpressions.Group group)
public void UpdateGroup(GroupDao group)
{
throw new NotImplementedException();
}