I want you to act as a Senior C# software developer. with lots of experience in C# Domain Driven Design, using C# Clean Architecture. I will provide some with the Invoice Entity, then I will tell you to explain the code, you can see that class uses Clean Architecture C# design patterns under domain-driven design, can you explain the C# design patterns used considering that in another part of the application (i will not provide you with those extra classes but just know they exist and are there to be used by the entity class), those classes are the Invoice specification class, get One Invoice by Id with related children entities specification class, the fluent epi configuration class for the Invoice, the DTO for the Invoice, the auto mapper profile for the profile, the endpoints for the invoice update endpoint class, the create invoice as well as the get List of invoices and the get one complete invoice with related parent entities and children entities GetOneWithChildrenEntities endpoint, I also have the blazor web assembly Invoice UI and the code to communicate with the endpoint.
so as you can see I have a complete app, please explain the C# design patterns used, here is the entity invoice class
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Ardalis.GuardClauses;
using dddSimpleInvoice.Core.Events;
using dddSimpleInvoiceL.SharedKernel;
using dddSimpleInvoiceL.SharedKernel.Interfaces;
namespace dddSimpleInvoice.Core.Entities
{
public class Invoice : BaseEntityEv, IAggregateRoot
{
[Key]
public Guid InvoiceId { get; private set; }
public string DeliveryAddressId { get; private set; }
public string InvoiceCode { get; private set; }
public DateTime InvoiceDate { get; private set; }
public string? CustomerPurchaseOrderNumber { get; private set; }
public bool IsCreditNote { get; private set; }
public string? CreditNoteReason { get; private set; }
public string? Comments { get; private set; }
public string? DeliveryInstructions { get; private set; }
public string? InternalComments { get; private set; }
public Guid LastEditedBy { get; private set; }
public DateTime LastEditedWhen { get; private set; }
public DateTime CreateDate { get; private set; }
public DateTime? DueDate { get; private set; }
public DateTime? ShipDate { get; private set; }
public DateTime? DateInvoiced { get; private set; }
public int InvoiceStatus { get; private set; }
public decimal? TotalSale { get; private set; }
public decimal? TotalSaleTax { get; private set; }
public void SetDeliveryAddressId(string deliveryAddressId)
{
DeliveryAddressId = deliveryAddressId;
}
public void SetInvoiceCode(string invoiceCode)
{
InvoiceCode = Guard.Against.NullOrEmpty(invoiceCode, nameof(invoiceCode));
}
public void UpdateCustomerForInvoice(Guid newCustomerId)
{
Guard.Against.NullOrEmpty(newCustomerId, nameof(newCustomerId));
if (newCustomerId == CustomerId)
{
return;
}
CustomerId = newCustomerId;
}
public void SetCustomerPurchaseOrderNumber(string customerPurchaseOrderNumber)
{
CustomerPurchaseOrderNumber = customerPurchaseOrderNumber;
}
public void SetCreditNoteReason(string creditNoteReason)
{
CreditNoteReason = creditNoteReason;
}
public void SetComments(string comments)
{
Comments = comments;
}
public void SetDeliveryInstructions(string deliveryInstructions)
{
DeliveryInstructions = deliveryInstructions;
}
public void SetInternalComments(string internalComments)
{
InternalComments = internalComments;
}
public virtual Customer Customer { get; private set; }
public Guid CustomerId { get; private set; }
private readonly List _invoiceDetails = new();
public IEnumerable InvoiceDetails => _invoiceDetails.AsReadOnly();
public void AddNewInvoiceDetail(InvoiceDetail invoiceDetail)
{
Guard.Against.Null(invoiceDetail, nameof(invoiceDetail));
Guard.Against.NullOrEmpty(invoiceDetail.InvoiceDetailId, nameof(invoiceDetail.InvoiceDetailId));
Guard.Against.DuplicateInvoiceDetail(_invoiceDetails, invoiceDetail, nameof(invoiceDetail));
_invoiceDetails.Add(invoiceDetail);
}
public void DeleteInvoiceDetail(InvoiceDetail invoiceDetail)
{
Guard.Against.Null(invoiceDetail, nameof(invoiceDetail));
var invoiceDetailToDelete = _invoiceDetails
.Where(id => id.InvoiceDetailId == invoiceDetail.InvoiceDetailId)
.FirstOrDefault();
if (invoiceDetailToDelete != null)
{
_invoiceDetails.Remove(invoiceDetailToDelete);
}
}
private Invoice() {} // EF required
[SetsRequiredMembers]
public Invoice(Guid invoiceId, Guid customerId, string? deliveryAddressId, string invoiceCode, DateTime invoiceDate, string? customerPurchaseOrderNumber, bool isCreditNote, string? creditNoteReason, string? comments, string? deliveryInstructions, string? internalComments, System.Guid lastEditedBy, DateTime lastEditedWhen, DateTime createDate, DateTime? dueDate, DateTime? shipDate, DateTime? dateInvoiced, int invoiceStatus, decimal? totalSale, decimal? totalSaleTax)
{
InvoiceId = Guard.Against.NullOrEmpty(invoiceId, nameof(invoiceId));
CustomerId = Guard.Against.NullOrEmpty(customerId, nameof(customerId));
DeliveryAddressId = deliveryAddressId;
InvoiceCode = Guard.Against.NullOrWhiteSpace(invoiceCode, nameof(invoiceCode));
InvoiceDate = Guard.Against.OutOfSQLDateRange(invoiceDate, nameof(invoiceDate));
CustomerPurchaseOrderNumber = customerPurchaseOrderNumber;
IsCreditNote = Guard.Against.Null(isCreditNote, nameof(isCreditNote));
CreditNoteReason = creditNoteReason;
Comments = comments;
DeliveryInstructions = deliveryInstructions;
InternalComments = internalComments;
LastEditedBy = Guard.Against.NullOrEmpty(lastEditedBy, nameof(lastEditedBy));
LastEditedWhen = Guard.Against.OutOfSQLDateRange(lastEditedWhen, nameof(lastEditedWhen));
CreateDate = Guard.Against.OutOfSQLDateRange(createDate, nameof(createDate));
DueDate = dueDate;
ShipDate = shipDate;
DateInvoiced = dateInvoiced;
InvoiceStatus = Guard.Against.NegativeOrZero(invoiceStatus, nameof(invoiceStatus));
TotalSale = totalSale;
TotalSaleTax = totalSaleTax;
}
}
}