public async Task <Unit> Handle(ChangeOrderStateCommand request, CancellationToken cancellationToken) { var userId = _httpContextAccessor.HttpContext.User.Claims.ToTokenPayload().UserClaims.Id; var orderId = Guid.Parse(request.OrderId); var order = await _orderRepository.GetByIdAsync(orderId); if (order == null || order.SellerId != userId) { throw new NotFoundException(); } var newOrderState = OrderState.Parse(request.OrderState); if (newOrderState == order.OrderState) { return(await Unit.Task); } order.ChangeOrderState(newOrderState); _orderRepository.Update(order); await _orderRepository.UnitOfWork.SaveChangesAndDispatchDomainEventsAsync(cancellationToken); return(await Unit.Task); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity <Order>() .HasKey(x => x.Id); modelBuilder.Entity <Order>() .Property(x => x.OrderState) .HasConversion(x => x.Name, x => OrderState.Parse(x)) .HasDefaultValue(OrderState.Started); modelBuilder.Entity <OrderItem>() .HasKey(x => x.Id); modelBuilder.Entity <OrderItem>() .Property(x => x.PricePerItem) .HasColumnType("decimal(18,4)"); modelBuilder.Entity <DeliveryAddress>() .HasKey(x => x.Id); modelBuilder.Entity <DeliveryMethod>() .HasKey(x => x.Id); }