119 lines
4.0 KiB
C#
119 lines
4.0 KiB
C#
using Zurnal.Data.Repository;
|
|
using Zurnal.Date.Repository;
|
|
using Zurnal.domain.Models;
|
|
|
|
|
|
namespace Zurnal.Domain.UseCase
|
|
{
|
|
public class UserUseCase : IGroupRepository
|
|
{
|
|
private readonly UserRepositoryImpl _repositoryUserImpl;
|
|
internal IGroupRepository RepositoryGroupImpl { get; }
|
|
|
|
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
|
|
{
|
|
_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(),
|
|
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();
|
|
|
|
public bool RemoveUserByGuid(Guid userGuid)
|
|
{
|
|
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
|
}
|
|
|
|
public User UpdateUser(User user, Guid 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.");
|
|
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
|
|
}
|
|
|
|
private static UserLocalEntity GetUserLocalEntity(UserLocalEntity userLocalEntity)
|
|
{
|
|
return userLocalEntity;
|
|
}
|
|
|
|
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 };
|
|
}
|
|
|
|
public List<Group> GetAllGroup()
|
|
{
|
|
return new List<Group>();
|
|
}
|
|
|
|
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 bool AddGroup(GroupLocalEntity newGroup)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void AddGroupFromRegex(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();
|
|
}
|
|
|
|
internal class UserLocalEntity
|
|
{
|
|
public string FIO { get; set; }
|
|
public Guid GroupID { get; set; }
|
|
public Guid Guid { get; set; }
|
|
}
|
|
}
|
|
} |