Example #1
0
        public async Task Execute(FulfillPersonalGoalOperationRequest request)
        {
            var employee = await _authorizationContext.CurrentEmployee();

            var personalGoal = employee.PersonalGoals
                               .FirstOrDefault(goal => goal.TopicId == request.TopicId && goal.CompletionDate == null);

            if (personalGoal == null)
            {
                throw new ApplicationException($"Goal for topic {request.TopicId} not found");
            }

            personalGoal.CompletionDate = DateTime.Today;

            await _employeeRepository.UpdateAsync(employee);
        }
        public async Task Execute(LearnTopicOperationRequest request)
        {
            var fulfillGoalRequest = new FulfillPersonalGoalOperationRequest
            {
                TopicId = request.TopicId
            };

            try
            {
                await _fulfillPersonalGoalOperation.Execute(fulfillGoalRequest);
            }
            catch (GoalNotAssignedException)
            {
                var assignGoalRequest = new AssignGoalToSelfOperationRequest
                {
                    TopicIds = new List <Guid> {
                        request.TopicId
                    }
                };
                await _assignGoalsToSelfOperation.Execute(assignGoalRequest);

                await _fulfillPersonalGoalOperation.Execute(fulfillGoalRequest);
            }
        }