Ejemplo n.º 1
0
        protected override void When(object @event)
        {
            switch (@event)
            {
            case ClassifiedAdCreated e:
                Id             = e.Id;
                OwnerId        = new UserId(e.OwnerId);
                State          = ClassifiedAdState.Inactive;
                Title          = ClassifiedAdTitle.NoTitle();
                Text           = ClassifiedAdText.NoText();
                Price          = Price.NoPrice();
                ApprovedBy     = UserId.NoUser();
                ClassifiedAdId = e.Id;
                break;

            case ClassifiedAdTitleChanged e:
                Title = ClassifiedAdTitle.FromString(e.Title);
                break;

            case ClassifiedAdTextUpdated e:
                Text = ClassifiedAdText.FromString(e.Text);
                break;

            case ClassifiedAdPriceUpdated e:
                Price = Price.Create(e.Price, Currency.Create(e.CurrencyCode, 2));
                break;

            case ClassifiedAdSentToReview e:
                State = ClassifiedAdState.PendingReview;
                break;

            case ClassifiedAdPublished e:
                ApprovedBy = new UserId(e.ApprovedBy);
                State      = ClassifiedAdState.Active;
                break;

            case PictureAdded e:
                var newPicture = new Picture(Apply);
                ApplyToEntity(newPicture, e);
                _pictures.Add(newPicture);
                break;

            case PictureResized e:
                var picture = FindPicture(e.PictureId);
                ApplyToEntity(picture, @event);
                break;
            }
        }