58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
|
|
using Yuna.Website.Server.Storage;
|
|
using Yuna.Website.Server.Model;
|
|
|
|
using Yuna.Website.Server.Services.DeviceSkillService;
|
|
using Yuna.Website.Server.Storage.Repositories.Device;
|
|
|
|
namespace Yuna.Website.Server.Services.DeviceService
|
|
{
|
|
public class DeviceService : IDeviceService
|
|
{
|
|
private readonly IPropService _propService;
|
|
private readonly IDeviceRepository _deviceRepository;
|
|
public DeviceService(IPropService propService, IDeviceRepository repository)
|
|
{
|
|
_propService = propService;
|
|
_deviceRepository = repository;
|
|
}
|
|
|
|
public async Task<Device?> AddProps(IReadOnlyList<Prop> props, long deviceId)
|
|
{
|
|
var device = await _deviceRepository.GetById(deviceId);
|
|
if (device is null) return null;
|
|
|
|
await _deviceRepository.AddProps(props, deviceId);
|
|
|
|
device.Props.AddRange(props);
|
|
return device;
|
|
}
|
|
|
|
public async Task<Device?> Create(Device device)
|
|
{
|
|
var result = await _deviceRepository.Create(device);
|
|
return result;
|
|
}
|
|
|
|
public async Task<Device?> Delete(long id)
|
|
{
|
|
var prop = await _deviceRepository.GetById(id);
|
|
if (prop is null) return null;
|
|
|
|
var result = await _deviceRepository.Delete(id);
|
|
return result;
|
|
}
|
|
|
|
public async Task<Device?> GetById(long id)
|
|
{
|
|
var result = await _deviceRepository.GetById(id);
|
|
return result;
|
|
}
|
|
public async Task<IReadOnlyList<Device>> GetList()
|
|
{
|
|
var result = await _deviceRepository.GetList();
|
|
return result ?? [];
|
|
}
|
|
}
|
|
}
|