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("امکان اجرای عملیات درخواستی وجود ندارد"); } }
public void Handle(UpdateTitleCommand command) { var advertisement = _repository.Load(command.Id); if (advertisement == null) { throw new InvalidOperationException($"آگهی با شناسه {command.Id} یافت نشد."); } advertisement.SetTitle(AdvertisementTitle.FromString(command.Title)); _unitOfWork.Commit(); }
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)); }