public async Task <ICommandResult> Handle(CartAddCommand mesage) { try { bool isLockSuccess = await _cartService.CreatingCart(mesage.ClientId); if (isLockSuccess) { var shard = await _shardingService.GetCurrentWriteShardByRoundRobin(ShardGroup); Cart cart = new Cart(mesage, shard.Id, mesage.Version); CartItem shoppingCartItem = new CartItem(mesage.CartItem); CartItemDetail shoppingCartItemDetail = new CartItemDetail(mesage.CartItemDetail); var newCartItems = cart.Add(shoppingCartItem, shoppingCartItemDetail, mesage.CartItem.Quantity, out var newCartItemDetail); await _cartService.Save(shard.ConnectionString, cart, newCartItems, newCartItemDetail); _eventSender.Add(cart.Events); await _eventSender.Notify(); ICommandResult result = new CommandResult() { Message = "", ObjectId = cart.Id, Status = CommandResult.StatusEnum.Sucess, }; return(result); } else { throw new MessageException(ResourceKey.Cart_IsCreating); } } catch (MessageException e) { e.Data["Param"] = mesage; ICommandResult result = new CommandResult() { Message = e.Message, Status = CommandResult.StatusEnum.Fail, ResourceName = e.ResourceName }; return(result); } catch (Exception e) { e.Data["Param"] = mesage; ICommandResult result = new CommandResult() { Message = e.Message, Status = CommandResult.StatusEnum.Fail }; return(result); } finally { await _cartService.CreatedCart(mesage.ClientId); } }