Add project files.

This commit is contained in:
2022-10-06 16:53:07 +03:00
parent 45fac5e086
commit 6f3acce7d4
38 changed files with 1051 additions and 0 deletions
@@ -0,0 +1,44 @@
using Ardalis.GuardClauses;
using PracticeCalendar.Domain.Common;
using System.Diagnostics.Contracts;
namespace PracticeCalendar.Domain.Entities
{
/// <summary>
/// Attendee to an event
/// </summary>
public class Attendee: EntityBase
{
public Attendee(string name, string emailAddress)
{
Guard.Against.NullOrEmpty(name);
Guard.Against.NullOrEmpty(emailAddress);
Name = name;
EmailAddress = emailAddress;
}
public int PracticeEventId { get; private set; }
public string Name { get; set; } = string.Empty;
public string EmailAddress { get; set; } = string.Empty;
public bool IsAttending { get; private set; }
/// <summary>
/// Set if the Attendee is attending
/// </summary>
/// <param name="isAttending"></param>
public void SetIsAttending (bool isAttending)
{
this.IsAttending = isAttending;
//TODO - raise event
}
/// <summary>
/// Assign Attendee to the practice event
/// </summary>
/// <param name="practiceEventId"></param>
public void AssignToEvent(int practiceEventId)
{
this.PracticeEventId = practiceEventId;
}
}
}
@@ -0,0 +1,63 @@
using Ardalis.GuardClauses;
using PracticeCalendar.Domain.Common;
using PracticeCalendar.Domain.Common.Interfaces;
using PracticeCalendar.Domain.Events;
using PracticeCalendar.Domain.Exceptions;
namespace PracticeCalendar.Domain.Entities
{
/// <summary>
/// Practice event aggregate
/// </summary>
public class PracticeEvent : EntityBase, IAggregateRoot
{
public PracticeEvent(string title, string description)
{
Guard.Against.NullOrEmpty(title, nameof(title));
Guard.Against.NullOrEmpty(description, nameof(description));
this.Title = title;
this.Description = description;
}
public string Title { get; private set; } = string.Empty;
public string Description{ get; private set; } = string.Empty;
private List<Attendee> attendees = new List<Attendee>();
public IEnumerable<Attendee> Attendees => attendees.AsReadOnly();
public DateTime StartTime { get; private set; }
public DateTime EndTime { get; private set; }
public void AddAttendee(Attendee attendee)
{
Guard.Against.Null(attendee, nameof(attendee));
attendee.AssignToEvent(this.Id);
attendees.Add(attendee);
var attendeeAddedEvent = new AttendeeAddedEvent(this, attendee);
base.RegisterDomainEvent(attendeeAddedEvent);
}
public void UpdateTitleAndDescription(string title, string description)
{
this.Title = title;
this.Description = description;
}
public void AttendeeAcceptEvent(int attendeeId)
{
var attendee = this.Attendees.FirstOrDefault(x => x.Id == attendeeId);
if (attendee == null)
throw new InvalidAttendeeException(attendeeId);
attendee.SetIsAttending(true);
}
public void AttendeeDeclineEvent(int attendeeId)
{
var attendee = this.Attendees.FirstOrDefault(x => x.Id == attendeeId);
if (attendee == null)
throw new InvalidAttendeeException(attendeeId);
attendee.SetIsAttending(false);
}
}
}
@@ -0,0 +1,13 @@
using Ardalis.Specification;
namespace PracticeCalendar.Domain.Entities.Specifications
{
public class PracticeEventByIdWithAttendees : Specification<PracticeEvent>
{
public PracticeEventByIdWithAttendees(int eventId)
{
Query.Where(x=>x.Id == eventId)
.Include(x => x.Attendees);
}
}
}
@@ -0,0 +1,12 @@
using Ardalis.Specification;
namespace PracticeCalendar.Domain.Entities.Specifications
{
public class PracticeEventsWithAttendees : Specification<PracticeEvent>
{
public PracticeEventsWithAttendees()
{
Query.Include(x => x.Attendees);
}
}
}