pr1/Demo/Domain/UseCase/GroupUseCase.cs
2024-10-20 00:39:57 +03:00

52 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Demo.Data.LocalData;
using Demo.Data.Repository;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Demo.Domain.UseCase
{
public class GroupUseCase
{
private List<GroupLocalEntity> _groups = LocalStaticData.groups;
public List<GroupLocalEntity> GetAllGroups() => _groups;
public void AddGroup(GroupLocalEntity group)
{
group.Id = _groups.Any() ? _groups.Max(g => g.Id) + 1 : 1;
_groups.Add(group);
}
public void UpdateGroup(GroupLocalEntity group)
{
var existingGroup = _groups.FirstOrDefault(g => g.Id == group.Id);
if (existingGroup != null)
{
existingGroup.Name = group.Name;
}
}
public void RenameGroup(int groupId, string newName)
{
if (string.IsNullOrWhiteSpace(newName))
{
throw new ArgumentException("Новое имя группы не может быть пустым", nameof(newName));
}
var existingGroup = _groups.FirstOrDefault(g => g.Id == groupId);
if (existingGroup == null)
{
throw new KeyNotFoundException($"Группа с ID {groupId} не найдена.");
}
existingGroup.Name = newName;
}
}
}