presence/Data/Repository/UserRepositoty.cs

74 lines
2.2 KiB
C#
Raw Normal View History

2024-12-06 08:51:13 +00:00
using presence.Data.LocalData;
using presence.Data.LocalData.Entity;
using presence.Data.RemoteData.RemoteDatabase.DAO;
using presence.Data.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace presence.Data.ReportsHistory
{
public class UserRepositoryImpl: IUserRepository
{
public UserRepositoryImpl()
{
GetAllUsers = LocalStaticData.users.Select(it => new UserDao { GroupID = it.GroupID, UserFIO = it.UserFIO, UserID = it.UserId}).ToList();
}
public List<UserDao> GetAllUsers
{ get; set; }
public List<UserDao> GetAllUser()
{
return GetAllUsers;
}
public bool RemoveUserById(int userId)
{
UserDao? userLocal = GetAllUsers
.Where(x => x.UserID == userId).FirstOrDefault();
if (userLocal == null) return false;
return GetAllUsers.Remove(userLocal);
}
public UserDao FindUserById(int userId)
{
UserDao? userLocal = GetAllUsers
.Where(x => x.UserID == userId).FirstOrDefault();
if (userLocal == null) throw new Exception("Пользователь не найден");
return userLocal;
}
public UserDao? GetUserById(int userId)
{
UserDao? userLocal = GetAllUsers
.Where(x => x.UserID == userId).FirstOrDefault();
if (userLocal == null) return null;
return userLocal;
}
public UserDao? UpdateUser(UserDao userUpdateDao)
{
UserDao? userLocal = GetAllUsers
.Where(x => x.UserID == userUpdateDao.UserID).FirstOrDefault();
if (userLocal == null) return null;
userLocal.UserFIO = userUpdateDao.UserFIO;
userLocal.GroupID = userUpdateDao.GroupID;
return userLocal;
}
public UserDao? UpdateUserById(int userId)
{
UserDao? userLocal = GetAllUsers
.Where(x => x.UserID == userId).FirstOrDefault();
if (userLocal == null) return null;
return userLocal;
}
}
}