public async Task <ActionResult <LearningDayModel> > CreateLearningDay(CreateLearningDayModel model)
        {
            var request = new CreateLearningDayOperationRequest
            {
                Date     = model.Date.Date,
                Comments = model.Comments,
                TopicIds = model.TopicIds
            };

            CreateLearningDayOperationResponse response;

            try
            {
                response = await _createLearningDayOperation.Execute(request);
            }
            catch (LearningDayAlreadyExistsException ex)
            {
                return(Conflict(ex.Message));
            }
            catch (LimitExceededException ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(new LearningDayModel {
                Id = response.Id
            }));
        }
Exemplo n.º 2
0
        public async Task <CreateLearningDayOperationResponse> Execute(CreateLearningDayOperationRequest request)
        {
            var employee = await _authorizationContext.CurrentEmployee();

            await ThrowIfInvalidLearningDayAsync(employee.Id, request.Date);

            var learningDayTopics = request.TopicIds?
                                    .Select(topicId => new Domain.Entity.LearningCalendar.LearningDayTopic
            {
                TopicId        = topicId,
                ProgressStatus = Domain.Entity.LearningCalendar.ProgressStatus.InProgress
            }).ToList();

            var learningDay = new Domain.Entity.LearningCalendar.LearningDay
            {
                EmployeeId        = employee.Id,
                Date              = request.Date,
                Comments          = request.Comments,
                LearningDayTopics = learningDayTopics
            };

            await _learningDayRepository.CreateAsync(learningDay);

            return(new CreateLearningDayOperationResponse
            {
                Id = learningDay.Id
            });
        }