-
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 pull request #16 from SoftTeam-Emergentes/feat/art-event-manage…
…ment2 feat: add delete features
- Loading branch information
Showing
13 changed files
with
166 additions
and
5 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...TARS/AtEventManagement/Application/Participant/Command/DeleteParticipantCommandHandler.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,43 @@ | ||
using MediatR; | ||
using PERUSTARS.AtEventManagement.Domain.Model.Aggregates; | ||
using PERUSTARS.AtEventManagement.Domain.Model.Commads; | ||
using PERUSTARS.AtEventManagement.Domain.Model.Repositories; | ||
using PERUSTARS.Shared.Domain.Repositories; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace PERUSTARS.AtEventManagement.Application.Participant.Command | ||
{ | ||
public class DeleteParticipantCommandHandler:IRequestHandler<DeleteParticipantCommand,string> | ||
{ | ||
private readonly IParticipantRepository _participantRepository; | ||
private readonly IUnitOfWork _unitOfWork; | ||
public DeleteParticipantCommandHandler(IParticipantRepository participantRepository, IUnitOfWork unitOfWork) | ||
{ | ||
_participantRepository = participantRepository; | ||
_unitOfWork = unitOfWork; | ||
} | ||
|
||
public async Task<string> Handle(DeleteParticipantCommand request, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
PERUSTARS.AtEventManagement.Domain.Model.Aggregates.Participant p = _participantRepository.FindByIdAsync(request.id).Result; | ||
if (p != null) | ||
{ | ||
_participantRepository.Remove(p); | ||
await _unitOfWork.CompleteAsync(); | ||
return "Participant deleted"; | ||
} | ||
else { | ||
return "Participant with the given Id doesn't exist"; | ||
} | ||
} | ||
catch (Exception e) { | ||
throw new ApplicationException($"An error occurred while deleting the participant: {e.Message}"); | ||
} | ||
|
||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...RS/AtEventManagement/Application/Participant/Command/Service/ParticipantCommandService.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 MediatR; | ||
using PERUSTARS.AtEventManagement.Domain.Model.Commads; | ||
using PERUSTARS.AtEventManagement.Domain.Services.Participant; | ||
using System.Threading.Tasks; | ||
|
||
namespace PERUSTARS.AtEventManagement.Application.Participant.Command.Service | ||
{ | ||
public class ParticipantCommandService:IParticipantCommandService | ||
{ | ||
private readonly IMediator _mediator; | ||
public ParticipantCommandService(IMediator mediator) | ||
{ | ||
_mediator = mediator; | ||
} | ||
|
||
public async Task<string> deleteParticipant(DeleteParticipantCommand deleteParticipantCommand) | ||
{ | ||
return await _mediator.Send(deleteParticipantCommand); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ERUSTARS/AtEventManagement/Application/artevents/commands/DeleteArtEventCommandHandler.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,40 @@ | ||
using MediatR; | ||
using PERUSTARS.AtEventManagement.Domain.Model.Aggregates; | ||
using PERUSTARS.AtEventManagement.Domain.Model.Commads; | ||
using PERUSTARS.AtEventManagement.Domain.Model.Repositories; | ||
using PERUSTARS.Shared.Domain.Repositories; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace PERUSTARS.AtEventManagement.Application.artevents.commands | ||
{ | ||
public class DeleteArtEventCommandHandler : IRequestHandler<DeleteArtEventCommand, string> | ||
{ | ||
private readonly IArtEventRepository _artEventRepository; | ||
private readonly IUnitOfWork _unitOfWork; | ||
public DeleteArtEventCommandHandler(IArtEventRepository artEventRepository, IUnitOfWork unitOfWork) | ||
{ | ||
_artEventRepository = artEventRepository; | ||
_unitOfWork = unitOfWork; | ||
} | ||
|
||
public async Task<string> Handle(DeleteArtEventCommand request, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
ArtEvent artEvent= _artEventRepository.FindByIdAsync(request.id).Result; | ||
if (artEvent != null) { | ||
_artEventRepository.Remove(artEvent); | ||
await _unitOfWork.CompleteAsync(); | ||
|
||
} | ||
} | ||
catch(Exception e) { | ||
throw new ApplicationException($"An error occurred while deleting the art event: {e.Message}"); | ||
|
||
} | ||
return "Art event deleted"; | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
PERUSTARS/PERUSTARS/AtEventManagement/Domain/Model/Commads/DeleteArtEventCommand.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,9 @@ | ||
using MediatR; | ||
|
||
namespace PERUSTARS.AtEventManagement.Domain.Model.Commads | ||
{ | ||
public class DeleteArtEventCommand:IRequest<string> | ||
{ | ||
public int id { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
PERUSTARS/PERUSTARS/AtEventManagement/Domain/Model/Commads/DeleteParticipantCommand.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,9 @@ | ||
using MediatR; | ||
|
||
namespace PERUSTARS.AtEventManagement.Domain.Model.Commads | ||
{ | ||
public class DeleteParticipantCommand:IRequest<string> | ||
{ | ||
public int id { get; set; } | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
...ARS/PERUSTARS/AtEventManagement/Domain/Services/Participant/IParticipantCommandService.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,10 @@ | ||
using PERUSTARS.AtEventManagement.Domain.Model.Commads; | ||
using System.Threading.Tasks; | ||
|
||
namespace PERUSTARS.AtEventManagement.Domain.Services.Participant | ||
{ | ||
public interface IParticipantCommandService | ||
{ | ||
Task<string> deleteParticipant(DeleteParticipantCommand deleteParticipantCommand); | ||
} | ||
} |
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