SES-121 Added spells tables #43

Merged
s426135 merged 2 commits from SES-121 into dev 2021-01-03 15:54:48 +01:00
25 changed files with 541 additions and 2 deletions
Showing only changes of commit 4b0382a931 - Show all commits

View File

@ -24,7 +24,9 @@ namespace SessionCompanion.Database
public virtual DbSet<Strength> Strengths { get; set; }
public virtual DbSet<User> Users { get; set; }
public virtual DbSet<Wisdom> Wisdoms { get; set; }
public virtual DbSet<Spell> Spells { get; set; }
public virtual DbSet<CharacterSpell> CharacterSpells { get; set; }
public virtual DbSet<CharacterSpellSlots> CharacterSpellSlots { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder builder)

View File

@ -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 CharacterSpellRepository : Repository<CharacterSpell>, IRepository<CharacterSpell>
{
public CharacterSpellRepository(ApplicationDbContext _dbContext) : base(_dbContext)
{ }
}
}

View File

@ -0,0 +1,14 @@
using SessionCompanion.Database.Repositories.Base;
using SessionCompanion.Database.Tables;
namespace SessionCompanion.Database.Repositories
{
public class CharacterSpellSlotsRepository: Repository<CharacterSpellSlots>, IRepository<CharacterSpellSlots>
{
public CharacterSpellSlotsRepository(ApplicationDbContext _dbContext)
: base(_dbContext)
{
}
}
}

View File

@ -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 SpellRepository : Repository<Spell>, IRepository<Spell>
{
public SpellRepository(ApplicationDbContext _dbContext) : base(_dbContext)
{ }
}
}

View File

@ -17,4 +17,8 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SessionCompanion.ViewModels\SessionCompanion.ViewModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace SessionCompanion.Database.Tables
{
public class CharacterSpell : BaseEntity
{
[ForeignKey(nameof(Character))]
public int CharacterId { get; set; }
public virtual Character Character { get; set; }
[ForeignKey(nameof(Spell))]
public int SpellId { get; set; }
public virtual Spell Spell { get; set; }
}
}

View File

@ -0,0 +1,48 @@

namespace SessionCompanion.Database.Tables
{
using System.ComponentModel.DataAnnotations.Schema;
public class CharacterSpellSlots : BaseEntity
{
[ForeignKey(nameof(Character))]
public int CharacterId { get; set; }
public virtual Character Character { get; set; }
public int FirstLevelSlots { get; set; }
public int FirstLevelSlotsUsed { get; set; }
public int SecondLevelSlots { get; set; }
public int SecondLevelSlotsUsed { get; set; }
public int ThirdLevelSlots { get; set; }
public int ThirdLevelSlotsUsed { get; set; }
public int FourthLevelSlots { get; set; }
public int FourthLevelSlotsUsed { get; set; }
public int FifthLevelSlots { get; set; }
public int FifthLevelSlotsUsed { get; set; }
public int SixthLevelSlots { get; set; }
public int SixthLevelSlotsUsed { get; set; }
public int SeventhLevelSlots { get; set; }
public int SeventhLevelSlotsUsed { get; set; }
public int EightLevelSlots { get; set; }
public int EightLevelSlotsUsed { get; set; }
public int NinthLevelSlots { get; set; }
public int NinthLevelSlotsUsed { get; set; }
}
}

View File

@ -0,0 +1,25 @@
using System.Collections.Generic;
using static SessionCompanion.ViewModels.Enums.SpellsEnums;
namespace SessionCompanion.Database.Tables
{
public class Spell : BaseEntity
{
public string Name { get; set; }
public string Description { get; set; }
public string HigherLevel { get; set; }
public Ranges Range { get; set; }
public string Components { get; set; }
public string Material { get; set; }
public bool Ritual { get; set; }
public Durations Duration { get; set; }
public bool Concentration { get; set; }
public CastingTimes CastingTime { get; set; }
public int Level { get; set; }
public Schools School { get; set; }
public string Classes { get; set; }
public string Subclasses { get; set; }
public virtual ICollection<CharacterSpell> CharacterSpells { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base;
using SessionCompanion.ViewModels.CharacterSpellViewModels;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SessionCompanion.Services.Interfaces
{
public interface ICharacterSpellService : IServiceBase<CharacterSpellViewModel, CharacterSpell>
{
}
}

View File

@ -0,0 +1,12 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base;
using SessionCompanion.ViewModels.CharacterSpellSlotsViewModels;
namespace SessionCompanion.Services.Interfaces
{
public interface ICharacterSpellSlotsService : IServiceBase<CharacterSpellSlotsViewModel,CharacterSpellSlots>
{
}
}

View File

@ -0,0 +1,13 @@
using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base;
using SessionCompanion.ViewModels.SpellViewModels;
using System;
using System.Collections.Generic;
using System.Text;
namespace SessionCompanion.Services.Interfaces
{
public interface ISpellService : IServiceBase<SpellViewModel, Spell>
{
}
}

View File

@ -0,0 +1,33 @@
using AutoMapper;
using SessionCompanion.Database.Tables;
using SessionCompanion.ViewModels.CharacterSpellViewModels;
using System.Linq;
namespace SessionCompanion.Services.Profiles
{
public class CharacterSpellProfile : Profile
{
public CharacterSpellProfile()
{
CreateMap<CharacterSpellViewModel, CharacterSpell>().ReverseMap();
CreateMap<CharacterSpellWithSpellDetailsViewModel, CharacterSpell>();
CreateMap<CharacterSpell, CharacterSpellWithSpellDetailsViewModel>()
.ForMember(vm => vm.Level, conf => conf.MapFrom(spell => spell.Spell.Level))
.ForMember(vm => vm.Concentration, conf => conf.MapFrom(spell => spell.Spell.Concentration))
.ForMember(vm => vm.Ritual, conf => conf.MapFrom(spell => spell.Spell.Ritual))
.ForMember(vm => vm.Name, conf => conf.MapFrom(spell => spell.Spell.Name.ToString()))
.ForMember(vm => vm.Material, conf => conf.MapFrom(spell => spell.Spell.Material.ToString()))
.ForMember(vm => vm.Range, conf => conf.MapFrom(spell => spell.Spell.Range.ToString()))
.ForMember(vm => vm.Duration, conf => conf.MapFrom(spell => spell.Spell.Duration.ToString()))
.ForMember(vm => vm.CastingTime, conf => conf.MapFrom(spell => spell.Spell.CastingTime.ToString()))
.ForMember(vm => vm.School, conf => conf.MapFrom(spell => spell.Spell.School.ToString()))
.ForMember(vm => vm.Descriptions, conf => conf.MapFrom(spell => spell.Spell.Description.Split(new char[] { ';' }).ToList()))
.ForMember(vm => vm.Components, conf => conf.MapFrom(spell => spell.Spell.Components.Split(new char[] { ';' }).ToList()))
.ForMember(vm => vm.HigherLevel, conf => conf.MapFrom(spell => spell.Spell.HigherLevel.Split(new char[] { ';' }).ToList()))
.ForMember(vm => vm.Classes, conf => conf.MapFrom(spell => spell.Spell.Classes.Split(new char[] { ';' }).ToList()))
.ForMember(vm => vm.Subclasses, conf => conf.MapFrom(spell => spell.Spell.Subclasses.Split(new char[] { ';' }).ToList()));
}
}
}

View File

@ -0,0 +1,14 @@
using AutoMapper;
using SessionCompanion.Database.Tables;
using SessionCompanion.ViewModels.CharacterSpellSlotsViewModels;
namespace SessionCompanion.Services.Profiles
{
public class CharacterSpellSlotsProfile : Profile
{
public CharacterSpellSlotsProfile()
{
CreateMap<CharacterSpellSlotsViewModel, CharacterSpellSlots>().ReverseMap();
}
}
}

View File

@ -0,0 +1,34 @@
using AutoMapper;
using SessionCompanion.Database.Tables;
using SessionCompanion.ViewModels.SpellViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SessionCompanion.Services.Profiles
{
public class SpellProfile : Profile
{
public SpellProfile()
{
CreateMap<SpellViewModel, Spell>()
.ForMember(model => model.Description, conf => conf.MapFrom(spell => string.Join(";", spell.Descriptions.Select(s => s.ToString()))))
.ForMember(model => model.Components, conf => conf.MapFrom(spell => string.Join(";", spell.Components.Select(s => s.ToString()))))
.ForMember(model => model.HigherLevel, conf => conf.MapFrom(spell => string.Join(";", spell.HigherLevel.Select(s => s.ToString()))))
.ForMember(model => model.Classes, conf => conf.MapFrom(spell => string.Join(";", spell.Classes.Select(s => s.ToString()))))
.ForMember(model => model.Subclasses, conf => conf.MapFrom(spell => string.Join(";", spell.Subclasses.Select(s => s.ToString()))));
CreateMap<Spell, SpellViewModel>()
.ForMember(vm => vm.Range, conf => conf.MapFrom(spell => spell.Range.ToString()))
.ForMember(vm => vm.Duration, conf => conf.MapFrom(spell => spell.Duration.ToString()))
.ForMember(vm => vm.CastingTime, conf => conf.MapFrom(spell => spell.CastingTime.ToString()))
.ForMember(vm => vm.School, conf => conf.MapFrom(spell => spell.School.ToString()))
.ForMember(vm => vm.Descriptions, conf => conf.MapFrom(spell => spell.Description.Split(new char[] { ';' }).ToList()))
.ForMember(vm => vm.Components, conf => conf.MapFrom(spell => spell.Components.Split(new char[] { ';' }).ToList()))
.ForMember(vm => vm.HigherLevel, conf => conf.MapFrom(spell => spell.HigherLevel.Split(new char[] { ';' }).ToList()))
.ForMember(vm => vm.Classes, conf => conf.MapFrom(spell => spell.Classes.Split(new char[] { ';' }).ToList()))
.ForMember(vm => vm.Subclasses, conf => conf.MapFrom(spell => spell.Subclasses.Split(new char[] { ';' }).ToList()));
}
}
}

View File

@ -0,0 +1,20 @@
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using SessionCompanion.Database.Repositories.Base;
using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.CharacterSpellViewModels;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SessionCompanion.Services.Services
{
public class CharacterSpellService : ServiceBase<CharacterSpellViewModel, CharacterSpell>, ICharacterSpellService
{
public CharacterSpellService(IMapper mapper, IRepository<CharacterSpell> repository) : base(mapper, repository)
{ }
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using SessionCompanion.Database.Repositories.Base;
using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.CharacterSpellSlotsViewModels;
namespace SessionCompanion.Services.Services
{
public class CharacterSpellSlotsService : ServiceBase<CharacterSpellSlotsViewModel, CharacterSpellSlots>, ICharacterSpellSlotsService
{
public CharacterSpellSlotsService(IMapper mapper, IRepository<CharacterSpellSlots> repository) : base(mapper, repository) { }
}
}

View File

@ -0,0 +1,18 @@
using AutoMapper;
using SessionCompanion.Database.Repositories.Base;
using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.SpellViewModels;
using System;
using System.Collections.Generic;
using System.Text;
namespace SessionCompanion.Services.Services
{
public class SpellService : ServiceBase<SpellViewModel, Spell>, ISpellService
{
public SpellService(IMapper mapper, IRepository<Spell> repository) : base(mapper, repository)
{ }
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SessionCompanion.ViewModels.CharacterSpellSlotsViewModels
{
public class CharacterSpellSlotsViewModel
{
public int Id { get; set; }
public int CharacterId { get; set; }
public int? FirstLevelSlots { get; set; }
public int FirstLevelSlotsUsed { get; set; }
public int SecondLevelSlots { get; set; }
public int SecondLevelSlotsUsed { get; set; }
public int ThirdLevelSlots { get; set; }
public int ThirdLevelSlotsUsed { get; set; }
public int FourthLevelSlots { get; set; }
public int FourthLevelSlotsUsed { get; set; }
public int FifthLevelSlots { get; set; }
public int FifthLevelSlotsUsed { get; set; }
public int SixthLevelSlots { get; set; }
public int SixthLevelSlotsUsed { get; set; }
public int SeventhLevelSlots { get; set; }
public int SeventhLevelSlotsUsed { get; set; }
public int EightLevelSlots { get; set; }
public int EightLevelSlotsUsed { get; set; }
public int NinthLevelSlots { get; set; }
public int NinthLevelSlotsUsed { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace SessionCompanion.ViewModels.CharacterSpellViewModels
{
public class CharacterSpellViewModel
{
public int Id { get; set; }
public int CharacterId { get; set; }
public int SpellId { get; set; }
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SessionCompanion.ViewModels.CharacterSpellViewModels
{
public class CharacterSpellWithSpellDetailsViewModel
{
public int SpellId { get; set; }
public string Name { get; set; }
public List<string> Descriptions { get; set; }
public List<string> HigherLevel { get; set; }
public string Range { get; set; }
public List<string> Components { get; set; }
public string Material { get; set; }
public bool Ritual { get; set; }
public string Duration { get; set; }
public bool Concentration { get; set; }
public string CastingTime { get; set; }
public int Level { get; set; }
public string School { get; set; }
public List<string> Classes { get; set; }
public List<string> Subclasses { get; set; }
}
}

View File

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SessionCompanion.ViewModels.Enums
{
public class SpellsEnums
{
public enum Components
{
V,
S,
M
}
public enum Ranges
{
Self,
Touch,
Special,
Sight,
Unlimited,
Feet_5,
Feet_10,
Feet_30,
Feet_60,
Feet_90,
Feet_100,
Feet_120,
Feet_150,
Feet_300,
Feet_500,
Miles_1,
Miles_500
}
public enum Durations
{
Instantaneous,
Until_dispelled,
Special,
Minutes_1,
Minutes_10,
Hours_1,
Hours_2,
Hours_8,
Hours_24,
Days_7,
Days_10,
Days_30,
Round_1
}
public enum CastingTimes
{
Minutes_1,
Minutes_10,
Hours_1,
Hours_8,
Hours_12,
Hours_24,
Action_1,
Reaction_1,
Bonus_Action_1
}
public enum Schools
{
Evocation,
Conjuration,
Abjuration,
Transmutation,
Enchantment,
Necromancy,
Divination,
Illusion
}
public enum Classes
{
Wizard,
Sorcerer,
Cleric,
Paladin,
Ranger,
Bard,
Druid,
Warlock
}
public enum Subclass
{
Lore,
Land,
Life,
Devotion,
Fiend
}
}
}

View File

@ -13,4 +13,8 @@
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Enums\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace SessionCompanion.ViewModels.SpellViewModels
{
public class SpellViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public List<string> Descriptions { get; set; }
public List<string> HigherLevel { get; set; }
public string Range { get; set; }
public List<string> Components { get; set; }
public string Material { get; set; }
public bool Ritual { get; set; }
public string Duration { get; set; }
public bool Concentration { get; set; }
public string CastingTime { get; set; }
public int Level { get; set; }
public string School { get; set; }
public List<string> Classes { get; set; }
public List<string> Subclasses { get; set; }
}
}

View File

@ -27,7 +27,9 @@ namespace SessionCompanion.Configurations
services.AddScoped<IRepository<Strength>, StrengthRepository>();
services.AddScoped<IRepository<User>, UserRepository>();
services.AddScoped<IRepository<Wisdom>, WisdomRepository>();
services.AddScoped<IRepository<Spell>, SpellRepository>();
services.AddScoped<IRepository<CharacterSpell>, CharacterSpellRepository>();
services.AddScoped<IRepository<CharacterSpellSlots>, CharacterSpellSlotsRepository>();
return services;
}
}

View File

@ -26,6 +26,10 @@ namespace SessionCompanion.Configurations
services.AddScoped<IStrengthService, StrengthService>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<IWisdomService, WisdomService>();
services.AddScoped<ISpellService, SpellService>();
services.AddScoped<ICharacterSpellService, CharacterSpellService>();
services.AddScoped<ICharacterSpellSlotsService, CharacterSpellSlotsService>();
return services;
}
}