コード例 #1
0
ファイル: CustomerCommandHandler.cs プロジェクト: thild/koos
        public async Task <bool> Handle(UpdateGoalCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(false);
            }

            var goal = new Goal(message.Description,
                                message.Reward,
                                message.StarsToAchieve,
                                message.StarsEarned,
                                message.StartDate,
                                message.EndDate);

            var existingGoal = _goalRepository.GetById(goal.Id);

            if (existingGoal != null && existingGoal.Id != goal.Id)
            {
                if (!existingGoal.Equals(goal))
                {
                    await Bus.RaiseEvent(new DomainNotification(message.MessageType, "The Goal e-mail has already been taken."));

                    return(false);
                }
            }

            _goalRepository.Update(goal);

            if (await Commit())
            {
                await Bus.RaiseEvent(new GoalUpdatedEvent(goal.Id,
                                                          goal.Description,
                                                          goal.Reward,
                                                          goal.StarsToAchieve,
                                                          goal.StarsEarned,
                                                          goal.StartDate,
                                                          goal.EndDate));
            }

            return(true);
        }