presence/Demo/Domain/UseCase/UserUseCase.cs

87 lines
2.3 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
{
2024-10-25 08:47:11 +00:00
FIO = user?.FIO, // Проверка на null
Guid = user?.Guid ?? Guid.Empty, // Возврат Guid.Empty, если user null
2024-10-21 12:42:00 +00:00
};
}
public bool RemoveUserByGuid(Guid userGuid)
{
return _userRepository.RemoveUserByGuid(userGuid);
}
public UserModel GetUserModelByGuid(Guid userGuid)
{
var user = FindUserByGuid(userGuid);
return new UserModel
{
2024-10-25 08:47:11 +00:00
FIO = user?.FIO, // Проверка на null
Guid = user?.Guid ?? Guid.Empty, // Возврат Guid.Empty, если user null
2024-10-21 12:42:00 +00:00
};
}
public bool UpdateUser(User user)
{
return _userRepository.UpdateUser(user);
}
public Group GetGroupById(int id)
{
return _groupRepo.GetGroupById(id);
}
2024-10-25 08:47:11 +00:00
internal bool RemoveUser(Guid userGuid)
{
throw new NotImplementedException();
}
2024-10-21 12:42:00 +00:00
}
public class UserModel
{
public string FIO { get; set; }
public Guid Guid { get; internal set; }
}
}