Exemplo n.º 1
0
        public async Task Handle(DisableTradeLocationCommand notification)
        {
            var entityCurrent = await _tradeRepository.GetLocationByIdAsync(notification.IdTradeLocations);

            if (!IsEntityFound(entityCurrent, notification.MessageType, "TradeLocation.NotFound"))
            {
                return;
            }

            var entityCurrentTrade = await _tradeRepository.GetByIdAsync((int)entityCurrent.IdParent);

            if (!IsEntityFound(entityCurrentTrade, notification.MessageType, "Trade.NotFound"))
            {
                return;
            }

            var userEntity = GetUserEntityTrade(notification.UserLoggedIn, entityCurrentTrade.UserGet, entityCurrentTrade.UserLet);

            if (userEntity == null)
            {
                return;
            }
            if (!IsUserCanModifyEntity(notification.UserLoggedIn, userEntity))
            {
                return;
            }

            await _tradeRepository.DisableLocationAsync(entityCurrentTrade.Id, entityCurrent.Id);

            if (Commit())
            {
                await _mediator.PublishEvent(new TradeLocationDisabledEvent(_logger, notification.IdTradeLocations));
            }
        }