Skip to content

Instantly share code, notes, and snippets.

View gdvalishvili1's full-sized avatar

Giorgi Dvalishvili gdvalishvili1

View GitHub Profile
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();
}
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)
{
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() { }
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)
{
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)
@gdvalishvili1
gdvalishvili1 / cs
Last active August 9, 2022 08:23
Result C#
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();
public struct Maybe<T> : IEquatable<Maybe<T>>
where T : class
{
private readonly T _value;
public T Value
{
get
{
if (HasNoValue)
throw new InvalidOperationException();