Example #1
0
        public async Task <CarManufactureChanged> Handle(RequestChangeCarManufacture request, CancellationToken cancellationToken)
        {
            var result = await _carModel.ChangeCarManufacture(request);

            var evt = CarManufactureChanged.From(result);
            await _mediator.Publish(AggregateEvent.Create <RequestChangeCarManufacture>(evt.AggregateId, evt, request));

            await _mediator.Publish(evt);

            return(evt);
        }
Example #2
0
        public async Task <Car> ChangeCarManufacture(RequestChangeCarManufacture changeCarManufacture)
        {
            var ob = car.Cars.FirstOrDefault(c => c.Id == changeCarManufacture.AggregateId);

            ob.Model = changeCarManufacture.Model ?? ob.Model;
            ob.Make  = changeCarManufacture.Make ?? ob.Make;
            ob.Year  = changeCarManufacture.Year ?? ob.Year;
            car.Cars.Update(ob);
            await car.SaveChangesAsync();

            return(ob);
        }
        public async Task <ActionResult> UpdateCarAsync([FromBody] RequestChangeCarManufacture car)
        {
            try
            {
                await _mediator.Send(car);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(NotFound(ex));
            }
        }