2024-10-24 20:41:31 +00:00
|
|
|
using Data.RemoteData.RemoteDataBase.DAO;
|
2024-10-16 20:15:49 +00:00
|
|
|
using Demo.Data.LocalData;
|
|
|
|
using Demo.domain.Models;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace Demo.Data.Repository
|
|
|
|
{
|
2024-10-24 20:41:31 +00:00
|
|
|
public class SQLUserRepositoryImpl:IUserRepository
|
2024-10-16 20:15:49 +00:00
|
|
|
{
|
|
|
|
|
2024-10-24 20:41:31 +00:00
|
|
|
private readonly RemoteDatabaseContext _remoteDatabaseContext;
|
|
|
|
|
|
|
|
public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) {
|
|
|
|
_remoteDatabaseContext = remoteDatabaseContext;
|
|
|
|
GetAllUsers = _remoteDatabaseContext.Users.Select(x => new UserLocalEntity{FIO = x.FIO, Guid = x.Guid, GroupID = x.GroupID}).ToList();
|
2024-10-16 20:15:49 +00:00
|
|
|
}
|
|
|
|
public List<UserLocalEntity> GetAllUsers
|
|
|
|
{ get; set; }
|
|
|
|
|
2024-10-21 09:07:49 +00:00
|
|
|
public List<UserLocalEntity> GetAllUser()
|
|
|
|
{
|
2024-10-24 20:41:31 +00:00
|
|
|
return _remoteDatabaseContext.Users.Select(x => new UserLocalEntity{FIO = x.FIO, Guid = x.Guid, GroupID = x.GroupID}).ToList();
|
2024-10-21 09:07:49 +00:00
|
|
|
}
|
|
|
|
|
2024-10-16 20:15:49 +00:00
|
|
|
public bool RemoveUserByGuid(Guid userGuid)
|
|
|
|
{
|
2024-10-24 20:41:31 +00:00
|
|
|
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid);
|
|
|
|
_remoteDatabaseContext.Users.Remove(userDAO);
|
|
|
|
_remoteDatabaseContext.SaveChanges();
|
|
|
|
return true;
|
2024-10-16 20:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public UserLocalEntity? GetUserByGuid(Guid userGuid) {
|
2024-10-24 20:41:31 +00:00
|
|
|
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid);
|
|
|
|
return new UserLocalEntity{FIO = userDAO.FIO, GroupID = userDAO.GroupID, Guid = userGuid};
|
2024-10-16 20:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEntity) {
|
2024-10-24 20:41:31 +00:00
|
|
|
var user = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userUpdateLocalEntity.Guid);
|
|
|
|
if (user == null){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
user.FIO = userUpdateLocalEntity.FIO;
|
|
|
|
user.GroupID = userUpdateLocalEntity.GroupID;
|
|
|
|
_remoteDatabaseContext.SaveChanges();
|
|
|
|
return new UserLocalEntity{FIO = user.FIO, Guid = user.Guid, GroupID = user.GroupID};
|
2024-10-16 20:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|