public async Task <bool> Handle(CompleteGoalCommand command, CancellationToken cancellationToken)
        {
            var goal = await _goalsRepository.FindByIdAsync(command.Id);

            if (goal == null)
            {
                throw new Exception("The goal wasn't found");
            }

            goal.Complete();

            await _goalsRepository.Update(goal);

            await _goalsRepository.UnitOfWork.SaveEntitiesAsync();

            return(true);
        }
Exemple #2
0
        public async Task <bool> Handle(UpdateGoalCommand request, CancellationToken cancellationToken)
        {
            var goal = await _goalsRepository.FindByIdAsync(request.Id);

            if (goal == null)
            {
                throw new Exception("The goal wasn't found");
            }

            goal.Title       = request.Title;
            goal.Description = request.Description;
            goal.AimDate     = request.AimDateStart.HasValue ? new DateTimeInterval(request.AimDateStart.Value, request.AimDateEnd.Value) : null;

            await _goalsRepository.Update(goal);

            await _goalsRepository.UnitOfWork.SaveEntitiesAsync();

            return(true);
        }