コード例 #1
0
ファイル: Edit.cs プロジェクト: imambaig/RMSGlobal
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var directSale = await _context.DirectSales.FindAsync(request.Id);

                if (directSale == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { directsale = "Could not find directsale" });
                }

                ////_context.Database.BeginTransaction();
                // Add Integration event to clean the basket

                directSale.Name           = request.Name ?? directSale.Name;
                directSale.EndDate        = request.EndDate ?? directSale.EndDate;
                directSale.DirectSaleType = request.DirectSaleType ?? directSale.DirectSaleType;

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    var _directSalePublishedStartedIntegrationEvent = new DirectSalePublishedIntegrationEvent(request.Id, request.Name, request.DirectSaleType, request.EndDate);
                    await _sellerIntegrationEventService.AddAndSaveEventAsync(_directSalePublishedStartedIntegrationEvent);

                    ////_context.Database.CommitTransaction();

                    //_sellerIntegrationEventService.PublishEvent(_directSalePublishedStartedIntegrationEvent);
                    return(Unit.Value);
                }


                throw new Exception("Problem Saving Changes");
            }
コード例 #2
0
ファイル: Create.cs プロジェクト: imambaig/RMSGlobal
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var directSale = new DirectSale
                {
                    Id             = request.Id,
                    Name           = request.Name,
                    EndDate        = request.EndDate,
                    DirectSaleType = request.DirectSaleType
                };

                _context.DirectSales.Add(directSale);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    var _directSalePublishedStartedIntegrationEvent = new DirectSalePublishedIntegrationEvent(request.Id, request.Name, request.DirectSaleType, request.EndDate);
                    //await _sellerIntegrationEventService.AddAndSaveEventAsync(_directSalePublishedStartedIntegrationEvent);
                    //_context.Database.CommitTransaction();
                    _sellerIntegrationEventService.PublishEvent(_directSalePublishedStartedIntegrationEvent);
                    return(Unit.Value);
                }
                throw new Exception("Problem Saving Changes");
            }