Пример #1
0
        public async Task <Unit> Handle(ShowMyPackCommand command, CancellationToken cancellationToken)
        {
            var playerId = command.PlayerId;
            var myPack   = new MyPack()
            {
                Money = "",
                Wares = new List <WareModel>()
            };
            var player = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                return(Unit.Value);
            }

            myPack.Money = player.Money.ToMoney();

            var playerWares = await _playerWareDomainService.GetAll(player.Id);

            if (playerWares == null)
            {
                return(Unit.Value);
            }

            var ids = playerWares.Select(x => x.WareId);

            var wares = (await _wareDomainService.GetAll()).Where(x => ids.Contains(x.Id));

            foreach (var playerWare in playerWares)
            {
                var ware = wares.FirstOrDefault(x => x.Id == playerWare.WareId);
                if (ware != null)
                {
                    var wareModel = _mapper.Map <WareModel>(ware);
                    wareModel.PlayerWareId = playerWare.Id;
                    wareModel.Number       = playerWare.Number;
                    wareModel.Status       = playerWare.Status;
                    myPack.Wares.Add(wareModel);
                }
            }

            await _mudProvider.ShowMyPack(playerId, myPack);

            return(Unit.Value);
        }