public override void Execute(ICommand cmd, IEventSourceRepository repository) { var c = cmd.MapToCommand <MakeNewOrderCommand>(); var customer = repository.GetById <Customer>(c.CustomerId); Self.CreateNewOrder(customer.AggregateRootId); foreach (Guid item in c.Quantities.Keys) { var product = repository.GetById <Product>(item); var quantity = c.Quantities[item]; var totalAmount = product.GetTotalAmount(quantity); if (customer.HasSufficientAmountToPurchase(totalAmount) && product.HasAvailableStockToPurchaseByQuantity(quantity)) { Self.AddOrderItem(quantity, totalAmount, customer.name, product.productName, product.AggregateRootId, customer.AggregateRootId); customer.DecreaseCashBalance(totalAmount); product.DecreaseStockBalance(quantity); } else { throw new Exception("Insufficient amount to purchase"); } } }
public override void Execute(ICommand cmd, IEventSourceRepository repository) { var c = cmd.MapToCommand <ChangeProductQuantityInOrderItemCommand>(); //Arrange var order = repository.GetById <Order>(c.AggregateRootId); var product = repository.GetById <Product>(c.ProductId); var customer = repository.GetById <Customer>(c.CustomerId); var quantity = order.GetQuantityInSelectedOrderItem(c.RowId); var totalAmount = order.GetTotalAmountInSelectedOrderItem(c.RowId); var newtotalAmount = product.GetTotalAmount(c.Quantity); //Act customer.IncreaseCashBalance(totalAmount); product.IncreaseStockBalance(quantity); order.ChangeProductQuantityInOrderItem(c.RowId, c.Quantity, newtotalAmount); customer.DecreaseCashBalance(newtotalAmount); product.DecreaseStockBalance(c.Quantity); }
protected async Task PublishEventStoreAsync <TEvent>(string eventName, IEventSourceRepository eventSourceRepository, TEvent @event) where TEvent : INotification, IAggregateModel { try { // convert event model into json var movieEventJson = JsonConvert.SerializeObject(@event); // Generate Event Source Model EventSourceModel eventSourceModel = new() { AggregateId = Convert.ToString(@event.AggregateId), EventName = eventName, PayLoad = movieEventJson }; // Push Event Source await eventSourceRepository ?.AddEventStoreAsync(eventSourceModel); } catch { throw; } }
public WorkshopPlanningController( IEventSourceRepository <WorkshopPlanning> planningRepo, IPlanMaintenanceJobCommandHandler planMaintenanceJobCommandHandler, IFinishMaintenanceJobCommandHandler finishMaintenanceJobCommand) { _planningRepo = planningRepo; _planMaintenanceJobCommandHandler = planMaintenanceJobCommandHandler; _finishMaintenanceJobCommandHandler = finishMaintenanceJobCommand; }
public OrderCommandHandler(IOrderRepository orderRepository, IEmployeesRepository employeeRepository, ICustomersRepository customerRepository, IEventSourceRepository eventStoreRepository) { _orderRepository = orderRepository; _employeeRepository = employeeRepository; _customerRepository = customerRepository; _eventStoreRepository = eventStoreRepository; }
public AuctionRepository(IEventSourceRepository <Auction, Guid> repository) { this.repository = repository; }
public MovieRemovedEventHandler(IEventSourceRepository eventSourceRepository) { this.eventSourceRepository = eventSourceRepository; }
public PetitionCommandHandler(IEventSourceRepository <PetitionAggregate> repository) { _repository = repository; }
public MovieTitleChangedEventHandler(IEventSourceRepository eventSourceRepository) { this.eventSourceRepository = eventSourceRepository; }
public ProductsController(IUnitOfWork uow,IEventSourceRepository repo) { this.UnitOfWork = uow; this.repo = repo; }
public EventRepository(IEventSourceRepository eventSourceRepository, IHttpContextAccessor httpContextAccessor) { _eventSourceRepository = eventSourceRepository; _httpContextAccessor = httpContextAccessor; }
public EventSourceManager(IEventSourceRepository eventSourceRepository) { this.repository = eventSourceRepository; }
public EmployeesCommandHandler(IEmployeesRepository employeesRepository, IEventSourceRepository eventStoreRepository) { _employeesRepository = employeesRepository; _eventStoreRepository = eventStoreRepository; }
public override void Execute(ICommand cmd, IEventSourceRepository repository) { var c = cmd.MapToCommand <CreateNewCustomerCommand>(); Self.CreateNewCustomer(c.Name, c.CashBalance); }
public CustomerCommandHandler(ICustomersRepository customersRepository, IEventSourceRepository eventStoreRepository) { _customersRepository = customersRepository; _eventStoreRepository = eventStoreRepository; }
public FinishMaintenanceJobCommandHandler(IMessagePublisher messagePublisher, IEventSourceRepository <WorkshopPlanning> planningRepo) { _messagePublisher = messagePublisher; _planningRepo = planningRepo; }
public MovieReleasedDateChangedEventHandler(IEventSourceRepository eventSourceRepository) { this.eventSourceRepository = eventSourceRepository; }
public AccountCommandHandler(IAccountRepository accountRepository, IEventSourceRepository eventStoreRepository) { _accountRepository = accountRepository; _eventStoreRepository = eventStoreRepository; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifetime, IEventSourceRepository <WorkshopPlanning> workshopPlanningRepo) { Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(_configuration) .Enrich.WithMachineName() .CreateLogger(); app.UseMvc(); app.UseDefaultFiles(); app.UseStaticFiles(); // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "WorkshopManagement API - v1"); }); // initialize database workshopPlanningRepo.EnsureDatabase(); }
public override void Execute(ICommand cmd, IEventSourceRepository repository) { var c = cmd.MapToCommand <CreateNewProductCommand>(); Self.CreateNewProduct(c.ProductName, c.Price, c.Stock); }
public OrdersController(IUnitOfWork uow, IEventSourceRepository repo) { this.UnitOfWork = uow; this.repo = repo; }
public SupplierCommandHandler(ISupplierRepository supplierRepository, IEventSourceRepository eventSourceRepository) { _supplierRepository = supplierRepository; _eventSourceRepository = eventSourceRepository; }