Ejemplo n.º 1
0
        public async Task <IActionResult> Update([FromBody] OrderDTO entity)
        {
            var user = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            await _service.Update(entity.ToOrderEntity(), user);

            await _mediator.Publish(new UpdateOrderCommand(entity));

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Add([FromBody] OrderDTO entity)
        {
            var user   = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var result = await _service.CreateAsync(entity.ToOrderEntity(), user);

            var saved = await _service.GetAsync(result.Id, "Customer", "OrderDetails");

            //assign product to order detail to save in the event store
            var dto = saved.ToOrderDTO();

            for (int i = 0; i < dto.OrderDetails.Count; i++)
            {
                dto.OrderDetails[i].Product = entity.OrderDetails.Find(x => x.ProductId ==
                                                                       dto.OrderDetails[i].ProductId).Product;
            }
            await _mediator.Publish(new UpdateStockCommand(dto));

            return(Ok(entity));
        }