85 lines
2.4 KiB
C#
85 lines
2.4 KiB
C#
using Demo.Data.Repository;
|
||
using Demo.Data.Exceptions;
|
||
using Demo.Domain.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using Demo.domain.Models;
|
||
|
||
namespace Demo.Domain.UseCase
|
||
{
|
||
public class UserUseCase
|
||
{
|
||
private readonly UserRepositoryImpl _userRepositoryImpl;
|
||
|
||
public UserUseCase(UserRepositoryImpl userRepositoryImpl)
|
||
{
|
||
_userRepositoryImpl = userRepositoryImpl;
|
||
}
|
||
|
||
public List<UserLocalEntity> GetAllUsers()
|
||
{
|
||
try
|
||
{
|
||
return new List<UserLocalEntity>(_userRepositoryImpl.GetAllUsers);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($"Ошибка при получении пользователей: {ex.Message}");
|
||
return new List<UserLocalEntity>();
|
||
}
|
||
}
|
||
|
||
public void DeleteUserByGuid(Guid guid)
|
||
{
|
||
try
|
||
{
|
||
_userRepositoryImpl.DeleteUserByGuid(guid);
|
||
}
|
||
catch (DataNotFoundException ex)
|
||
{
|
||
Console.WriteLine($"Ошибка при удалении пользователя: {ex.Message}");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($"Неизвестная ошибка: {ex.Message}");
|
||
}
|
||
}
|
||
|
||
public UserLocalEntity? FindUserByGuid(Guid guid)
|
||
{
|
||
try
|
||
{
|
||
return _userRepositoryImpl.FindUserByGuid(guid);
|
||
}
|
||
catch (DataNotFoundException ex)
|
||
{
|
||
Console.WriteLine($"Ошибка при поиске пользователя: {ex.Message}");
|
||
return null;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($"Неизвестная ошибка: {ex.Message}");
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public void UpdateUser(Guid guid, string newFIO, int newGroupID)
|
||
{
|
||
var users = _userRepositoryImpl.GetAllUsers;
|
||
var user = users.FirstOrDefault(u => u.Guid == guid);
|
||
|
||
if (user != null)
|
||
{
|
||
user.FIO = newFIO;
|
||
user.GroupID = newGroupID;
|
||
}
|
||
else
|
||
{
|
||
throw new GuidNotFoundException($"Пользователь с GUID {guid} не найден.");
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
}
|