refactoring backend structure

This commit is contained in:
Michele 2021-02-15 23:35:55 +00:00
parent dcc59f7b69
commit 0e1c16ab91
36 changed files with 786 additions and 454 deletions

View file

@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2021-02-12T11:47:08.026Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.63" etag="N1L05Rh-iNcs-Q1Nc1cU" version="14.3.1" type="device"><diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">7Vvbdto4FP0aHpPlC7c8gnNpO2mGljSZV4EFaJAtRhYh9OvnyJZvKICd4DohrMUDOpZlS3vraGvbbtiO93zD0WL2nbmYNizDfW7Ylw3LMpuW1ZA/w11HkU5bBaacuKpSGhiS31gFDRVdEhcHuYqCMSrIIh8cM9/HY5GLIc7ZKl9twmj+qgs0xVpgOEZUjz4SV8yiaNfqpPEvmExn8ZXN9kV0xENxZdWTYIZctsqE7KuG7XDGRPTPe3YwlYMXj8vj1/UjvZ23b779CP5Dv/p/3d89nEWNXZc5JekCx754ddO/55PrLw/Nf/9ZDK5/rIyb3ujbmTrFeEJ0qcbLQd4Ckamv+izW8UAGK+JR5EOpP2G+GKojMAx9ROUJ9uUY7g9zCDxhLghg0FMHBFtAdDwj1L1Fa7aUvQgEGs/jUn/GOPkNzSIKh0wIwGEuFJ2sdq7GUJ4JYQOiHAdQZxAPjZmEblEgVJ0xoxQtAjIKb1hW8RCfEr/PhGBe3BBb+i52VSnBOiwIzuYJe+T5BQFRwMnRwM8ZOiqAbjDzsOBrqKKOJlxTk82My6uUumZbxWZZ2tpdNWXUdJkmbSeX+wnTC/lTGIT0evbG9ZoFrweI5C6HKADvI4H7chiDLBHhT6araSikZwmqmhpV75CHNZrCSIsMJSmeiK2EDBZoTPzpbVjnsplGfqqeyhCDcyc0JMOMuC72Q7IIJFDEJ8mQBSO+CIei1YcfDJhjnLcaLbghB8pmWoafrM6Fw3zgFSIhgTCQdYUlYV+g1s6Ju59a6zxiZZHNEikHaVn8LD3VcAyMcfvrXwFkjWMDckdCmQmPqr9Vwd2yaobb1uC+8hCRp/VcF1J0cAL8oIB3ujUD3tQA1xCmJJQPajTMF5fWPfB7AKRsLsb7XtLh8szUOGHrnLBfwJ+iEaYDFhBBmGyfR3U3eFFX0jaNZjFUd6z+bwK1pYE6WPLxDAVSRIDqmsPwhv+OcD5XBqpZd25ua6gOxdKV3Swo+o2T6D+c6Dc3RL/drlb0mxui3+6+X9Hf2c5U427pjY5QNxZMO+3CNHsvG4CuhmUP7l7aN5bxHZaSo0PyoIKwNN617wAuToLw4KAWVflV6UFTNwy/QuI3rgANMkLhMnPPZMDnTDZ3ZFM6K4KaVYHcrTtTm7rXdoPlkjvEHvERl4jfoznWTeKPjm9VkNav+eMb2JWOse/25CMXKI0ok3K7DyGlx00jKl4TGi9dewRzfv3D7hTHUwfTEVtdpYF+GIADMVNKy+2Awb4U74cMNhhTXGA7J+92J7AvAckxRYI85Z887RDnA0ncVJhbRl6YW4adbyLqpDor+6inbEPRKGgNHcyq182/AWcTHARM1+unLWb1W0x7c8tXdIvZMfaS+IUdpt0ssMPsvI8dpqn7lkNEkcq4n3BtSybvx9lZmrpNqaH32bca5WEtuoGsbK+h25SfSrHEiL1ryWJuZPrOKyWLvdGQ1dm4l6oli+40bntOeRIs1QuWltHN0aHwizCWuWOR2a5YWq0P9CKMbqQOBcdYf3rzWRRLpzC93o1i0c1Rh4jj05wHtcDL41y7B27pfikkbXF8r63VDHTtb79YumUKyl6u4pbhMPcE+IEBL/xmTHWI64aqA2MijtA5qBtr+5Vi7HBY64amBvKnNxjK49oqKMOqchgs3ft7AIjcY1ygq0OxXXsm1u2/v5disZT2Qk8+q7yV8+CEaGFEL2rPt+WsP7YIx7qcuZf4gmb9Vp8a271OX4zlXqtP4SyplLU1muqG3uj6Jc9zEsJY+SaKun6t5p6Gtrh+WkNnm0+cNtphk0mAKzEOLd04NM7PY+BTuoZmXCYR7Ek7I2XJRWt4H43n05C/DqOMw3GfpQakcrut4jkhnl/qo0t1W43k87PiRt3ZGxkVE/OPwaWbZ8WxivXTRwXrMLM/fin3j0One2YUeiEXeLTV+8zI8U1UdRVcxMFPNPpurEu56G8khkaAbVwpvk5cHIYpdt7Fj5P0W7gCxfST66h6+uG6ffU/</diagram></mxfile>

View file

@ -9,10 +9,10 @@ using System.Text;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Sledgemapper.Services;
using Sledgemapper.Entities; using Sledgemapper.Entities;
using Sledgemapper.Models.Users; using Sledgemapper.Models.Users;
using Sledgemapper.Helpers; using Sledgemapper.Helpers;
using Sledgemapper.Api.Infrastructure.Services;
namespace Sledgemapper.Controllers namespace Sledgemapper.Controllers
{ {

View file

@ -2,7 +2,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Sledgemapper.Entities; using Sledgemapper.Entities;
namespace Sledgemapper.Api.Models namespace Sledgemapper.Api.Core.Entities.CampaignAggregate
{ {
public class Campaign public class Campaign
{ {

View file

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Sledgemapper.Api.Models namespace Sledgemapper.Api.Core.Entities.CampaignAggregate
{ {
public class Map public class Map
{ {
@ -10,7 +10,6 @@ namespace Sledgemapper.Api.Models
[Required] [Required]
public string MapName { get; set; } public string MapName { get; set; }
[Required] [Required]
public int CampaignId { get; set; } public int CampaignId { get; set; }

View file

@ -1,81 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Sledgemapper.Api.Models;
namespace Sledgemapper.Api.Data
{
public static class DbInitializer
{
public static void Initialize(MyDbContext context)
{
context.Database.EnsureCreated();
}
}
public class MyDbContext : DbContext
{
public DbSet<MapLog> MapLogs { get; set; }
public DbSet<Session> Sessions { get; set; }
public DbSet<UserConnection> UserConnections { get; set; }
public DbSet<SessionUser> SessionUsers { get; set; }
public DbSet<Snapshot> Snapshots { get; set; }
public MyDbContext(DbContextOptions options) : base(options)
{
}
// protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
// {
// // optionsBuilder.
// // options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
// // optionsBuilder.UseSqlite("Filename=SledgemapperDatabase.db", options =>
// // {
// // options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
// // });
// optionsBuilder.UseSqlite("Filename=MyDatabase.db").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
// base.OnConfiguring(optionsBuilder);
// }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Map table names
modelBuilder.Entity<MapLog>().ToTable("MapLog", "dbo");
modelBuilder.Entity<MapLog>(entity =>
{
entity.HasKey(e => e.MapLogId);
});
modelBuilder.Entity<Session>().ToTable("Session", "dbo");
modelBuilder.Entity<Session>(entity =>
{
entity.HasKey(e => e.SessionId);
entity.HasIndex(e => e.SessionName).IsUnique();
});
modelBuilder.Entity<UserConnection>().ToTable("UserConnection", "dbo");
modelBuilder.Entity<UserConnection>(entity =>
{
entity.HasKey(e => e.UserConnectionId);
entity.HasIndex(e => e.UserId);
});
modelBuilder.Entity<SessionUser>().ToTable("SessionUser", "dbo");
modelBuilder.Entity<SessionUser>(entity =>
{
entity.HasKey(e => e.SessionUserId);
entity.HasIndex(e => e.SessionId);
});
modelBuilder.Entity<Snapshot>().ToTable("Snapshot", "dbo");
modelBuilder.Entity<Snapshot>(entity =>
{
entity.HasKey(e => e.SnapshotId);
});
base.OnModelCreating(modelBuilder);
}
}
}

View file

@ -1,5 +1,5 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications; using Sledgemapper.Api.Notifications;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
@ -13,11 +13,11 @@ namespace Sledgemapper.Api.Handlers
public class DeleteNoteCommandHandler : IRequestHandler<DeleteNoteCommand, bool> public class DeleteNoteCommandHandler : IRequestHandler<DeleteNoteCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public DeleteNoteCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public DeleteNoteCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(DeleteNoteCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(DeleteNoteCommand notification, CancellationToken cancellationToken)

View file

@ -1,6 +1,6 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Notifications; using Sledgemapper.Api.Notifications;
using System.Linq; using System.Linq;
@ -12,11 +12,11 @@ namespace Sledgemapper.Api.Handlers
{ {
public class DeleteOverlayCommandHandler : IRequestHandler<DeleteOverlayCommand, bool> public class DeleteOverlayCommandHandler : IRequestHandler<DeleteOverlayCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public DeleteOverlayCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public DeleteOverlayCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(DeleteOverlayCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(DeleteOverlayCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,7 +1,7 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications; using Sledgemapper.Api.Notifications;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using System.Linq; using System.Linq;
using System.Text.Json; using System.Text.Json;
@ -12,11 +12,11 @@ namespace Sledgemapper.Api.Handlers
{ {
public class DeleteTileCommandHandler : IRequestHandler<DeleteTileCommand,bool> public class DeleteTileCommandHandler : IRequestHandler<DeleteTileCommand,bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public DeleteTileCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public DeleteTileCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(DeleteTileCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(DeleteTileCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,5 +1,5 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications; using Sledgemapper.Api.Notifications;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
@ -13,11 +13,11 @@ namespace Sledgemapper.Api.Handlers
public class DeleteWallCommandHandler : IRequestHandler<DeleteWallCommand, bool> public class DeleteWallCommandHandler : IRequestHandler<DeleteWallCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public DeleteWallCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public DeleteWallCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(DeleteWallCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(DeleteWallCommand notification, CancellationToken cancellationToken)

View file

@ -1,5 +1,5 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
@ -11,9 +11,9 @@ namespace Sledgemapper.Api.Commands
{ {
public class GetMapSnapshotCommandHandler : IRequestHandler<GetMapSnapshotCommand, Sledgemapper.Shared.Entities.Session> public class GetMapSnapshotCommandHandler : IRequestHandler<GetMapSnapshotCommand, Sledgemapper.Shared.Entities.Session>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
public GetMapSnapshotCommandHandler(MyDbContext dbcontext) { _dbcontext = dbcontext; } public GetMapSnapshotCommandHandler(SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; }
public async Task<Sledgemapper.Shared.Entities.Session> Handle(GetMapSnapshotCommand notification, CancellationToken cancellationToken) public async Task<Sledgemapper.Shared.Entities.Session> Handle(GetMapSnapshotCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,5 +1,5 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using System.Linq; using System.Linq;
@ -12,11 +12,11 @@ namespace Sledgemapper.Api.Handlers
{ {
public class NewLineCommandHandler : IRequestHandler<NewLineCommand, bool> public class NewLineCommandHandler : IRequestHandler<NewLineCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public NewLineCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public NewLineCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewLineCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(NewLineCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,5 +1,5 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications; using Sledgemapper.Api.Notifications;
@ -12,11 +12,11 @@ namespace Sledgemapper.Api.Handlers
{ {
public class NewNoteCommandHandler : IRequestHandler<NewNoteCommand, bool> public class NewNoteCommandHandler : IRequestHandler<NewNoteCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public NewNoteCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public NewNoteCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewNoteCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(NewNoteCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,7 +1,7 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications; using Sledgemapper.Api.Notifications;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using System.Linq; using System.Linq;
using System.Text.Json; using System.Text.Json;
@ -12,11 +12,11 @@ namespace Sledgemapper.Api.Handlers
{ {
public class NewOverlayCommandHandler : IRequestHandler<NewOverlayCommand, bool> public class NewOverlayCommandHandler : IRequestHandler<NewOverlayCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public NewOverlayCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public NewOverlayCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewOverlayCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(NewOverlayCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,5 +1,5 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using System.Linq; using System.Linq;
@ -12,11 +12,11 @@ namespace Sledgemapper.Api.Handlers
{ {
public class NewRoomCommandHandler : IRequestHandler<NewRoomCommand, bool> public class NewRoomCommandHandler : IRequestHandler<NewRoomCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public NewRoomCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public NewRoomCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewRoomCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(NewRoomCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,5 +1,5 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
@ -10,10 +10,10 @@ namespace Sledgemapper.Api.Commands
{ {
public class NewSnapshotCommandHandler : IRequestHandler<NewSnapshotCommand, bool> public class NewSnapshotCommandHandler : IRequestHandler<NewSnapshotCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public NewSnapshotCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public NewSnapshotCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewSnapshotCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(NewSnapshotCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,5 +1,5 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
@ -12,10 +12,10 @@ namespace Sledgemapper.Api.Commands
{ {
public class NewTileCommandHandler : IRequestHandler<NewTileCommand, bool> public class NewTileCommandHandler : IRequestHandler<NewTileCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public NewTileCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public NewTileCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewTileCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(NewTileCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,5 +1,5 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications; using Sledgemapper.Api.Notifications;
@ -12,11 +12,11 @@ namespace Sledgemapper.Api.Handlers
{ {
public class NewWallCommandHandler : IRequestHandler<NewWallCommand, bool> public class NewWallCommandHandler : IRequestHandler<NewWallCommand, bool>
{ {
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator; private readonly IMediator _mediator;
public NewWallCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } public NewWallCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewWallCommand notification, CancellationToken cancellationToken) public async Task<bool> Handle(NewWallCommand notification, CancellationToken cancellationToken)
{ {

View file

@ -1,5 +1,5 @@
// using MediatR; // using MediatR;
// using Sledgemapper.Api.Data; // using Sledgemapper.Api.Infrastructure.Data;
// using System.Threading; // using System.Threading;
// using System.Threading.Tasks; // using System.Threading.Tasks;
// using Sledgemapper.Api.Notifications; // using Sledgemapper.Api.Notifications;
@ -9,10 +9,10 @@
// { // {
// public class PingCommandHandler : IRequestHandler<PingCommand, bool> // public class PingCommandHandler : IRequestHandler<PingCommand, bool>
// { // {
// private readonly MyDbContext _dbcontext; // private readonly SledgemapperDbContext _dbcontext;
// private readonly IMediator _mediator; // private readonly IMediator _mediator;
// public PingCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } // public PingCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
// public async Task<bool> Handle(PingCommand notification, CancellationToken cancellationToken) // public async Task<bool> Handle(PingCommand notification, CancellationToken cancellationToken)
// { // {

View file

@ -1,6 +1,6 @@
using MediatR; using MediatR;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Api.Models; using Sledgemapper.Api.Models;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,9 +10,9 @@ namespace Sledgemapper.Api.Handlers
public class StartNewSessionHandler : IRequestHandler<NewSessionCommand, bool> public class StartNewSessionHandler : IRequestHandler<NewSessionCommand, bool>
{ {
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly MyDbContext _dbcontext; private readonly SledgemapperDbContext _dbcontext;
public StartNewSessionHandler(IMediator mediator, MyDbContext dbcontext) public StartNewSessionHandler(IMediator mediator, SledgemapperDbContext dbcontext)
{ {
_mediator = mediator; _mediator = mediator;
_dbcontext = dbcontext; _dbcontext = dbcontext;

View file

@ -1,24 +1,24 @@
using Microsoft.EntityFrameworkCore; // using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; // using Microsoft.Extensions.Configuration;
using Sledgemapper.Entities; // using Sledgemapper.Entities;
namespace Sledgemapper.Helpers // namespace Sledgemapper.Helpers
{ // {
public class DataContext : DbContext // public class DataContext : DbContext
{ // {
protected readonly IConfiguration Configuration; // protected readonly IConfiguration Configuration;
public DataContext(IConfiguration configuration) // public DataContext(IConfiguration configuration)
{ // {
Configuration = configuration; // Configuration = configuration;
} // }
protected override void OnConfiguring(DbContextOptionsBuilder options) // protected override void OnConfiguring(DbContextOptionsBuilder options)
{ // {
// connect to sql server database // // connect to sql server database
options.UseSqlServer(Configuration.GetConnectionString("WebApiDatabase")); // options.UseSqlServer(Configuration.GetConnectionString("WebApiDatabase"));
} // }
public DbSet<User> Users { get; set; } // public DbSet<User> Users { get; set; }
} // }
} // }

View file

@ -1,16 +1,16 @@
using Microsoft.EntityFrameworkCore; // using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; // using Microsoft.Extensions.Configuration;
namespace Sledgemapper.Helpers // namespace Sledgemapper.Helpers
{ // {
public class SqliteDataContext : DataContext // public class SqliteDataContext : DataContext
{ // {
public SqliteDataContext(IConfiguration configuration) : base(configuration) { } // public SqliteDataContext(IConfiguration configuration) : base(configuration) { }
protected override void OnConfiguring(DbContextOptionsBuilder options) // protected override void OnConfiguring(DbContextOptionsBuilder options)
{ // {
// connect to sqlite database // // connect to sqlite database
options.UseSqlite(Configuration.GetConnectionString("WebApiDatabase")); // options.UseSqlite(Configuration.GetConnectionString("WebApiDatabase"));
} // }
} // }
} // }

View file

@ -6,7 +6,7 @@ using System.Collections.Concurrent;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using Sledgemapper.Clients; using Sledgemapper.Clients;
using System; using System;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Sledgemapper.Api.Models; using Sledgemapper.Api.Models;
using Sledgemapper.Helpers; using Sledgemapper.Helpers;
@ -17,13 +17,13 @@ namespace Sledgemapper.Api.Hubs
public class SledgemapperHub : Hub<ISledgemapperClient> public class SledgemapperHub : Hub<ISledgemapperClient>
{ {
private static readonly ConcurrentDictionary<int, string> UserColors = new(); private static readonly ConcurrentDictionary<int, string> UserColors = new();
private readonly MyDbContext _dbContext; private readonly SledgemapperDbContext _dbContext;
private readonly DataContext _datacontext; // private readonly DataContext _datacontext;
public SledgemapperHub(MyDbContext dbContext, DataContext datacontext) public SledgemapperHub(SledgemapperDbContext dbContext/*, DataContext datacontext*/)
{ {
_dbContext = dbContext; _dbContext = dbContext;
_datacontext = datacontext; // _datacontext = datacontext;
} }
// other colors // other colors
@ -89,7 +89,7 @@ namespace Sledgemapper.Api.Hubs
public async Task Ping(string sessionName, Tile location) public async Task Ping(string sessionName, Tile location)
{ {
var userId = int.Parse(Context.User.Identity.Name); var userId = int.Parse(Context.User.Identity.Name);
var user = _datacontext.Users.First(u => u.Id == userId); var user = _dbContext.Users.First(u => u.Id == userId);
var player = new Player { UserId = userId, Initials = user.Initials, Position = new Tile { X = 0, Y = 0 }, Color = UserColors[userId] }; var player = new Player { UserId = userId, Initials = user.Initials, Position = new Tile { X = 0, Y = 0 }, Color = UserColors[userId] };
await Clients.Group(sessionName).Ping(new Ping{X=location.X, Y=location.Y, Player=player}); await Clients.Group(sessionName).Ping(new Ping{X=location.X, Y=location.Y, Player=player});
@ -106,7 +106,7 @@ namespace Sledgemapper.Api.Hubs
_dbContext.SessionUsers.Add(userSession); _dbContext.SessionUsers.Add(userSession);
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
await Groups.AddToGroupAsync(Context.ConnectionId, session.SessionName); await Groups.AddToGroupAsync(Context.ConnectionId, session.SessionName);
var user = _datacontext.Users.First(u => u.Id == userId); var user = _dbContext.Users.First(u => u.Id == userId);
var player = new Player { UserId = userId, Initials = user.Initials, Position = new Tile { X = 0, Y = 0 }, Color = UserColors[userId] }; var player = new Player { UserId = userId, Initials = user.Initials, Position = new Tile { X = 0, Y = 0 }, Color = UserColors[userId] };
@ -131,7 +131,7 @@ namespace Sledgemapper.Api.Hubs
{ {
var userId = int.Parse(Context.User.Identity.Name); var userId = int.Parse(Context.User.Identity.Name);
var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == sessionId).OrderBy(m => m.UserId).ToList(); var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == sessionId).OrderBy(m => m.UserId).ToList();
var user = _datacontext.Users.First(u => u.Id == userId); var user = _dbContext.Users.First(u => u.Id == userId);
var player = new Player { UserId = userId, Initials = user.Initials, Position = tile, Color = UserColors[userId] }; var player = new Player { UserId = userId, Initials = user.Initials, Position = tile, Color = UserColors[userId] };
await Clients.Group(sessionName).PlayerUpdate(player); await Clients.Group(sessionName).PlayerUpdate(player);
} }

View file

@ -0,0 +1,214 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Sledgemapper.Api.Infrastructure.Data;
namespace Sledgemapper.Api.Migrations
{
[DbContext(typeof(SledgemapperDbContext))]
[Migration("20210214232542_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.3");
modelBuilder.Entity("Sledgemapper.Api.Models.Campaign", b =>
{
b.Property<int>("CampaignId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CampaignName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("OwnerUserId")
.HasColumnType("INTEGER");
b.HasKey("CampaignId");
b.ToTable("Campaigns");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Map", b =>
{
b.Property<int>("MapId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CampaignId")
.HasColumnType("INTEGER");
b.Property<string>("MapName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("MapId");
b.ToTable("Maps");
});
modelBuilder.Entity("Sledgemapper.Api.Models.MapLog", b =>
{
b.Property<int>("MapLogId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Object")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Operation")
.IsRequired()
.HasMaxLength(1)
.HasColumnType("TEXT");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<double>("Timestamp")
.HasColumnType("REAL");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("MapLogId");
b.ToTable("MapLogs");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Session", b =>
{
b.Property<int>("SessionId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("OwnerUserId")
.HasColumnType("INTEGER");
b.Property<string>("SessionName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("SessionId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Sledgemapper.Api.Models.SessionUser", b =>
{
b.Property<int>("SessionUserId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("SessionUserId");
b.ToTable("SessionUsers");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Snapshot", b =>
{
b.Property<int>("SnapshotId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Object")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<double>("Timestamp")
.HasColumnType("REAL");
b.HasKey("SnapshotId");
b.ToTable("Snapshots");
});
modelBuilder.Entity("Sledgemapper.Api.Models.UserConnection", b =>
{
b.Property<int>("UserConnectionId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ConnectionId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("UserConnectionId");
b.ToTable("UserConnections");
});
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("CampaignId")
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("Initials")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<byte[]>("PasswordHash")
.HasColumnType("BLOB");
b.Property<byte[]>("PasswordSalt")
.HasColumnType("BLOB");
b.Property<string>("Username")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CampaignId");
b.ToTable("Users");
});
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.HasOne("Sledgemapper.Api.Models.Campaign", null)
.WithMany("InvitedUsers")
.HasForeignKey("CampaignId");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Campaign", b =>
{
b.Navigation("InvitedUsers");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,171 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Sledgemapper.Api.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Campaigns",
columns: table => new
{
CampaignId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
CampaignName = table.Column<string>(type: "TEXT", nullable: false),
OwnerUserId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Campaigns", x => x.CampaignId);
});
migrationBuilder.CreateTable(
name: "MapLogs",
columns: table => new
{
MapLogId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
UserId = table.Column<int>(type: "INTEGER", nullable: false),
SessionId = table.Column<int>(type: "INTEGER", nullable: false),
Operation = table.Column<string>(type: "TEXT", maxLength: 1, nullable: false),
Type = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
Object = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
Timestamp = table.Column<double>(type: "REAL", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MapLogs", x => x.MapLogId);
});
migrationBuilder.CreateTable(
name: "Maps",
columns: table => new
{
MapId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
MapName = table.Column<string>(type: "TEXT", nullable: false),
CampaignId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Maps", x => x.MapId);
});
migrationBuilder.CreateTable(
name: "Sessions",
columns: table => new
{
SessionId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
SessionName = table.Column<string>(type: "TEXT", nullable: false),
OwnerUserId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Sessions", x => x.SessionId);
});
migrationBuilder.CreateTable(
name: "SessionUsers",
columns: table => new
{
SessionUserId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
SessionId = table.Column<int>(type: "INTEGER", nullable: false),
UserId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SessionUsers", x => x.SessionUserId);
});
migrationBuilder.CreateTable(
name: "Snapshots",
columns: table => new
{
SnapshotId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
SessionId = table.Column<int>(type: "INTEGER", nullable: false),
Object = table.Column<string>(type: "TEXT", nullable: false),
Timestamp = table.Column<double>(type: "REAL", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Snapshots", x => x.SnapshotId);
});
migrationBuilder.CreateTable(
name: "UserConnections",
columns: table => new
{
UserConnectionId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
UserId = table.Column<int>(type: "INTEGER", nullable: false),
ConnectionId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserConnections", x => x.UserConnectionId);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
FirstName = table.Column<string>(type: "TEXT", nullable: true),
LastName = table.Column<string>(type: "TEXT", nullable: true),
Username = table.Column<string>(type: "TEXT", nullable: true),
Initials = table.Column<string>(type: "TEXT", nullable: true),
PasswordHash = table.Column<byte[]>(type: "BLOB", nullable: true),
PasswordSalt = table.Column<byte[]>(type: "BLOB", nullable: true),
CampaignId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
table.ForeignKey(
name: "FK_Users_Campaigns_CampaignId",
column: x => x.CampaignId,
principalTable: "Campaigns",
principalColumn: "CampaignId",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_Users_CampaignId",
table: "Users",
column: "CampaignId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "MapLogs");
migrationBuilder.DropTable(
name: "Maps");
migrationBuilder.DropTable(
name: "Sessions");
migrationBuilder.DropTable(
name: "SessionUsers");
migrationBuilder.DropTable(
name: "Snapshots");
migrationBuilder.DropTable(
name: "UserConnections");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Campaigns");
}
}
}

View file

@ -0,0 +1,212 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Sledgemapper.Api.Infrastructure.Data;
namespace Sledgemapper.Api.Migrations
{
[DbContext(typeof(SledgemapperDbContext))]
partial class SledgemapperDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.3");
modelBuilder.Entity("Sledgemapper.Api.Models.Campaign", b =>
{
b.Property<int>("CampaignId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CampaignName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("OwnerUserId")
.HasColumnType("INTEGER");
b.HasKey("CampaignId");
b.ToTable("Campaigns");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Map", b =>
{
b.Property<int>("MapId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CampaignId")
.HasColumnType("INTEGER");
b.Property<string>("MapName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("MapId");
b.ToTable("Maps");
});
modelBuilder.Entity("Sledgemapper.Api.Models.MapLog", b =>
{
b.Property<int>("MapLogId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Object")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Operation")
.IsRequired()
.HasMaxLength(1)
.HasColumnType("TEXT");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<double>("Timestamp")
.HasColumnType("REAL");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("MapLogId");
b.ToTable("MapLogs");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Session", b =>
{
b.Property<int>("SessionId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("OwnerUserId")
.HasColumnType("INTEGER");
b.Property<string>("SessionName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("SessionId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Sledgemapper.Api.Models.SessionUser", b =>
{
b.Property<int>("SessionUserId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("SessionUserId");
b.ToTable("SessionUsers");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Snapshot", b =>
{
b.Property<int>("SnapshotId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Object")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<double>("Timestamp")
.HasColumnType("REAL");
b.HasKey("SnapshotId");
b.ToTable("Snapshots");
});
modelBuilder.Entity("Sledgemapper.Api.Models.UserConnection", b =>
{
b.Property<int>("UserConnectionId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ConnectionId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("UserConnectionId");
b.ToTable("UserConnections");
});
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("CampaignId")
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("Initials")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<byte[]>("PasswordHash")
.HasColumnType("BLOB");
b.Property<byte[]>("PasswordSalt")
.HasColumnType("BLOB");
b.Property<string>("Username")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CampaignId");
b.ToTable("Users");
});
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.HasOne("Sledgemapper.Api.Models.Campaign", null)
.WithMany("InvitedUsers")
.HasForeignKey("CampaignId");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Campaign", b =>
{
b.Navigation("InvitedUsers");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,88 @@
using Microsoft.EntityFrameworkCore;
using Sledgemapper.Api.Core.Entities.CampaignAggregate;
using Sledgemapper.Api.Models;
using Sledgemapper.Entities;
namespace Sledgemapper.Api.Infrastructure.Data
{
// public static class DbInitializer
// {
// public static void Initialize(SledgemapperDbContext context)
// {
// context.Database.EnsureCreated();
// }
// }
public class SledgemapperDbContext : DbContext
{
public DbSet<Sledgemapper.Api.Core.Entities.CampaignAggregate.Campaign> Campaigns { get; set; }
public DbSet<MapLog> MapLogs { get; set; }
public DbSet<Map> Maps { get; set; }
public DbSet<Session> Sessions { get; set; }
public DbSet<SessionUser> SessionUsers { get; set; }
public DbSet<Snapshot> Snapshots { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<UserConnection> UserConnections { get; set; }
public SledgemapperDbContext(DbContextOptions options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// optionsBuilder.
// options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
// optionsBuilder.UseSqlite("Filename=SledgemapperDatabase.db", options =>
// {
// options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
// });
optionsBuilder.UseSqlite("Filename=Sledgemapper.db").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
base.OnConfiguring(optionsBuilder);
}
// protected override void OnModelCreating(ModelBuilder modelBuilder)
// {
// // Map table names
// modelBuilder.Entity<MapLog>().ToTable("MapLog", "dbo");
// modelBuilder.Entity<MapLog>(entity =>
// {
// entity.HasKey(e => e.MapLogId);
// });
// modelBuilder.Entity<Session>().ToTable("Session", "dbo");
// modelBuilder.Entity<Session>(entity =>
// {
// entity.HasKey(e => e.SessionId);
// entity.HasIndex(e => e.SessionName).IsUnique();
// });
// modelBuilder.Entity<UserConnection>().ToTable("UserConnection", "dbo");
// modelBuilder.Entity<UserConnection>(entity =>
// {
// entity.HasKey(e => e.UserConnectionId);
// entity.HasIndex(e => e.UserId);
// });
// modelBuilder.Entity<SessionUser>().ToTable("SessionUser", "dbo");
// modelBuilder.Entity<SessionUser>(entity =>
// {
// entity.HasKey(e => e.SessionUserId);
// entity.HasIndex(e => e.SessionId);
// });
// modelBuilder.Entity<Snapshot>().ToTable("Snapshot", "dbo");
// modelBuilder.Entity<Snapshot>(entity =>
// {
// entity.HasKey(e => e.SnapshotId);
// });
// base.OnModelCreating(modelBuilder);
// }
}
}

View file

@ -1,10 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Entities; using Sledgemapper.Entities;
using Sledgemapper.Helpers; using Sledgemapper.Helpers;
namespace Sledgemapper.Services namespace Sledgemapper.Api.Infrastructure.Services
{ {
public interface IUserService public interface IUserService
{ {
@ -18,9 +19,9 @@ namespace Sledgemapper.Services
public class UserService : IUserService public class UserService : IUserService
{ {
private DataContext _context; private SledgemapperDbContext _context;
public UserService(DataContext context) public UserService(SledgemapperDbContext context)
{ {
_context = context; _context = context;
} }

View file

@ -1,53 +0,0 @@
// // <auto-generated />
// using System;
// using Microsoft.EntityFrameworkCore;
// using Microsoft.EntityFrameworkCore.Infrastructure;
// using Microsoft.EntityFrameworkCore.Metadata;
// using Microsoft.EntityFrameworkCore.Migrations;
// using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
// using Sledgemapper.Helpers;
// namespace Sledgemapper.Migrations.SqlServerMigrations
// {
// [DbContext(typeof(DataContext))]
// [Migration("20200102103423_InitialCreate")]
// partial class InitialCreate
// {
// protected override void BuildTargetModel(ModelBuilder modelBuilder)
// {
// #pragma warning disable 612, 618
// modelBuilder
// .HasAnnotation("ProductVersion", "3.1.0")
// .HasAnnotation("Relational:MaxIdentifierLength", 128)
// .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// modelBuilder.Entity("Sledgemapper.Entities.User", b =>
// {
// b.Property<int>("Id")
// .ValueGeneratedOnAdd()
// .HasColumnType("int")
// .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// b.Property<string>("FirstName")
// .HasColumnType("nvarchar(max)");
// b.Property<string>("LastName")
// .HasColumnType("nvarchar(max)");
// b.Property<byte[]>("PasswordHash")
// .HasColumnType("varbinary(max)");
// b.Property<byte[]>("PasswordSalt")
// .HasColumnType("varbinary(max)");
// b.Property<string>("Username")
// .HasColumnType("nvarchar(max)");
// b.HasKey("Id");
// b.ToTable("Users");
// });
// #pragma warning restore 612, 618
// }
// }
// }

View file

@ -1,33 +0,0 @@
// using Microsoft.EntityFrameworkCore.Migrations;
// namespace Sledgemapper.Migrations.SqlServerMigrations
// {
// public partial class InitialCreate : Migration
// {
// protected override void Up(MigrationBuilder migrationBuilder)
// {
// migrationBuilder.CreateTable(
// name: "Users",
// columns: table => new
// {
// Id = table.Column<int>(nullable: false)
// .Annotation("SqlServer:Identity", "1, 1"),
// FirstName = table.Column<string>(nullable: true),
// LastName = table.Column<string>(nullable: true),
// Username = table.Column<string>(nullable: true),
// PasswordHash = table.Column<byte[]>(nullable: true),
// PasswordSalt = table.Column<byte[]>(nullable: true)
// },
// constraints: table =>
// {
// table.PrimaryKey("PK_Users", x => x.Id);
// });
// }
// protected override void Down(MigrationBuilder migrationBuilder)
// {
// migrationBuilder.DropTable(
// name: "Users");
// }
// }
// }

View file

@ -1,51 +0,0 @@
// // <auto-generated />
// using System;
// using Microsoft.EntityFrameworkCore;
// using Microsoft.EntityFrameworkCore.Infrastructure;
// using Microsoft.EntityFrameworkCore.Metadata;
// using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
// using Sledgemapper.Helpers;
// namespace Sledgemapper.Migrations.SqlServerMigrations
// {
// [DbContext(typeof(DataContext))]
// partial class DataContextModelSnapshot : ModelSnapshot
// {
// protected override void BuildModel(ModelBuilder modelBuilder)
// {
// #pragma warning disable 612, 618
// modelBuilder
// .HasAnnotation("ProductVersion", "3.1.0")
// .HasAnnotation("Relational:MaxIdentifierLength", 128)
// .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// modelBuilder.Entity("Sledgemapper.Entities.User", b =>
// {
// b.Property<int>("Id")
// .ValueGeneratedOnAdd()
// .HasColumnType("int")
// .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// b.Property<string>("FirstName")
// .HasColumnType("nvarchar(max)");
// b.Property<string>("LastName")
// .HasColumnType("nvarchar(max)");
// b.Property<byte[]>("PasswordHash")
// .HasColumnType("varbinary(max)");
// b.Property<byte[]>("PasswordSalt")
// .HasColumnType("varbinary(max)");
// b.Property<string>("Username")
// .HasColumnType("nvarchar(max)");
// b.HasKey("Id");
// b.ToTable("Users");
// });
// #pragma warning restore 612, 618
// }
// }
// }

View file

@ -1,52 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Sledgemapper.Helpers;
namespace Sledgemapper.Migrations.SqliteMigrations
{
[DbContext(typeof(SqliteDataContext))]
[Migration("20200102102942_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.0");
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<string>("Initials")
.HasColumnType("TEXT");
b.Property<byte[]>("PasswordHash")
.HasColumnType("BLOB");
b.Property<byte[]>("PasswordSalt")
.HasColumnType("BLOB");
b.Property<string>("Username")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -1,34 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Sledgemapper.Migrations.SqliteMigrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
FirstName = table.Column<string>(nullable: true),
LastName = table.Column<string>(nullable: true),
Username = table.Column<string>(nullable: true),
Initials = table.Column<string>(nullable: true),
PasswordHash = table.Column<byte[]>(nullable: true),
PasswordSalt = table.Column<byte[]>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users");
}
}
}

View file

@ -1,50 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Sledgemapper.Helpers;
namespace Sledgemapper.Migrations.SqliteMigrations
{
[DbContext(typeof(SqliteDataContext))]
partial class SqliteDataContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.0");
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<string>("Initials")
.HasColumnType("TEXT");
b.Property<byte[]>("PasswordHash")
.HasColumnType("BLOB");
b.Property<byte[]>("PasswordSalt")
.HasColumnType("BLOB");
b.Property<string>("Username")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
namespace Sledgemapper.Api namespace Sledgemapper.Api
{ {
@ -37,8 +37,8 @@ namespace Sledgemapper.Api
var services = scope.ServiceProvider; var services = scope.ServiceProvider;
try try
{ {
var context = services.GetRequiredService<MyDbContext>(); var context = services.GetRequiredService<SledgemapperDbContext>();
DbInitializer.Initialize(context); // DbInitializer.Initialize(context);
} }
catch (Exception ex) catch (Exception ex)
{ {

View file

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Sledgemapper.Api.Data; using Sledgemapper.Api.Infrastructure.Data;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using MediatR; using MediatR;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
@ -14,9 +14,9 @@ using Sledgemapper.Helpers;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using System.Text; using System.Text;
using AutoMapper; using AutoMapper;
using Sledgemapper.Services;
using System.Security.Claims; using System.Security.Claims;
using Sledgemapper.Api.Hubs; using Sledgemapper.Api.Hubs;
using Sledgemapper.Api.Infrastructure.Services;
namespace Sledgemapper.Api namespace Sledgemapper.Api
{ {
@ -38,7 +38,7 @@ namespace Sledgemapper.Api
// if (_env.IsProduction()) // if (_env.IsProduction())
// services.AddDbContext<DataContext>(); // services.AddDbContext<DataContext>();
// else // else
services.AddDbContext<DataContext, SqliteDataContext>(); // services.AddDbContext<DataContext, SqliteDataContext>();
// services.AddRazorPages(); // services.AddRazorPages();
services.AddCors(); services.AddCors();
@ -46,9 +46,9 @@ namespace Sledgemapper.Api
services.AddSignalR(); services.AddSignalR();
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
services.AddMediatR(typeof(Startup)); services.AddMediatR(typeof(Startup));
services.AddDbContext<MyDbContext>(options => {options.UseSqlite("Data Source=db/sledgemapper.db"); options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);}); services.AddDbContext<SledgemapperDbContext>(options => {options.UseSqlite("Data Source=db/sledgemapper.db"); options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);});
// services.AddEntityFrameworkSqlite().AddDbContext<MyDbContext>(); // services.AddEntityFrameworkSqlite().AddDbContext<SledgemapperDbContext>();
// configure strongly typed settings objects // configure strongly typed settings objects
var c = Configuration.GetSection("AppSettings"); var c = Configuration.GetSection("AppSettings");
var appSettingsSection = Configuration.GetSection("AppSettings"); var appSettingsSection = Configuration.GetSection("AppSettings");
@ -98,7 +98,7 @@ namespace Sledgemapper.Api
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataContext dataContext) public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SledgemapperDbContext dataContext)
{ {
dataContext.Database.Migrate(); dataContext.Database.Migrate();