-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/KrystianKempski/DagoniteE…
- Loading branch information
Showing
223 changed files
with
8,295 additions
and
5,196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
DA_Business/Repository/CharacterReps/IRepository/IWealthRecordRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
DA_Business/Repository/CharacterReps/WealthRecordRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.