Merge branch 'master' into SES-68
This commit is contained in:
commit
0196595df2
@ -14,10 +14,16 @@ namespace SessionCompanion.Database
|
||||
public virtual DbSet<Background> Backgrounds { get; set; }
|
||||
public virtual DbSet<Biography> Biographies { get; set; }
|
||||
public virtual DbSet<Character> Characters { get; set; }
|
||||
public virtual DbSet<Charisma> Charismas { get; set; }
|
||||
public virtual DbSet<Class> Classes { get; set; }
|
||||
public virtual DbSet<Constitution> Constitutions { get; set; }
|
||||
public virtual DbSet<Dexterity> Dexterities { get; set; }
|
||||
public virtual DbSet<Intelligence> Intelligences { get; set; }
|
||||
public virtual DbSet<Race> Races { get; set; }
|
||||
public virtual DbSet<Statistics> Statistics { get; set; }
|
||||
public virtual DbSet<Strength> Strengths { get; set; }
|
||||
public virtual DbSet<User> Users { get; set; }
|
||||
public virtual DbSet<Wisdom> Wisdoms { get; set; }
|
||||
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories
|
||||
{
|
||||
public class AlignmentRepository : Repository<Alignment>, IRepository<Alignment>
|
||||
{
|
||||
public AlignmentRepository(ApplicationDbContext _dbContext) : base(_dbContext)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories
|
||||
{
|
||||
public class BackgroundRepository : Repository<Background>, IRepository<Background>
|
||||
{
|
||||
public BackgroundRepository(ApplicationDbContext _dbContext) : base(_dbContext)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories.Base
|
||||
{
|
||||
public interface IRepository<T> where T : BaseEntity
|
||||
{
|
||||
IQueryable<T> Get();
|
||||
IQueryable<T> Get(Expression<Func<T, bool>> expression);
|
||||
Task<T> Get(int id);
|
||||
Task Create(T entity);
|
||||
Task Update(T entity);
|
||||
void Delete(T entity);
|
||||
Task<bool> Any(Expression<Func<T, bool>> expression);
|
||||
Task<bool> Any(int id);
|
||||
void Dispose();
|
||||
Task Save();
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories.Base
|
||||
{
|
||||
public class Repository<T> : IRepository<T> where T : BaseEntity
|
||||
{
|
||||
protected ApplicationDbContext RepositoryContext { get; set; }
|
||||
|
||||
public Repository(ApplicationDbContext repositoryContext)
|
||||
{
|
||||
this.RepositoryContext = repositoryContext;
|
||||
}
|
||||
|
||||
public IQueryable<T> Get()
|
||||
{
|
||||
return this.RepositoryContext.Set<T>();
|
||||
}
|
||||
|
||||
public IQueryable<T> Get(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return this.RepositoryContext.Set<T>().Where(expression);
|
||||
}
|
||||
|
||||
public Task<bool> Any(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return RepositoryContext.Set<T>().AnyAsync(expression);
|
||||
}
|
||||
|
||||
public Task<bool> Any(int id)
|
||||
{
|
||||
return RepositoryContext.Set<T>().AnyAsync(n => n.Id == id);
|
||||
}
|
||||
|
||||
|
||||
public async Task<T> Get(int id)
|
||||
{
|
||||
return await RepositoryContext.Set<T>().FindAsync(id);
|
||||
}
|
||||
|
||||
public virtual Task Create(T entity)
|
||||
{
|
||||
return Task.FromResult(RepositoryContext.Set<T>().AddAsync(entity));
|
||||
}
|
||||
|
||||
public virtual Task Update(T entity)
|
||||
{
|
||||
return Task.FromResult(RepositoryContext.Set<T>().Update(entity));
|
||||
}
|
||||
|
||||
public virtual void Delete(T entity)
|
||||
{
|
||||
this.RepositoryContext.Set<T>().Remove(entity);
|
||||
}
|
||||
|
||||
public virtual async Task Save()
|
||||
{
|
||||
await RepositoryContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
RepositoryContext.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories
|
||||
{
|
||||
public class BiographyRepository : Repository<Biography>, IRepository<Biography>
|
||||
{
|
||||
public BiographyRepository(ApplicationDbContext _dbContext) : base(_dbContext)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories
|
||||
{
|
||||
public class CharacterRepository : Repository<Character>, IRepository<Character>
|
||||
{
|
||||
public CharacterRepository(ApplicationDbContext _dbContext) : base(_dbContext)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories
|
||||
{
|
||||
public class ClassRepository : Repository<Class>, IRepository<Class>
|
||||
{
|
||||
public ClassRepository(ApplicationDbContext _dbContext) : base(_dbContext)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories
|
||||
{
|
||||
public class RaceRepository : Repository<Race>, IRepository<Race>
|
||||
{
|
||||
public RaceRepository(ApplicationDbContext _dbContext) : base(_dbContext)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories
|
||||
{
|
||||
public class StatisticsRepository : Repository<Statistics>, IRepository<Statistics>
|
||||
{
|
||||
public StatisticsRepository(ApplicationDbContext _dbContext) : base(_dbContext)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Repositories
|
||||
{
|
||||
public class UserRepository : Repository<User>, IRepository<User>
|
||||
{
|
||||
public UserRepository(ApplicationDbContext _dbContext) : base(_dbContext)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -13,5 +13,11 @@ namespace SessionCompanion.Database.Tables
|
||||
public virtual User User { get; set; }
|
||||
public virtual Biography Biography { get; set; }
|
||||
public virtual Statistics Statistics { get; set; }
|
||||
public virtual Charisma Charisma { get; set; }
|
||||
public virtual Constitution Constitution { get; set; }
|
||||
public virtual Dexterity Dexterity { get; set; }
|
||||
public virtual Intelligence Intelligence { get; set; }
|
||||
public virtual Strength Strength { get; set; }
|
||||
public virtual Wisdom Wisdom { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Tables
|
||||
{
|
||||
public class Charisma : BaseEntity
|
||||
{
|
||||
[ForeignKey(nameof(Character))]
|
||||
public int CharacterId { get; set; }
|
||||
public virtual Character Character { get; set; }
|
||||
|
||||
public int Value { get; set; }
|
||||
public int Modification { get; set; }
|
||||
public int SavingThrows { get; set; }
|
||||
public bool CanSaveThrows { get; set; }
|
||||
public int Deception { get; set; }
|
||||
public bool CanDeception { get; set; }
|
||||
public int Intimidation { get; set; }
|
||||
public bool CanIntimidation { get; set; }
|
||||
public int Performance { get; set; }
|
||||
public bool CanPerformance { get; set; }
|
||||
public int Persuasion { get; set; }
|
||||
public bool CanPersuasion { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Tables
|
||||
{
|
||||
public class Constitution : BaseEntity
|
||||
{
|
||||
[ForeignKey(nameof(Character))]
|
||||
public int CharacterId { get; set; }
|
||||
public virtual Character Character { get; set; }
|
||||
|
||||
public int Value { get; set; }
|
||||
public int Modification { get; set; }
|
||||
public int SavingThrows { get; set; }
|
||||
public bool CanSaveThrows { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Tables
|
||||
{
|
||||
public class Dexterity : BaseEntity
|
||||
{
|
||||
[ForeignKey(nameof(Character))]
|
||||
public int CharacterId { get; set; }
|
||||
public virtual Character Character { get; set; }
|
||||
|
||||
public int Value { get; set; }
|
||||
public int Modification { get; set; }
|
||||
public int SavingThrows { get; set; }
|
||||
public bool CanSaveThrows { get; set; }
|
||||
public int Acrobatics { get; set; }
|
||||
public bool CanAcrobatics { get; set; }
|
||||
public int SleightOfHand { get; set; }
|
||||
public bool CanSleightOfHand { get; set; }
|
||||
public int Stealth { get; set; }
|
||||
public bool CanStealth { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Tables
|
||||
{
|
||||
public class Intelligence : BaseEntity
|
||||
{
|
||||
[ForeignKey(nameof(Character))]
|
||||
public int CharacterId { get; set; }
|
||||
public virtual Character Character { get; set; }
|
||||
|
||||
public int Value { get; set; }
|
||||
public int Modification { get; set; }
|
||||
public int SavingThrows { get; set; }
|
||||
public bool CanSaveThrows { get; set; }
|
||||
public int Arcana { get; set; }
|
||||
public bool CanArcana { get; set; }
|
||||
public int History { get; set; }
|
||||
public bool CanHistory { get; set; }
|
||||
public int Investigation { get; set; }
|
||||
public bool CanInvestigation { get; set; }
|
||||
public int Nature { get; set; }
|
||||
public bool CanNature { get; set; }
|
||||
public int Religion { get; set; }
|
||||
public bool CanReligion { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Tables
|
||||
{
|
||||
public class Strength : BaseEntity
|
||||
{
|
||||
[ForeignKey(nameof(Character))]
|
||||
public int CharacterId { get; set; }
|
||||
public virtual Character Character { get; set; }
|
||||
|
||||
public int Value { get; set; }
|
||||
public int Modification { get; set; }
|
||||
public int SavingThrows { get; set; }
|
||||
public bool CanSaveThrows { get; set; }
|
||||
public int Athletics { get; set; }
|
||||
public bool CanAthletics { get; set; }
|
||||
}
|
||||
}
|
29
SessionCompanion/SessionCompanion.Database/Tables/Wisdom.cs
Normal file
29
SessionCompanion/SessionCompanion.Database/Tables/Wisdom.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace SessionCompanion.Database.Tables
|
||||
{
|
||||
public class Wisdom : BaseEntity
|
||||
{
|
||||
[ForeignKey(nameof(Character))]
|
||||
public int CharacterId { get; set; }
|
||||
public virtual Character Character { get; set; }
|
||||
|
||||
public int Value { get; set; }
|
||||
public int Modification { get; set; }
|
||||
public int SavingThrows { get; set; }
|
||||
public bool CanSaveThrows { get; set; }
|
||||
public int AnimalHandling { get; set; }
|
||||
public bool CanAnimalHandling { get; set; }
|
||||
public int Insight { get; set; }
|
||||
public bool CanInsight { get; set; }
|
||||
public int Medicine { get; set; }
|
||||
public bool CanMedicine { get; set; }
|
||||
public int Perception { get; set; }
|
||||
public bool CanPerception { get; set; }
|
||||
public int Survival { get; set; }
|
||||
public bool CanSurvival { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SessionCompanion.Database.Repositories;
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SessionCompanion.Configurations
|
||||
{
|
||||
public static class RepositoryConfiguration
|
||||
{
|
||||
public static IServiceCollection AddRepositories(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<IRepository<Alignment>, AlignmentRepository>();
|
||||
services.AddScoped<IRepository<Background>, BackgroundRepository>();
|
||||
services.AddScoped<IRepository<Biography>, BiographyRepository>();
|
||||
services.AddScoped<IRepository<Character>, CharacterRepository>();
|
||||
services.AddScoped<IRepository<Class>, ClassRepository>();
|
||||
services.AddScoped<IRepository<Race>, RaceRepository>();
|
||||
services.AddScoped<IRepository<Statistics>, StatisticsRepository>();
|
||||
services.AddScoped<IRepository<User>, UserRepository>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using SessionCompanion.Configurations;
|
||||
using SessionCompanion.Database;
|
||||
|
||||
namespace SessionCompanion
|
||||
@ -27,6 +28,8 @@ namespace SessionCompanion
|
||||
services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseSqlServer(
|
||||
Configuration.GetConnectionString("DefaultConnection")));
|
||||
services.AddRepositories();
|
||||
|
||||
// In production, the Angular files will be served from this directory
|
||||
services.AddSpaStaticFiles(configuration =>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user