Skip to content

Commit

Permalink
feat: add exception info to toastr msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
KrystianKempski committed Nov 14, 2024
1 parent c744e3b commit eb91069
Show file tree
Hide file tree
Showing 52 changed files with 655 additions and 712 deletions.
4 changes: 2 additions & 2 deletions DA_Business/Repository/CharacterReps/AttributeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<AttributeDTO> Create(AttributeDTO objDTO)
await contex.SaveChangesAsync();
return _mapper.Map<Attribute, AttributeDTO>(addedObj.Entity);
}
catch (Exception ex) { throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name); }
catch (Exception ex) { throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message); }
}

public async Task<int> Delete(int id)
Expand Down Expand Up @@ -73,7 +73,7 @@ public async Task<IDictionary<string,AttributeDTO>> GetAll(int? charId = null)
}
}
catch (Exception ex) {
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name);
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}

return new Dictionary<string, AttributeDTO>();
Expand Down
3 changes: 2 additions & 1 deletion DA_Business/Repository/CharacterReps/BaseSkillRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using DA_DataAccess.CharacterClasses;
using DA_DataAccess.Data;
using DA_Models.CharacterModels;
using DagoniteEmpire.Exceptions;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -35,7 +36,7 @@ public async Task<BaseSkillDTO> Create(BaseSkillDTO objDTO)
}
catch (Exception ex)
{
;
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
return null;
}
Expand Down
20 changes: 7 additions & 13 deletions DA_Business/Repository/CharacterReps/BonusRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,14 @@ public BonusRepository(IDbContextFactory<ApplicationDbContext> db, IMapper mappe
}
public async Task<BonusDTO> Create(BonusDTO objDTO)
{
try
{
using var contex = await _db.CreateDbContextAsync();
var obj = _mapper.Map<BonusDTO, Bonus>(objDTO);
var addedObj = contex.Bonuses.Add(obj);
await contex.SaveChangesAsync();

using var contex = await _db.CreateDbContextAsync();
var obj = _mapper.Map<BonusDTO, Bonus>(objDTO);
var addedObj = contex.Bonuses.Add(obj);
await contex.SaveChangesAsync();

return _mapper.Map<Bonus, BonusDTO>(addedObj.Entity);

return _mapper.Map<Bonus, BonusDTO>(addedObj.Entity);
}
catch (Exception ex)
{
;
}
return null;
}

public async Task<int> Delete(int id)
Expand Down
6 changes: 3 additions & 3 deletions DA_Business/Repository/CharacterReps/CharacterRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task<CharacterDTO> Create(CharacterDTO objDTO)
return _mapper.Map<Character, CharacterDTO>(addedObj.Entity);
}
catch (Exception ex) {
throw new RepositoryErrorException("Error in"+ System.Reflection.MethodBase.GetCurrentMethod().Name);
throw new RepositoryErrorException("Error in"+ System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}

Expand Down Expand Up @@ -127,7 +127,7 @@ public async Task<int> Delete(int id)
return await contex.SaveChangesAsync();
}
catch (Exception ex) {
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name);
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message );
}
}

Expand Down Expand Up @@ -474,7 +474,7 @@ public async Task<CharacterDTO> Update(CharacterDTO objDTO)
return objDTO;
}
catch (Exception ex) {
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name);
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}

Expand Down
6 changes: 3 additions & 3 deletions DA_Business/Repository/CharacterReps/EquipmentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<EquipmentDTO> Create(EquipmentDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Equipment Repository Create");
throw new RepositoryErrorException("Error in Equipment Repository Create: " + ex.Message); ;
}
}

Expand All @@ -78,7 +78,7 @@ public async Task<int> Delete(int id)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Equipment Repository Delete");
throw new RepositoryErrorException("Error in Equipment Repository Delete: " + ex.Message);
}
}

Expand Down Expand Up @@ -249,7 +249,7 @@ public async Task<EquipmentDTO> Update(EquipmentDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Equipment Repository Update");
throw new RepositoryErrorException("Error in Equipment Repository Update: " + ex.Message);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task<EquipmentSlotDTO> Create(EquipmentSlotDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in EquipmentSlot Repository Create");
throw new RepositoryErrorException("Error in EquipmentSlot Repository Create: " + ex.Message);
}
}

Expand All @@ -65,7 +65,7 @@ public async Task<int> Delete(int id)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in EquipmentSlot Repository Delete");
throw new RepositoryErrorException("Error in EquipmentSlot Repository Delete: " + ex.Message);
}
}

Expand Down Expand Up @@ -275,7 +275,7 @@ public async Task<EquipmentSlotDTO> Update(EquipmentSlotDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in EquipmentSlot Repository Update");
throw new RepositoryErrorException("Error in EquipmentSlot Repository Update: " + ex.Message);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions DA_Business/Repository/CharacterReps/MobRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<MobDTO> Create(MobDTO objDTO)
return _mapper.Map<Mob, MobDTO>(addedObj.Entity);
}
catch (Exception ex) {
throw new RepositoryErrorException("Error in"+ System.Reflection.MethodBase.GetCurrentMethod().Name);
throw new RepositoryErrorException("Error in"+ System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}

Expand All @@ -56,7 +56,7 @@ public async Task<int> Delete(int id)
return await contex.SaveChangesAsync();
}
catch (Exception ex) {
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name);
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public async Task<MobDTO> Update(MobDTO objDTO)
}
}
catch (Exception ex) {
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name);
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions DA_Business/Repository/CharacterReps/ProfessionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<ProfessionDTO> Create(ProfessionDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Profession Repository Create");
throw new RepositoryErrorException("Error in Profession Repository Create: " + ex.Message);
}

}
Expand All @@ -63,7 +63,7 @@ public async Task<int> Delete(int id)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Profession Repository Delete");
throw new RepositoryErrorException("Error in Profession Repository Delete: " + ex.Message);
}
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task<ProfessionDTO> Update(ProfessionDTO objDTO)
{
var updateProfession = _mapper.Map<ProfessionDTO, Profession>(objDTO);
// Update parent
contex.Entry(obj).CurrentValues.SetValues(updateProfession);
contex.Entry(obj).CurrentValues.SetValues(updateProfession);

// Delete spell circles
if (obj.SpellCircles is not null)
Expand All @@ -113,7 +113,7 @@ public async Task<ProfessionDTO> Update(ProfessionDTO objDTO)
//delete those who is not in updated profession
if (!updateProfession.SpellCircles.Any(c => c.Id == existingChild.Id))
{
if(existingChild.SpellSlots is not null)
if (existingChild.SpellSlots is not null)
{
foreach (var existingSlot in existingChild.SpellSlots)
{
Expand All @@ -135,7 +135,7 @@ public async Task<ProfessionDTO> Update(ProfessionDTO objDTO)
SpellCircle? existingCircle;
if (!obj.SpellCircles.IsNullOrEmpty())
{
existingCircle = obj.SpellCircles. FirstOrDefault(c => c.Id == newCircle.Id && c.Id != default(int));
existingCircle = obj.SpellCircles.FirstOrDefault(c => c.Id == newCircle.Id && c.Id != default(int));
}
else
{
Expand All @@ -145,7 +145,7 @@ public async Task<ProfessionDTO> Update(ProfessionDTO objDTO)

if (existingCircle != null)
{

// Delete spell Slot
if (obj.SpellCircles is not null)
{
Expand Down Expand Up @@ -201,7 +201,7 @@ public async Task<ProfessionDTO> Update(ProfessionDTO objDTO)
if (existingSlot != null)
{
// Update slot
contex.Entry(existingSlot).CurrentValues.SetValues(spellSlot);
contex.Entry(existingSlot).CurrentValues.SetValues(spellSlot);
// update spell

Spell? existingSpell = contex.Spells.Include(t => t.SpellSlots).FirstOrDefault(c => c.Id == spellSlot.SpellId && c.Id != default(int));
Expand All @@ -210,7 +210,7 @@ public async Task<ProfessionDTO> Update(ProfessionDTO objDTO)
contex.Entry(existingSpell).CurrentValues.SetValues(spellSlot.Spell);
else
{
if(spellSlot.Spell is not null)
if (spellSlot.Spell is not null)
{
spellSlot.Spell.SpellSlots = new HashSet<SpellSlot>();
spellSlot.Spell.SpellSlots.Add(existingSlot);
Expand All @@ -226,7 +226,7 @@ public async Task<ProfessionDTO> Update(ProfessionDTO objDTO)
}
else
{
if(newCircle.SpellSlots is not null)
if (newCircle.SpellSlots is not null)
{
// Remove unnessesary existing spells
foreach (var slot in newCircle.SpellSlots)
Expand Down Expand Up @@ -255,7 +255,7 @@ public async Task<ProfessionDTO> Update(ProfessionDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Profession Repository Update");
throw new RepositoryErrorException("Error in Profession Repository Update: " + ex.Message);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions DA_Business/Repository/CharacterReps/RaceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<RaceDTO> Create(RaceDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Race Repository Create");
throw new RepositoryErrorException("Error in Race Repository Create: " + ex.Message); ;
}
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public async Task<int> Delete(int id)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Race Repository Delete");
throw new RepositoryErrorException("Error in Race Repository Delete: " + ex.Message); ;
}
}

Expand Down Expand Up @@ -247,7 +247,7 @@ public async Task<RaceDTO> Update(RaceDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Race Repository Update");
throw new RepositoryErrorException("Error in Race Repository Update: " + ex.Message);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task<IDictionary<string, SpecialSkillDTO>> GetAll(int? charId = nul
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name);
throw new RepositoryErrorException("Error in" + System.Reflection.MethodBase.GetCurrentMethod().Name +": " + ex.Message);
}

return new Dictionary<string, SpecialSkillDTO>();
Expand Down
6 changes: 3 additions & 3 deletions DA_Business/Repository/CharacterReps/SpellCircleRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<SpellCircleDTO> Create(SpellCircleDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in SpellCircle Repository Create");
throw new RepositoryErrorException("Error in SpellCircle Repository Create: " + ex.Message);
}
}

Expand All @@ -58,7 +58,7 @@ public async Task<int> Delete(int id)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in SpellCircles Repository Delete");
throw new RepositoryErrorException("Error in SpellCircles Repository Delete: " + ex.Message); ;
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ public async Task<SpellCircleDTO> Update(SpellCircleDTO objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in SpellCircle Repository Update");
throw new RepositoryErrorException("Error in SpellCircle Repository Update: " + ex.Message);
}
}

Expand Down
6 changes: 3 additions & 3 deletions DA_Business/Repository/CharacterReps/SpellRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<Spell> Create(Spell objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Spell Repository Create");
throw new RepositoryErrorException("Error in Spell Repository Create: " + ex.Message); ;
}
}

Expand All @@ -53,7 +53,7 @@ public async Task<int> Delete(int id)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Spell Repository Delete"); ;
throw new RepositoryErrorException("Error in Spell Repository Delete: " + ex.Message); ;
}
}

Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task<Spell> Update(Spell objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in Spell Repository Update");
throw new RepositoryErrorException("Error in Spell Repository Update: " + ex.Message); ;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions DA_Business/Repository/CharacterReps/SpellSlotRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<SpellSlot> Create(SpellSlot objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in SpellSlot Repository Create");
throw new RepositoryErrorException("Error in SpellSlot Repository Create: " + ex.Message);
}
}

Expand All @@ -53,7 +53,7 @@ public async Task<int> Delete(int id)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in SpellSlot Repository Delete"); ;
throw new RepositoryErrorException("Error in SpellSlot Repository Delete: " + ex.Message); ;
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task<SpellSlot> Update(SpellSlot objDTO)
}
catch (Exception ex)
{
throw new RepositoryErrorException("Error in SpellSlot Repository Update");
throw new RepositoryErrorException("Error in SpellSlot Repository Update: " + ex.Message); ;
}
}
}
Expand Down
Loading

0 comments on commit eb91069

Please sign in to comment.