Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/Application/Members/IMemberService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IMemberService : ITransientService

//Task<int> GetCountAsync(CancellationToken cancellationToken);

//Task<MemberDetailsDto> GetAsync(string userId, CancellationToken cancellationToken);
Task<MemberDetailsDto> GetAsync(string userId, CancellationToken cancellationToken);

/*Task<List<UserRoleDto>> GetRolesAsync(string userId, CancellationToken cancellationToken);
Task<string> AssignRolesAsync(string userId, UserRolesRequest request, CancellationToken cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using EventManagment.Application.Members;
using EventManagment.Domain.Common.Events;
using EventManagment.Domain.Events;

namespace EventManagment.Application.Participants;

public class CreateGuestParticipantRequest : IRequest<Guid>
{
public Guid EventId { get; set; }
public string MemberNumber { get; set; } = default!;
public string FirstName { get; set; } = default!;
public string LastName { get; set; } = default!;
public string Address { get; set; } = default!;
public string Gender { get; set; } = default!;
public string? Email { get; set; }
public string PhoneNumber { get; set; } = default!;
public string? Title { get; set; }

}

public class CreateGuestParticipantRequestHandler : IRequestHandler<CreateGuestParticipantRequest, Guid>
{
private readonly IRepository<Participant> _repository;
private readonly IFileStorageService _file;
private readonly IMemberService _memberService;

public CreateGuestParticipantRequestHandler(IRepository<Participant> repository, IFileStorageService file, IMemberService memberService) =>
(_repository, _file, _memberService) = (repository, file, memberService);

public async Task<Guid> Handle(CreateGuestParticipantRequest request, CancellationToken cancellationToken)
{
// TODO: USE THE MEMBER NUMBER FROM THE REQUEST TO FETCH THE MEMBER INFORMATION FROM THE MEMBER SERVICE
var member = await _memberService.GetAsync(request.MemberNumber, cancellationToken);
// TODO: HANDLE WHEN THE MEMBER NUMBER DOES NOT EXIST FROM THE MEMBER SERVICE
if(member is null)
{
throw new ArgumentNullException($"Invalid Member Number{request.MemberNumber}");
}
// TODO: IMPLEMENT A PRIVATE METHOD IN AN HELPER CLASS TO GENERATE REGISTRATION NUMBER FOR THE PARTICIPANT BASED ON THE EVENT

// TODO: THE PARTICIPANT OBJECT SHOULD BE CREATED FROM THE DOMAIN CONSTRUCTOR IN THE PARTICIPANT CLASS.
var participant = new Participant(request.MemberNumber,request.FirstName, request.LastName, request.Address,
request.PhoneNumber, request.Email, request.Gender, request.Title, ParticipantType.Guest);

// Add Domain Events to be raised after the commit
participant.DomainEvents.Add(EntityCreatedEvent.WithEntity(participant));

await _repository.AddAsync(participant, cancellationToken);

// TODO: GENERATE TAG/TICKET DOWNLOAD LINK TO BE SENT VIA SMS OR EMAIL
// TODO: SEND AN SMS, WHATSAPP OR EMAIL MESSAGE TO THE REGISTERED PARTICIPANT, CALL AN INOTIFICATION SERVICE TO DO THIS. OR USE A BACKGROUND JOB , ADDING THE REGISTRATION TO A QUEUE

return participant.Id;
}
}
27 changes: 26 additions & 1 deletion src/Core/Domain/Events/Participant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -14,7 +15,7 @@ public class Participant : AuditableEntity, IAggregateRoot
public ParticipantType ParticipantType { get; private set; }
public string FirstName { get; private set; } = default!;
public string LastName { get; private set; } = default!;
public string? Tiltle { get; private set; }
public string? Title { get; private set; }
public string? Email { get; private set; }
public string? PhoneNumber { get; private set; }
public int? JamaatId { get; private set; }
Expand All @@ -28,4 +29,28 @@ public class Participant : AuditableEntity, IAggregateRoot
public DateTime? CheckInDate { get; private set; }

// TODO: ADD DOMAIN CONSTRUCTOR TO CREATE PARTICIPANT

public Participant(string memberNum, string firstName, string lastName, string address, string phoneNum, string email, string gender, string title, ParticipantType participant)
{
MemberNumber = memberNum;
RegistrationNumber = GenerateRandomNumber();
FirstName = firstName;
LastName = lastName;
Address = address;
PhoneNumber = phoneNum;
Email = email;
Gender = gender;
Title = title;
ParticipantType = participant;
}

public Participant()
{

}
private static string GenerateRandomNumber()
{
var registrationNum = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 7);
return registrationNum;
}
}
8 changes: 8 additions & 0 deletions src/Host/Controllers/Participants/ParticipantsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ public async Task<ParticipantDto> GetAsync(Guid eventId, Guid participantId)
{
return await Mediator.Send(new GetParticipantByEventIdRequest(eventId, participantId));
}

[HttpPost]
[MustHavePermission(FSHAction.Create, FSHResource.Participants)]
[OpenApiOperation("Register Guest Participant.", "")]
public Task<Guid> CreateAsyn(CreateGuestParticipantRequest request)
{
return Mediator.Send(request);
}
}