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/DevBetterWeb.Core/Entities/Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void ExtendCurrentSubscription(DateTime newEndDate)
MemberSubscription s = MemberSubscriptions[i];
if (s.Dates.Contains(DateTime.Today))
{
s.Dates = new DateTimeRange(s.Dates.StartDate, newEndDate);
s.Dates.UpdateEnd(newEndDate);
RegisterDomainEvent(new SubscriptionUpdatedEvent(this, s));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public async Task ExtendMemberSubscription(string email, System.DateTime subscri
if (member is null) throw new MemberWithEmailNotFoundException(email);
member.ExtendCurrentSubscription(subscriptionEndDate);

await _memberRepository.UpdateAsync(member);
await _memberRepository.SaveChangesAsync();

_logger.LogInformation($"Extended {member.UserFullName} subscription to {subscriptionEndDate.ToShortDateString}");
Expand Down
30 changes: 17 additions & 13 deletions src/DevBetterWeb.Core/ValueObjects/DateTimeRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ public DateTimeRange(DateTime startDate, DateTime? endDate)
EndDate = endDate;
}

/// <summary>
/// Returns total number of days in the DateTimeRange.
/// If no EndDate has been specified, will use provided endDateToUseIfMissing instead.
/// </summary>
/// <param name="endDateToUseIfMissing"></param>
/// <returns></returns>
public int ToDays(DateTime endDateToUseIfMissing)
public void UpdateEnd(DateTime endDate)
{
EndDate = endDate;
}

/// <summary>
/// Returns total number of days in the DateTimeRange.
/// If no EndDate has been specified, will use provided endDateToUseIfMissing instead.
/// </summary>
/// <param name="endDateToUseIfMissing"></param>
/// <returns></returns>
public int ToDays(DateTime endDateToUseIfMissing)
{
var end = EndDate ?? endDateToUseIfMissing;

Expand All @@ -48,14 +53,13 @@ public int ToDaysInRangeThroughPeriodEndDate(DateTime periodEndDate)

public bool Contains(DateTime date)
{
if (date >= StartDate && date <= EndDate)
{
return true;
}
return false;
if (date < StartDate) return false;
if (EndDate == null) return true;

return date <= EndDate;
}

protected override IEnumerable<IComparable> GetEqualityComponents()
protected override IEnumerable<IComparable> GetEqualityComponents()
{
yield return StartDate;
yield return EndDate ?? DateTime.MaxValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MemberSubscriptionConfig : IEntityTypeConfiguration<MemberSubscription>
{
public void Configure(EntityTypeBuilder<MemberSubscription> builder)
{
builder.OwnsOne(x => x.Dates)
.ToTable("MemberSubscriptionDates");
}
builder
.ComplexProperty(x => x.Dates);
}
}
Loading
Loading