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 _groups = LocalStaticData.groups; public List 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; } } }