Major refactor and cleanup.

This commit is contained in:
2025-11-13 04:05:35 +00:00
parent 1d67081792
commit 8f6d334af4
833 changed files with 86800 additions and 74355 deletions

View File

@@ -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;
}
}