Пример #1
0
        protected override void SetStateByEvent(IEvent @event)
        {
            switch (@event)
            {
            case AdvertisementCreated e:
                Id      = e.Id;
                OwnerId = UserId.FromGuid(e.OwnerId);
                State   = AdvertisementState.Inactive;
                break;

            case AdvertisementPriceUpdated e:
                Price = new Price(Rial.FromLong(e.Price));
                break;

            case AdvertisementSentForReview e:
                State = AdvertisementState.ReviewPending;
                break;

            case AdvertisementDescriptionUpdated e:
                Description = AdvertisementDescription.FromString(e.Description);
                break;

            case AdvertisementTitleUpdated e:
                Title = AdvertisementTitle.FromString(e.Title);
                break;

            default:
                throw new InvalidOperationException("امکان اجرای عملیات درخواستی وجود ندارد");
            }
        }
Пример #2
0
 public void UpdateDescription(AdvertisementDescription description)
 {
     HandleEvent(new AdvertisementDescriptionUpdated()
     {
         Id          = Id,
         Description = description.Value
     });
 }
Пример #3
0
        public void Handle(UpdateDescriptionCommand command)
        {
            var advertisement = _repository.Load(command.Id);

            if (advertisement == null)
            {
                throw new InvalidOperationException($"آگهی با شناسه {command.Id} یافت نشد.");
            }
            advertisement.UpdateDescription(AdvertisementDescription.FromString(command.Description));
            _unitOfWork.Commit();
        }
Пример #4
0
        public void Configure(EntityTypeBuilder <Advertisement> builder)
        {
            builder.Property(c => c.Price).HasConversion(c => c.Value.Value,
                                                         d => Price.FromLong(d));

            builder.Property(c => c.OwnerId).HasConversion(c => c.Value.ToString(),
                                                           d => UserId.FromString(d));

            builder.Property(c => c.ApprovedBy).HasConversion(c => c.Value.ToString(),
                                                              d => UserId.FromString(d));

            builder.Property(c => c.Description).HasConversion(c => c.Value,
                                                               d => AdvertisementDescription.FromString(d));

            builder.Property(c => c.Title).HasConversion(c => c.Value,
                                                         d => AdvertisementTitle.FromString(d));
        }