mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Major refactor and cleanup.
This commit is contained in:
@@ -30,49 +30,46 @@ using Marechai.Database.Models;
|
||||
using Marechai.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Marechai.Services
|
||||
namespace Marechai.Services;
|
||||
|
||||
public class SoundSynthsByMachineService(MarechaiContext context)
|
||||
{
|
||||
public class SoundSynthsByMachineService
|
||||
public async Task<List<SoundSynthByMachineViewModel>> GetByMachine(int machineId) => await context.SoundByMachine
|
||||
.Where(g => g.MachineId == machineId)
|
||||
.Select(g => new SoundSynthByMachineViewModel
|
||||
{
|
||||
Id = g.Id,
|
||||
Name = g.SoundSynth.Name,
|
||||
CompanyName = g.SoundSynth.Company.Name,
|
||||
SoundSynthId = g.SoundSynthId,
|
||||
MachineId = g.MachineId
|
||||
})
|
||||
.OrderBy(g => g.CompanyName)
|
||||
.ThenBy(g => g.Name)
|
||||
.ToListAsync();
|
||||
|
||||
public async Task DeleteAsync(long id, string userId)
|
||||
{
|
||||
readonly MarechaiContext _context;
|
||||
SoundByMachine item = await context.SoundByMachine.FindAsync(id);
|
||||
|
||||
public SoundSynthsByMachineService(MarechaiContext context) => _context = context;
|
||||
if(item is null) return;
|
||||
|
||||
public async Task<List<SoundSynthByMachineViewModel>> GetByMachine(int machineId) =>
|
||||
await _context.SoundByMachine.Where(g => g.MachineId == machineId).
|
||||
Select(g => new SoundSynthByMachineViewModel
|
||||
{
|
||||
Id = g.Id,
|
||||
Name = g.SoundSynth.Name,
|
||||
CompanyName = g.SoundSynth.Company.Name,
|
||||
SoundSynthId = g.SoundSynthId,
|
||||
MachineId = g.MachineId
|
||||
}).OrderBy(g => g.CompanyName).ThenBy(g => g.Name).ToListAsync();
|
||||
context.SoundByMachine.Remove(item);
|
||||
|
||||
public async Task DeleteAsync(long id, string userId)
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
}
|
||||
|
||||
public async Task<long> CreateAsync(int soundSynthId, int machineId, string userId)
|
||||
{
|
||||
var item = new SoundByMachine
|
||||
{
|
||||
SoundByMachine item = await _context.SoundByMachine.FindAsync(id);
|
||||
SoundSynthId = soundSynthId,
|
||||
MachineId = machineId
|
||||
};
|
||||
|
||||
if(item is null)
|
||||
return;
|
||||
await context.SoundByMachine.AddAsync(item);
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
_context.SoundByMachine.Remove(item);
|
||||
|
||||
await _context.SaveChangesWithUserAsync(userId);
|
||||
}
|
||||
|
||||
public async Task<long> CreateAsync(int soundSynthId, int machineId, string userId)
|
||||
{
|
||||
var item = new SoundByMachine
|
||||
{
|
||||
SoundSynthId = soundSynthId,
|
||||
MachineId = machineId
|
||||
};
|
||||
|
||||
await _context.SoundByMachine.AddAsync(item);
|
||||
await _context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return item.Id;
|
||||
}
|
||||
return item.Id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user