46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using Demo.Data.Repository;
|
|
using Demo.domain.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Demo.Domain.UseCase
|
|
{
|
|
internal class GroupUseCase
|
|
{
|
|
private readonly GroupRepositoryImpl _repositoryGroupImpl;
|
|
|
|
public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl)
|
|
{
|
|
_repositoryGroupImpl = repositoryGroupImpl;
|
|
}
|
|
|
|
// Вывести все группы
|
|
public List<Group> GetAllGroups()
|
|
{
|
|
return _repositoryGroupImpl.GetAllGroups().Select(it => new Group { Id = it.Id, Name = it.Name }).ToList();
|
|
}
|
|
// Создать новую группу
|
|
public void AddGroup(string groupName)
|
|
{
|
|
var newId = _repositoryGroupImpl.GetAllGroups().Max(g => g.Id) + 1;
|
|
GroupLocalEntity newGroup = new GroupLocalEntity
|
|
{
|
|
Id = newId,
|
|
Name = groupName
|
|
};
|
|
_repositoryGroupImpl.AddGroup(newGroup);
|
|
}
|
|
|
|
// Изменить название группы по ID
|
|
public void UpdateGroup(int groupId, string newGroupName)
|
|
{
|
|
GroupLocalEntity existingGroup = _repositoryGroupImpl.GetAllGroups().FirstOrDefault(g => g.Id == groupId);
|
|
existingGroup.Name = newGroupName;
|
|
_repositoryGroupImpl.UpdateGroup(existingGroup);
|
|
}
|
|
}
|
|
}
|