presence/Demo/Data/Repository/UserRepositoryImpl.cs
Class_Student 2971dbdac4 update
2024-11-01 10:14:01 +03:00

65 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Demo.Data.LocalData;
using Demo.domain.Models;
using Demo.Data.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Data.Repository
{
public class UserRepositoryImpl
{
private List<UserLocalEntity> _users;
public UserRepositoryImpl()
{
_users = LocalStaticData.users;
}
public IEnumerable<UserLocalEntity> GetAllUsers => _users;
public void DeleteUserByGuid(Guid guid)
{
var user = _users.FirstOrDefault(u => u.Guid == guid);
if (user != null)
{
_users.Remove(user);
}
else
{
throw new GuidNotFoundException($"Пользователь с GUID {guid} не найден.");
}
}
public UserLocalEntity? FindUserByGuid(Guid guid)
{
var user = _users.FirstOrDefault(u => u.Guid == guid);
if (user == null)
{
throw new GuidNotFoundException($"Пользователь с GUID {guid} не найден.");
}
return user;
}
public void UpdateUser(string guidOrInt, string newFIO, int newGroupID)
{
Guid guid;
if (!Guid.TryParse(guidOrInt, out guid))
{
throw new ArgumentException($"Значение '{guidOrInt}' не является корректным GUID.");
}
var user = _users.FirstOrDefault(u => u.Guid == guid);
if (user != null)
{
user.FIO = newFIO;
user.GroupID = newGroupID;
}
else
{
throw new GuidNotFoundException($"Пользователь с GUID {guid} не найден.");
}
}
}
}