Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KrystianKempski committed Dec 24, 2024
2 parents 158ce18 + c5fc710 commit 46c16b9
Show file tree
Hide file tree
Showing 223 changed files with 8,295 additions and 5,196 deletions.
7 changes: 4 additions & 3 deletions DA_Business/DA_Business.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -24,13 +24,14 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Dapper" Version="2.1.28" />
<PackageReference Include="MudBlazor" Version="6.21.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.8" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="Npgsql" Version="9.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0" />
<PackageReference Include="Syncfusion.Blazor.Grid" Version="27.1.56" />
<PackageReference Include="Syncfusion.Blazor.RichTextEditor" Version="27.1.56" />
<PackageReference Include="Syncfusion.Blazor.Themes" Version="27.1.56" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions DA_Business/Mapper/MappingProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public MappingProfile()
CreateMap<SpellCircle, SpellCircleDTO>().ReverseMap();
CreateMap<Wound, WoundDTO>().ReverseMap();
CreateMap<Wound, ConditionDTO>().ReverseMap();
CreateMap<WealthRecord, WealthRecordDTO>().ReverseMap();
}
}
}
7 changes: 7 additions & 0 deletions DA_Business/Repository/CharacterReps/CharacterRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ public async Task<IEnumerable<CharacterDTO>> GetAllForCampaign(int campaignId, b
return null;
}

public async Task<bool> CheckIfCharacterBelongToUser(string userName, int characterId)
{
using var contex = await _db.CreateDbContextAsync();
var obj = await contex.Characters.FirstOrDefaultAsync(u => u.Id == characterId && u.UserName == userName);
return obj is not null;
}

public async Task<CharacterDTO> Update(CharacterDTO objDTO)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public interface ICharacterRepository

public Task<IEnumerable<CharacterDTO>> GetAllApproved(string? userName = null, bool fullIncludes = false);
public Task<string> GetPortraitUrl(int id);
public Task<bool> CheckIfCharacterBelongToUser(string userName, int characterId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface ISpecialSkillRepository

public Task<SpecialSkillDTO> GetById(int id);
public Task<IDictionary<string, SpecialSkillDTO>> GetAll(int? baseId = null);
public Task<IEnumerable<SpecialSkillDTO>> GetAllFromGroup(int charId, string baseSkillName);

public Task Delete(SpecialSkillDTO objDTO);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using DA_DataAccess.CharacterClasses;
using DA_Models.CharacterModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DA_Business.Repository.CharacterReps.IRepository
{
public interface IWealthRecordRepository
{
public Task<WealthRecordDTO> Create(WealthRecordDTO objDTO);

public Task<WealthRecordDTO> Update(WealthRecordDTO objDTO);
public Task<int> Delete(int id);

public Task<WealthRecordDTO> GetById(int id);
public Task<IEnumerable<WealthRecordDTO>> GetAll(int? charId = null);
}
}
22 changes: 22 additions & 0 deletions DA_Business/Repository/CharacterReps/SpecialSkillRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ public async Task<IDictionary<string, SpecialSkillDTO>> GetAll(int? charId = nul
return new Dictionary<string, SpecialSkillDTO>();
}

public async Task<IEnumerable<SpecialSkillDTO>> GetAllFromGroup(int charId ,string baseSkillName)
{
try
{
List<SpecialSkill> obj;
using var contex = await _db.CreateDbContextAsync();
if (charId == null || charId < 1 || baseSkillName == string.Empty)
{
return new List<SpecialSkillDTO>();
}
else
{
obj = contex.SpecialSkills.Where(u => u.CharacterId == charId && u.RelatedBaseSkillName == baseSkillName).OrderBy(u => u.Index).ToList();
return _mapper.Map<IEnumerable<SpecialSkill>, IEnumerable<SpecialSkillDTO>>(obj);
}
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}

public async Task<SpecialSkillDTO> GetById(int id)
{
using var contex = await _db.CreateDbContextAsync();
Expand Down
122 changes: 122 additions & 0 deletions DA_Business/Repository/CharacterReps/WealthRecordRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using Abp.Collections.Extensions;
using AutoMapper;
using Castle.MicroKernel.Registration;
using DA_Business.Repository.CharacterReps.IRepository;
using DA_DataAccess.CharacterClasses;
using DA_DataAccess.Data;
using DA_Models.CharacterModels;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DagoniteEmpire.Exceptions;
using System.Runtime.Remoting;
using System.Diagnostics.Metrics;

namespace DA_Business.Repository.CharacterReps
{
public class WealthRecordRepository : IWealthRecordRepository
{
private readonly IDbContextFactory<ApplicationDbContext> _db;
private readonly IMapper _mapper;

public WealthRecordRepository(IDbContextFactory<ApplicationDbContext> db, IMapper mapper)
{
_db = db;
_mapper = mapper;
}
public async Task<WealthRecordDTO> Create(WealthRecordDTO objDTO)
{
try
{
using var contex = await _db.CreateDbContextAsync();
var obj = _mapper.Map<WealthRecordDTO, WealthRecord>(objDTO);


var addedObj = await contex.WealthRecords.AddAsync(obj);
await contex.SaveChangesAsync();

return _mapper.Map<WealthRecord, WealthRecordDTO>(addedObj.Entity);
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in WealthRecords Repository Create: " + ex.Message);
}
}

public async Task<int> Delete(int id)
{
try
{
using var contex = await _db.CreateDbContextAsync();
var obj = await contex.WealthRecords.FirstOrDefaultAsync(u => u.Id == id);
if (obj is not null)
{
contex.WealthRecords.Remove(obj);
await contex.SaveChangesAsync();
}
return 0;
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in WealthRecords Repository Delete: " + ex.Message);
}
}

public async Task<IEnumerable<WealthRecordDTO>> GetAll(int? charId = null)
{
using var contex = await _db.CreateDbContextAsync();
if(contex.WealthRecords.Any() == false)
return Enumerable.Empty<WealthRecordDTO>();
if (charId == null || charId < 1)
return _mapper.Map<IEnumerable<WealthRecord>, IEnumerable<WealthRecordDTO>>(contex.WealthRecords);
return _mapper.Map<IEnumerable<WealthRecord>, IEnumerable<WealthRecordDTO>>(contex.WealthRecords.Where(u => u.CharacterId == charId));
}


public async Task<WealthRecordDTO> GetById(int id)
{
using var contex = await _db.CreateDbContextAsync();
if (contex.WealthRecords.Any() == false)
return new WealthRecordDTO();
var obj = await contex.WealthRecords.FirstOrDefaultAsync(u => u.Id == id);
if (obj != null)
{
return _mapper.Map<WealthRecord, WealthRecordDTO>(obj);
}
return new WealthRecordDTO();
}

public async Task<WealthRecordDTO> Update(WealthRecordDTO objDTO)
{
try
{
using var contex = await _db.CreateDbContextAsync();
var obj = await contex.WealthRecords.FirstOrDefaultAsync(u => u.Id == objDTO.Id);
if (obj != null)
{
// Update parent
contex.Entry(obj).CurrentValues.SetValues(objDTO);
contex.WealthRecords.Update(obj);
await contex.SaveChangesAsync();
return _mapper.Map<WealthRecord, WealthRecordDTO>(obj);
}
else
{
obj = _mapper.Map<WealthRecordDTO, WealthRecord>(objDTO);
var addedObj = await contex.WealthRecords.AddAsync(obj);
await contex.SaveChangesAsync();
}

return _mapper.Map<WealthRecord, WealthRecordDTO>(obj);

}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in WealthRecords Repository Update: " + ex.Message);
}
}
}
}
2 changes: 1 addition & 1 deletion DA_Business/Repository/CharacterReps/WoundRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task<WoundDTO> Update(WoundDTO objDTO)
var addedObj = await contex.Wounds.AddAsync(obj);
await contex.SaveChangesAsync();
}
return objDTO;
return _mapper.Map<Wound, WoundDTO>(obj);
}
catch (Exception ex)
{
Expand Down
12 changes: 12 additions & 0 deletions DA_Business/Repository/ChatRepos/CampaignRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public async Task<CampaignDTO> Create(CampaignDTO objDTO)

}

public async Task<bool> CheckIfCampaignBelongToUser(string userName, int campaignId)
{
using var contex = await _db.CreateDbContextAsync();
var obj = await contex.Campaigns.Include(c=>c.Characters).FirstOrDefaultAsync(i=>i.Id == campaignId);

if (obj is null) return false;

var charac = obj.Characters.FirstOrDefault(c => c.UserName == userName);

return charac is not null;
}

public async Task<int> Delete(int id)
{
try
Expand Down
12 changes: 12 additions & 0 deletions DA_Business/Repository/ChatRepos/ChapterRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ public async Task<ChapterDTO> Create(ChapterDTO objDTO)

}

public async Task<bool> CheckIfChapterBelongToUser(string userName, int chapterId)
{
using var contex = await _db.CreateDbContextAsync();
var obj = await contex.Chapters.Include(c => c.Characters).FirstOrDefaultAsync(i => i.Id == chapterId);

if (obj is null) return false;

var charac = obj.Characters.FirstOrDefault(c => c.UserName == userName);

return charac is not null;
}

public async Task<int> Delete(int id)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public interface ICampaignRepository
Task<CampaignDTO> GetById(int id);

Task<CampaignDTO> Update(CampaignDTO objDTO);
Task<bool> CheckIfCampaignBelongToUser(string userName, int campaignId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public interface IChapterRepository
Task<ChapterDTO> GetById(int id);

Task<ChapterDTO> Update(ChapterDTO objDTO);
Task<bool> CheckIfChapterBelongToUser(string userName, int chapterId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public interface IPostRepository

Task<IEnumerable<PostDTO>> GetPage(int chapterId, int postPerPage, int pageNum);
Task<int> GetPostCount(int chapterId);
Task<int> GetCharacterPostCount(int characterId, DateTime? From = null, DateTime? To = null);
Task<DateTime> GetCharacterLastPostDate(int characterId);
}
}
60 changes: 60 additions & 0 deletions DA_Business/Repository/ChatRepos/PostRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,66 @@ public async Task<int> GetPostCount(int chapterId)
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}
public async Task<int> GetCharacterPostCount(int characterId)
{
try
{
using var contex = await _db.CreateDbContextAsync();
if (characterId == 0) throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name);

int count = contex.Posts.Where(u => u.CharacterId == characterId).Count();

return count;
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}

public async Task<DateTime> GetCharacterLastPostDate(int characterId)
{
try
{
using var contex = await _db.CreateDbContextAsync();
if (characterId == 0) throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name);

var posts = contex.Posts.Where(u => u.CharacterId == characterId);
if (posts is null || posts.Count() ==0)
return DateTime.MinValue;

DateTime date = posts.Max(r => r.CreatedDate);

return date;
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}

public async Task<int> GetCharacterPostCount(int characterId, DateTime? From = null, DateTime? To = null)
{
try
{
using var contex = await _db.CreateDbContextAsync();
if (characterId == 0) throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name);
int count = 0;
if (From is null && To is null)
count = contex.Posts.Where(u => u.CharacterId == characterId).Count();
else if (From is not null && To is null)
count = contex.Posts.Where(u => u.CharacterId == characterId && u.CreatedDate >= From).Count();
else if(From is not null && To is not null)
{
count = contex.Posts.Where(u => u.CharacterId == characterId && u.CreatedDate >= From && u.CreatedDate <= To).Count();
}
return count;
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}

public async Task<PostDTO> GetById(int id)
{
Expand Down
2 changes: 2 additions & 0 deletions DA_Business/Services/Interfaces/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public interface IUserService
{
public Task<UserInfo?> GetUserInfo();
public Task SetSelectedCharId(int charId);
public Task<bool> IsAuthenticated();
public Task LogOut();
}
}
Loading

0 comments on commit 46c16b9

Please sign in to comment.