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
using Microsoft.EntityFrameworkCore; | |
using PersistenceIgnorance.Domain.Voting; | |
using PersistenceIgnorance.Domain.Voting.Events; | |
using PersistenceIgnorance.Infrastructure.Persistence.Entities; | |
namespace PersistenceIgnorance.Infrastructure.Persistence.Repositories; | |
public class VotingRepository(VotingDbContext dbContext) | |
{ | |
public async Task<VotingEntity> GetAsync(int id) |
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
using PersistenceIgnorance.Domain.Voting.Events; | |
namespace PersistenceIgnorance.Domain.Voting; | |
public class Voting(List<Voter> voters) | |
{ | |
private readonly List<Voter> _voters = voters; | |
private readonly List<IEvent> _events = []; | |
private bool IsStarted { get; set; } |
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
var products = new List<Product> | |
{ | |
new() | |
{ | |
Title = "MacBook Pro 14 inch", | |
Description = "It's now even more capable, thanks to the new M3 chip." | |
}, | |
new() | |
{ | |
Title = "MacBook Pro 16 inch", |
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 CsvProductsExporterAdapter : IProductsExporter | |
{ | |
private CsvHelper CsvHelper { get; set; } | |
public CsvProductsExporterAdapter(CsvHelper csvHelper) | |
{ | |
CsvHelper = csvHelper; | |
} | |
public string Export(List<Product> data) |
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 CsvHelper | |
{ | |
private char Delimiter { get; set; } | |
public CsvHelper(char delimiter) | |
{ | |
Delimiter = delimiter; | |
} | |
public string GenerateCsv(List<object> rows) |
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 JsonProductsExporter : IProductsExporter | |
{ | |
public string Export(List<Product> products) | |
{ | |
return JsonSerializer.Serialize(products); | |
} | |
} |
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 XmlProductsExporter : IProductsExporter | |
{ | |
public string Export(List<Product> products) | |
{ | |
var xmlSerializer = new XmlSerializer(products.GetType()); | |
using var stringWriter = new StringWriter(); | |
using var xmlWriter = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented }; | |
xmlSerializer.Serialize(xmlWriter, products); |
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 interface IProductsExporter | |
{ | |
string Export(List<Product> products); | |
} |
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
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
modelBuilder | |
.Entity<Shipment>() | |
.Property(e => e.State) | |
.HasConversion( | |
s => s.ToString(), | |
s => s switch { | |
nameof(OrderPlacedState) => new OrderPlacedState(), | |
nameof(InTransitState) => new InTransitState(), |
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
var shipment = new Shipment(Guid.NewGuid(), "RU", "Istanbul") | |
shipment.ToInTransit(); | |
shipment.ToInCustoms(); | |
shipment.ToInCustomsCleared(); | |
shipment.ToOutForDelivery(); | |
shipment.ToNotDelivered(); | |
shipment.ToDelivered(); |
NewerOlder