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 }); }
private void UpdateAllDetails( Domain.Entity.LearningCalendar.LearningDay learningDay, Domain.Entity.LearningCalendar.Employee employee, UpdateLearningDayOperationRequest request) { List <(UpdateLearningDayOperationRequest.LearningDayTopic requestTopic, LearningDayTopic topic)> nonDeletedTopics = request.LearningDayTopics .Select(requestTopic => (requestTopic, learningDay.GetDayTopicByTopicId(requestTopic.TopicId))) .ToList(); var createdTopics = nonDeletedTopics .Where(group => group.topic == null) .Select(group => CreateDayTopic(employee, group.requestTopic)) .ToList(); var topicsToUpdate = nonDeletedTopics .Where(group => group.topic != null) .ToList(); topicsToUpdate.ForEach(group => UpdateDayTopic(employee, group.requestTopic, group.topic)); var updatedTopics = topicsToUpdate .Select(group => group.topic); learningDay.LearningDayTopics = createdTopics .Concat(updatedTopics) .ToList(); UpdateComment(learningDay, request); }
private void UpdateComment( Domain.Entity.LearningCalendar.LearningDay learningDay, UpdateLearningDayOperationRequest request) { learningDay.Comments = request.Comments; }