Exemplo n.º 1
0
 public Task Handle(V1.Create command)
 => Handle(
     command.ClassifiedAdId,
     state => ClassifiedAd.Create(
         ClassifiedAdId.FromGuid(command.ClassifiedAdId),
         UserId.FromGuid(command.SellerId)
         )
     );
        async Task Execute(ClassifiedAdId id, Func <ClassifiedAd, Task> update)
        {
            var ad = await _store.Load <ClassifiedAd>(id);

            await update(ad);

            await _store.Save(ad);
        }
 public Task Handle(V1.CreateOrder command)
 => Handle(
     command.OrderId,
     state => Order.Create(
         OrderId.FromGuid(command.OrderId),
         ClassifiedAdId.FromGuid(command.ClassifiedAdId),
         UserId.FromGuid(command.CustomerId)
         )
     );
Exemplo n.º 4
0
        public ClassifiedAdsCommandService(
            IAggregateStore store,
            ICurrencyLookup currencyLookup,
            UploadFile uploader) : base(store)
        {
            CreateWhen <V1.Create>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (cmd, id) => ClassifiedAd.Create(
                    ClassifiedAdId.FromGuid(id),
                    UserId.FromGuid(cmd.OwnerId)
                    )
                );

            UpdateWhen <V1.ChangeTitle>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd)
                => ad.SetTitle(ClassifiedAdTitle.FromString(cmd.Title))
                );

            UpdateWhen <V1.UpdateText>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd)
                => ad.UpdateText(ClassifiedAdText.FromString(cmd.Text))
                );

            UpdateWhen <V1.UpdatePrice>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd) => ad.UpdatePrice(
                    Price.FromDecimal(
                        cmd.Price, cmd.Currency ?? "EUR", currencyLookup
                        )
                    )
                );

            UpdateWhen <V1.RequestToPublish>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd) => ad.RequestToPublish()
                );

            UpdateWhen <V1.Publish>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd) => ad.Publish(UserId.FromGuid(cmd.ApprovedBy))
                );

            UpdateWhen <V1.Delete>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd) => ad.Delete()
                );

            UpdateWhen <V1.UploadImage>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                async(ad, cmd) => ad.AddPicture(
                    await uploader(cmd.Image), new PictureSize(2000, 2000)
                    )
                );
        }
Exemplo n.º 5
0
 public static OrderState.Result Create(
     OrderId orderId,
     ClassifiedAdId classifiedAdId,
     UserId customerId
     )
 => new OrderState().Apply(
     new V1.OrderCreated
 {
     OrderId        = orderId,
     ClassifiedAdId = classifiedAdId,
     CustomerId     = customerId
 }
     );
Exemplo n.º 6
0
 public Task <Domain.ClassifiedAd.ClassifiedAd> Load(ClassifiedAdId id)
 {
     return(_dbContext.ClassifiedAds.FindAsync(id.Value));
 }
Exemplo n.º 7
0
 public async Task <bool> Exists(ClassifiedAdId id)
 {
     return(await _dbContext.ClassifiedAds.FindAsync(id.Value) != null);
 }
Exemplo n.º 8
0
        public void CreateClassifiedAd(ClassifiedAdId id, UserId ownerId)
        {
            var classifiedAd = new ClassifiedAd(id, ownerId);

            // store the entity somehow
        }
Exemplo n.º 9
0
 public ClassifiedAd(ClassifiedAdId id, UserId ownerId)
 {
     Id       = id;
     _ownerId = ownerId;
 }
 Task Execute(ClassifiedAdId id, Action <ClassifiedAd> update)
 => Execute(id, ad => { update(ad); return(Task.CompletedTask); });
 private static string EntityId(ClassifiedAdId id) => $"ClassifiedAd/{id.ToString()}";
 public Task <ClassifiedAd> Load(ClassifiedAdId id) => _session.LoadAsync <ClassifiedAd>(EntityId(id));
 public Task <bool> Exists(ClassifiedAdId id) => _session.Advanced.ExistsAsync(EntityId(id));
Exemplo n.º 14
0
 public void Register(ClassifiedAdId id, OwnerId owner)
 {
 }