using data.Exception; using domain.Models; using remoteData.RemoteDataBase; using User = data.RemoteData.RemoteDataBase.DAO.UserDao; namespace data.Repository { public class SQLUserRepositoryImpl : IUserRepository { private readonly RemoteDatabaseContext _remoteDatabaseContext; public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) { _remoteDatabaseContext = remoteDatabaseContext; } public IEnumerable GetAllUsers => _remoteDatabaseContext.users .Select(u => new UserLocalEnity { Guid = u.Guid, FIO = u.FIO, GroupID = u.GroupID }) .ToList(); public bool RemoveUserByGuid(Guid userGuid) { var user = _remoteDatabaseContext.users.FirstOrDefault(u => u.Guid == userGuid); if (user == null) throw new UserNotFoundException(userGuid); _remoteDatabaseContext.users.Remove(user); _remoteDatabaseContext.SaveChanges(); return true; } public UserLocalEnity? UpdateUser(UserLocalEnity user) { var existingUser = _remoteDatabaseContext.users.FirstOrDefault(u => u.Guid == user.Guid); if (existingUser == null) throw new UserNotFoundException(user.Guid); existingUser.FIO = user.FIO; existingUser.GroupID = user.GroupID; _remoteDatabaseContext.SaveChanges(); return new UserLocalEnity { Guid = existingUser.Guid, FIO = existingUser.FIO, GroupID = existingUser.GroupID }; } public IEnumerable GetAllUsersDao => _remoteDatabaseContext.users.ToList(); public List GetUserNames() { return _remoteDatabaseContext.users .Select(u => new User { Guid = u.Guid, FIO = u.FIO }) .ToList(); } List IUserRepository.GetUserNames() { throw new NotImplementedException(); } } }