54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
using Data.RemoteData.RemoteDataBase.DAO;
|
|
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
|
|
{
|
|
public class SQLUserRepositoryImpl:IUserRepository
|
|
{
|
|
|
|
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();
|
|
}
|
|
public List<UserLocalEntity> GetAllUsers
|
|
{ get; set; }
|
|
|
|
public List<UserLocalEntity> GetAllUser()
|
|
{
|
|
return _remoteDatabaseContext.Users.Select(x => new UserLocalEntity{FIO = x.FIO, Guid = x.Guid, GroupID = x.GroupID}).ToList();
|
|
}
|
|
|
|
public bool RemoveUserByGuid(Guid userGuid)
|
|
{
|
|
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid);
|
|
_remoteDatabaseContext.Users.Remove(userDAO);
|
|
_remoteDatabaseContext.SaveChanges();
|
|
return true;
|
|
}
|
|
|
|
public UserLocalEntity? GetUserByGuid(Guid userGuid) {
|
|
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid);
|
|
return new UserLocalEntity{FIO = userDAO.FIO, GroupID = userDAO.GroupID, Guid = userGuid};
|
|
}
|
|
|
|
public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEntity) {
|
|
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};
|
|
}
|
|
}
|
|
} |