using Demo.Data.LocalData; using Demo.domain.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Data.RemoteData.RemoteDataBase.DAO; using Demo.Data.RemoteData.RemoteDataBase.DAO; namespace Demo.Data.Repository { public class SQLGroupRepositoryImpl : IGroupRepository { private readonly RemoteDatabaseContext _remoteDatabaseContext; public SQLGroupRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) { _remoteDatabaseContext = remoteDatabaseContext; GetAllGroups = _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, Id = x.Id}).ToList(); } public List GetAllGroups { get; set; } public List GetAllGroup() { return _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, Id = x.Id}).ToList(); } public GroupLocalEntity? UpdateGroupName(GroupLocalEntity groupUpdateLocalEntity) { var group = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupUpdateLocalEntity.Id); if (group == null){ return null; } group.Name = groupUpdateLocalEntity.Name; _remoteDatabaseContext.SaveChanges(); return new GroupLocalEntity{Name = group.Name, Id = group.Id}; } public GroupLocalEntity? CreateGroup(string Name) { GroupDao groupDAO = new GroupDao{Name = Name}; var result = _remoteDatabaseContext.Groups.Add(groupDAO); _remoteDatabaseContext.SaveChanges(); return new GroupLocalEntity{Name = groupDAO.Name, Id = groupDAO.Id}; } public bool RemoveGroupById(int groupID) { var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupID); _remoteDatabaseContext.Groups.Remove(groupDao); _remoteDatabaseContext.SaveChanges(); return true; } public GroupLocalEntity? GetGroupById(int groupId) { var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupId); return new GroupLocalEntity{Name = groupDao.Name, Id = groupDao.Id}; } } }