pr/Demo/Domain/UseCase/GroupUseCase.cs
2024-10-25 23:08:16 +03:00

43 lines
1.3 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 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;
}
}
}