using System; using System.Collections.Generic; using System.Linq; using Zurnal.Data.Repository; using Zurnal.domain.Models; using Zurnal.RemaDateBase.DateDao; namespace Zurnal.Date.Repository.SQLRepos { public class SQLUserRepositoryImpl : IUserRepository { private readonly RemoteDateBaseContext _remoteDataBaseContext; public SQLUserRepositoryImpl(RemoteDateBaseContext remoteDataBaseContext) { _remoteDataBaseContext = remoteDataBaseContext; } public List GetAllUsers => _remoteDataBaseContext.User.Select(user => new UserDao { UserGuid = user.UserGuid, FIO = user.FIO, GroupID = user.GroupID, }).ToList(); public bool RemoveUserByGuid(Guid userGuid) { var user = _remoteDataBaseContext.User.Find(userGuid); if (user == null) return false; _remoteDataBaseContext.User.Remove(user); _remoteDataBaseContext.SaveChanges(); return true; } public UserDao? GetUserByGuid(Guid userGuid) { var user = _remoteDataBaseContext.User.Find(userGuid); if (user == null) return null; return new UserDao { UserGuid = user.UserGuid, FIO = user.FIO, GroupID = user.GroupID, }; } public UserDao? UpdateUser(UserDao userUpdateLocalEnity) { var user = _remoteDataBaseContext.User.Find(userUpdateLocalEnity.UserGuid); if (user == null) return null; user.FIO = userUpdateLocalEnity.FIO; user.GroupID = userUpdateLocalEnity.GroupID; _remoteDataBaseContext.SaveChanges(); return userUpdateLocalEnity; } } }