Demo/Data/Repository/GroupRepositoryImpl.cs

85 lines
2.9 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
2024-10-23 07:06:56 +00:00
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Posechaemost.Data.LocalData;
using Posechaemost.Data.LocalData.Entity;
namespace Posechaemost.Data.Repository
{
2024-10-23 07:06:56 +00:00
public class GroupRepositoryImpl: IGroupRepository
{
2024-10-23 07:06:56 +00:00
public bool AddGroup(String name, String id)
{
GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault();
// GroupLocalEntity? group = new GroupLocalEntity();
groupLocal.Name = name;
groupLocal.Id = int.Parse(id);
return true;
}
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
2024-10-23 07:06:56 +00:00
public GroupLocalEntity GetGroupById(int groupID)
{
2024-10-23 07:06:56 +00:00
GroupLocalEntity groupLocal = GetAllGroups()
.Where(x => x.Id == groupID).FirstOrDefault();
if (groupLocal == null) return null;
return groupLocal;
}
2024-10-23 07:11:56 +00:00
public bool RemoveGroupById(int groupID){
2024-10-23 07:06:56 +00:00
GroupLocalEntity? groupLocal = GetAllGroups()
.Where(x => x.Id == groupID).FirstOrDefault();
if (groupLocal == null) return false;
return GetAllGroups().Remove(groupLocal);
}
2024-10-23 07:11:56 +00:00
// public GroupLocalEntity? AddGroup(String name, String id) //не работает
// {
// GroupLocalEntity? groupLocal = GetAllGroups()
// .Where(x => x.Id == groupID).FirstOrDefault();
// if (groupLocal == null) return false;
// return GetAllGroups().Remove(groupLocal);
// }
2024-10-23 07:06:56 +00:00
public bool UpdateGroupById(int groupID, String name)
{
GroupLocalEntity? groupLocal = GetAllGroups()
.Where(x => x.Id == groupID).FirstOrDefault();
if (groupLocal == null) return false;
2024-10-18 08:43:40 +00:00
groupLocal.Name = name;
2024-10-23 07:06:56 +00:00
return true;
2024-10-18 08:43:40 +00:00
}
}
2024-10-23 07:06:56 +00:00
}
// {
// public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
// public GroupLocalEntity? UpdateGroup(String name)
// {
// GroupLocalEntity? groupLocal = GetAllGroups()
// .Where(x => x.Name == name).FirstOrDefault();
// if (groupLocal == null) return null;
// groupLocal.Name = name;
// return groupLocal;
// }
// public GroupLocalEntity? AddGroup(String name, String id)
// {
// GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault();
// // GroupLocalEntity? group = new GroupLocalEntity(name, id);
// groupLocal.Name = name;
// groupLocal.Id = int.Parse(id);
// return groupLocal;
// }
// }