xxxproject/Demo/Data/Repository/GroupRepositoryImpl.cs

63 lines
1.6 KiB
C#
Raw Normal View History

2024-10-30 09:11:19 +00:00
using Demo.Data.Entity;
using Demo.Data.LocalData;
2024-10-14 11:51:48 +00:00
using Demo.domain.Models;
using System.Collections.Generic;
2024-10-21 12:42:07 +00:00
using System.Linq;
2024-10-14 11:51:48 +00:00
namespace Demo.Data.Repository
{
2024-10-21 12:42:07 +00:00
public class GroupRepositoryImpl : IGroupRepository
2024-10-14 11:51:48 +00:00
{
2024-10-21 12:42:07 +00:00
public List<GroupLocalEntity> GetAllGroups { get; private set; }
public GroupRepositoryImpl()
{
2024-10-18 09:51:43 +00:00
GetAllGroups = LocalStaticData.groups;
}
2024-10-21 12:42:07 +00:00
public List<GroupLocalEntity> GetAllGroup()
{
return GetAllGroups;
}
public GroupLocalEntity GetGroupById(int groupID)
{
return GetAllGroups.FirstOrDefault(g => g.Id == groupID);
}
public bool RemoveGroupById(int groupID)
2024-10-18 09:51:43 +00:00
{
2024-10-21 12:42:07 +00:00
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)
{
2024-10-23 09:42:17 +00:00
2024-10-21 12:42:07 +00:00
if (GetAllGroups.Any(g => g.Id == newGroup.Id))
{
2024-10-23 09:42:17 +00:00
return false;
2024-10-21 12:42:07 +00:00
}
2024-10-23 09:42:17 +00:00
GetAllGroups.Add(newGroup);
return true;
2024-10-18 09:51:43 +00:00
}
2024-10-14 11:51:48 +00:00
}
}