public async Task <ActionResult> Create(CreateProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                var productEvent = new CreateProductEvent
                {
                    Name   = model.Name,
                    Amount = model.Amount,
                    Price  = model.Price
                };

                try
                {
                    await _publishEndpoint.Publish <CreateProductEvent>(productEvent);

                    return(RedirectToAction(nameof(Index), new { success = true }));
                }
                catch
                {
                    ModelState.AddModelError(string.Empty, "Error - Create Product Event Publish");
                }
            }

            return(View(model));
        }
示例#2
0
        private void ProcessCommand(CreateProductDraftCommand productDraftCommand)
        {
            var @event = new CreateProductEvent()
            {
                ProductDraft = productDraftCommand.ProductDraft
            };

            this.Persist(@event, e => {
                Sender?.Tell(e);
                logger.Info("发布事件:{0}", Newtonsoft.Json.JsonConvert.SerializeObject(@event));
                Context.System.EventStream.Publish(e);
            });
        }
        public async Task HandleAsync(CreateProductCommand command)
        {
            var Id = this.idGenerator.Next();


            var product = Product.Create(Id, command.Name, command.Category, command.Description, command.ImageFile, command.Price);

            this.repository.Save(product);

            var @event = new CreateProductEvent(id: product.Id, name: product.Name, category: product.Category, summary: product.Summary, description: product.Description, imageFile: product.ImageFile, price: product.Price, status: ProductStatus.Draft);

            await this.eventDispatcher.PublishAsync(@event);
        }
        public ActionResult Create(ProductCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var @event = new CreateProductEvent
                {
                    AddedTags = model.TagsList
                };

                if (!string.Equals(model.Name, null))
                {
                    @event.Name = model.Name;
                }
                if (!string.Equals(model.Description, null))
                {
                    @event.Description = model.Description;
                }
                if (!string.Equals(model.Color, null))
                {
                    @event.Color = model.Color;
                }
                if (!string.Equals(model.Size, null))
                {
                    @event.Size = model.Size;
                }
                if (!decimal.Equals(model.Price, 0))
                {
                    @event.Price = model.Price;
                }

                var result = _service.Create(@event);

                PopulateModelState(result);

                if (ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Product"));
                }
            }

            return(View(model));
        }
示例#5
0
 public EventResult Create(CreateProductEvent @event)
 {
     return(_factory.GetHandler <CreateProductEvent>().Apply(@event, new EventOptions {
         Store = true
     }));
 }
        protected override DataModel.Product GetEntity(CreateProductEvent e)
        {
            var u = (UpdateProductEvent)e;

            return(UnitOfWork.ProductRepository.Find(x => x.Id == u.Id, noTracking: false).FirstOrDefault());
        }