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 GetAllUsers() { return _userRepository.GetAllUsers(); } public User FindUserByGuid(Guid userGuid) { return _userRepository.GetByGuid(userGuid); } public List 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, // Проверка на null Guid = user?.Guid ?? Guid.Empty, // Возврат Guid.Empty, если user null }; } public bool RemoveUserByGuid(Guid userGuid) { return _userRepository.RemoveUserByGuid(userGuid); } public UserModel GetUserModelByGuid(Guid userGuid) { var user = FindUserByGuid(userGuid); return new UserModel { FIO = user?.FIO, // Проверка на null Guid = user?.Guid ?? Guid.Empty, // Возврат Guid.Empty, если user null }; } public bool UpdateUser(User user) { return _userRepository.UpdateUser(user); } public Group GetGroupById(int id) { return _groupRepo.GetGroupById(id); } internal bool RemoveUser(Guid userGuid) { throw new NotImplementedException(); } } public class UserModel { public string FIO { get; set; } public Guid Guid { get; internal set; } } }