mirror of
https://github.com/morbalint/kemkas.git
synced 2026-07-18 03:13:46 +00:00
7bb7ab6f13
Base functionality:
DB
email sending
user registration & login
storing new characters and reading them back
Notes:
Functionality is "hidden" with no links pointing to it.
Most pages are scaffolded and not reviewed at all :(
local Dev db setup is pushed to git
NO local email setup :(
47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using Kemkas.Web.Db;
|
|
using Kemkas.Web.Db.Models;
|
|
using Kemkas.Web.Services.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Kemkas.Web.Services.Character;
|
|
|
|
public interface ICharacterPersistenceService
|
|
{
|
|
public Task<Guid> StoreNewCharacter(V1Karakter karakter);
|
|
|
|
public Task<V1Karakter?> GetCharacterById(Guid id);
|
|
}
|
|
|
|
public class CharacterPersistenceService(
|
|
ApplicationDbContext dbContext,
|
|
ICurrentUserService currentUserService
|
|
) : ICharacterPersistenceService
|
|
{
|
|
|
|
public async Task<Guid> StoreNewCharacter(V1Karakter karakter)
|
|
{
|
|
var currentUser = await currentUserService.GetCurrentUser();
|
|
karakter.OwnerUserId = currentUser?.Id;
|
|
karakter.Id = Guid.Empty;
|
|
dbContext.Karakterek.Add(karakter);
|
|
await dbContext.SaveChangesAsync();
|
|
return karakter.Id;
|
|
}
|
|
|
|
public async Task<V1Karakter?> GetCharacterById(Guid id)
|
|
{
|
|
var entity = await dbContext.Karakterek
|
|
.Include(x => x.KarakterKepzettsegek)
|
|
.Include(x => x.Szintlepesek)
|
|
.Include(x => x.Felszereles)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (entity?.OwnerUserId is null || entity.IsPublic)
|
|
{
|
|
return entity;
|
|
}
|
|
|
|
var currentUser = await currentUserService.GetCurrentUser();
|
|
return entity.OwnerUserId == currentUser?.Id ? entity : null;
|
|
}
|
|
} |