コード例 #1
0
        public async Task Handle(AddTradeEvaluationCommand notification)
        {
            var entityCurrentNotification = Mapper.Map <TradeEvaluationModel, Evaluation>(notification.TradeEvaluationModel);

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

            var entityCurrentDB = await _tradeRepository.GetByIdAsync(notification.TradeEvaluationModel.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.AddEvaluationAsync(entityCurrentDB.Id, entityCurrentNotification);

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