62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using Demo.Data.LocalData;
|
|
using Demo.domain.Models;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Demo.Data.Repository
|
|
{
|
|
public class GroupRepositoryImpl : IGroupRepository
|
|
{
|
|
public List<GroupLocalEntity> GetAllGroups { get; private set; }
|
|
|
|
public GroupRepositoryImpl()
|
|
{
|
|
GetAllGroups = LocalStaticData.groups;
|
|
}
|
|
|
|
public List<GroupLocalEntity> GetAllGroup()
|
|
{
|
|
return GetAllGroups;
|
|
}
|
|
|
|
public GroupLocalEntity GetGroupById(int groupID)
|
|
{
|
|
return GetAllGroups.FirstOrDefault(g => g.Id == groupID);
|
|
}
|
|
|
|
public bool RemoveGroupById(int groupID)
|
|
{
|
|
var group = GetAllGroups.FirstOrDefault(g => g.Id == groupID);
|
|
if (group != null)
|
|
{
|
|
GetAllGroups.Remove(group);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
|
|
{
|
|
var existingGroup = GetAllGroups.FirstOrDefault(g => g.Id == groupID);
|
|
if (existingGroup != null)
|
|
{
|
|
existingGroup.Name = updatedGroup.Name;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool AddGroup(GroupLocalEntity newGroup)
|
|
{
|
|
|
|
if (GetAllGroups.Any(g => g.Id == newGroup.Id))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
GetAllGroups.Add(newGroup);
|
|
return true;
|
|
}
|
|
}
|
|
}
|