presence/Demo/Domain/UseCase/UserUseCase.cs

83 lines
2.1 KiB
C#
Raw Normal View History

2024-10-21 12:42:00 +00:00
using Demo.Data.Repository;
using Demo.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Domain.UseCase
{
public class UserUseCase
{
private readonly UserRepositoryImpl _userRepository;
private readonly GroupRepositoryImpl _groupRepo;
public UserUseCase(UserRepositoryImpl userRepository, GroupRepositoryImpl groupRepo)
{
_userRepository = userRepository;
_groupRepo = groupRepo;
}
public List<User> GetAllUsers()
{
return _userRepository.GetAllUsers();
}
public User FindUserByGuid(Guid userGuid)
{
return _userRepository.GetByGuid(userGuid);
}
public List<UserModel> GetUsersAsModels()
{
return _userRepository.GetAllUsers()
.Select(user => new UserModel
{
FIO = user.FIO,
Guid = user.Guid,
}).ToList();
}
public UserModel GetUserModelById(Guid id)
{
var user = _userRepository.GetByGuid(id);
return new UserModel
{
FIO = user.FIO,
Guid = user.Guid,
};
}
public bool RemoveUserByGuid(Guid userGuid)
{
return _userRepository.RemoveUserByGuid(userGuid);
}
public UserModel GetUserModelByGuid(Guid userGuid)
{
var user = FindUserByGuid(userGuid);
return new UserModel
{
FIO = user.FIO,
Guid = user.Guid,
};
}
public bool UpdateUser(User user)
{
return _userRepository.UpdateUser(user);
}
// Новый метод для поиска группы по ID
public Group GetGroupById(int id)
{
return _groupRepo.GetGroupById(id);
}
}
public class UserModel
{
public string FIO { get; set; }
public Guid Guid { get; internal set; }
}
}