added BuildOverview and BuildEdit
This commit is contained in:
parent
a3062165e1
commit
9ffaf908f3
5 changed files with 226 additions and 8 deletions
69
Lieb/Data/GuildWars2BuildService.cs
Normal file
69
Lieb/Data/GuildWars2BuildService.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
using Lieb.Models.GuildWars2;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Lieb.Data
|
||||
{
|
||||
public class GuildWars2BuildService
|
||||
{
|
||||
private readonly IDbContextFactory<LiebContext> _contextFactory;
|
||||
|
||||
public GuildWars2BuildService(IDbContextFactory<LiebContext> contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public async Task AddOrEditBuild(GuildWars2Build build)
|
||||
{
|
||||
if (build != null)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
if (build.GuildWars2BuildId == 0)
|
||||
{
|
||||
context.GuildWars2Builds.Add(build);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
GuildWars2Build? buildToChange = await context.GuildWars2Builds
|
||||
.FirstOrDefaultAsync(r => r.GuildWars2BuildId == build.GuildWars2BuildId);
|
||||
|
||||
if (buildToChange != null)
|
||||
{
|
||||
buildToChange.BuildName = build.BuildName;
|
||||
buildToChange.Might = build.Might;
|
||||
buildToChange.Quickness = build.Quickness;
|
||||
buildToChange.Alacrity = build.Alacrity;
|
||||
buildToChange.Heal = build.Heal;
|
||||
buildToChange.Class = build.Class;
|
||||
buildToChange.EliteSpecialization = build.EliteSpecialization;
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteBuild(int buildId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
GuildWars2Build? build = await context.GuildWars2Builds.FirstOrDefaultAsync(b => b.GuildWars2BuildId == buildId);
|
||||
if (build != null)
|
||||
{
|
||||
context.GuildWars2Builds.Remove(build);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public List<GuildWars2Build> GetBuilds()
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.GuildWars2Builds.ToList();
|
||||
}
|
||||
|
||||
public GuildWars2Build GetBuild(int buildId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.GuildWars2Builds.FirstOrDefault(b => b.GuildWars2BuildId == buildId);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue