示例#1
0
        public async Task Handle(AddTradeLocationCommand notification)
        {
            var entityCurrentNotification = Mapper.Map <TradeLocationModel, Location>(notification.TradeLocationModel);

            if (!IsEntityValid(entityCurrentNotification))
            {
                return;
            }

            var entityCurrentDB = await _tradeRepository.GetByIdAsync(notification.TradeLocationModel.IdParent);

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

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

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

            await _tradeRepository.AddLocationAsync(entityCurrentDB.Id, entityCurrentNotification);

            if (Commit())
            {
                await _mediator.PublishEvent(new TradeLocationAddedEvent(_logger, Mapper.Map <TradeLocationModel>(notification.TradeLocationModel)));
            }
        }