This file contains hidden or 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
public class EFConcertRepository | |
{ | |
private readonly EventContext _db; | |
public void Store(Concert aggregateRoot) | |
{ | |
var snapshot = ConcertSnapshot.CreateFrom(aggregateRoot); | |
_db.Concerts.Add(ConcertEntity.FromConcertSnapshot(snapshot)); | |
_db.SaveChanges(); | |
} |
This file contains hidden or 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
public class ConcertSnapshot | |
{ | |
public Identity Id { get; set; } | |
public DateTime ConcertDate { get; set; } | |
public string Organizer { get; set; } | |
public string Description { get; set; } | |
public string TitleGeo { get; set; } | |
public string TitleEng { get; set; } | |
public ConcertSnapshot(Identity id, DateTime date, string organizer, string description, string titleGeo, string titleEng) | |
{ |
This file contains hidden or 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
public class Concert : AggregateRoot, IProvideSnapshot<ConcertSnapshot> | |
{ | |
private EventDescription EventDescription { get; set; } | |
private EventTitleSummary EventTitle { get; set; } | |
private EventOrganizer Organizer { get; set; } | |
public ConcertId Id { get; } | |
public override string Identity => Id.Value; | |
private Concert() : base() { } |
This file contains hidden or 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
public static string ProcessOrderPriceChangeImperative(int id) | |
{ | |
var order = Database.GetOrderById(id); | |
if (order == null) | |
return "order should be active"; | |
order.SetTicketsPricesTo(10); | |
order.Status = OrderStatus.Changed; | |
var sendEmail = SendEmail("your order changed"); | |
if (sendEmail.IsFailure) | |
{ |
This file contains hidden or 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
public class PortionProvider<T> | |
{ | |
private int _totalCount; | |
private int _countPerPortion; | |
public int TotalWholePortionsCount { get; private set; } | |
public int TotalModulePortionsCount { get; private set; } | |
public IEnumerable<T> SourceCollection { get; private set; } | |
public PortionProvider(IEnumerable<T> sourceCollection) : this(sourceCollection, 500) |
This file contains hidden or 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
public class Result | |
{ | |
public bool IsSuccess { get; } | |
public string Error { get; } | |
public bool IsFailure { get { return !IsSuccess; } } | |
protected Result(bool isSuccess, string error) | |
{ | |
if (isSuccess && error != string.Empty) | |
throw new InvalidOperationException(); |
This file contains hidden or 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
public struct Maybe<T> : IEquatable<Maybe<T>> | |
where T : class | |
{ | |
private readonly T _value; | |
public T Value | |
{ | |
get | |
{ | |
if (HasNoValue) | |
throw new InvalidOperationException(); |