public async Task <IHaveSessionDetails> GetSessionDetails(ISessionDetails details) { var sessionSpecification = TherapySessionSpecification.ByDetailsOrderDesc(details); var therapySession = await _therapySessionRepository.GetFirstOrDefaultAsync(sessionSpecification); if (therapySession != null) { return(therapySession); } var timeSlotSpecification = TimeSlotSpecification.ByDetailsOrderByDateDesc(details); var timeSlot = await _timeSlotRepository.GetFirstOrDefaultAsync(timeSlotSpecification); Check.NotNull(timeSlot, nameof(timeSlot)); return(timeSlot); }
public async Task <TherapySession> GetOrCreateIfNotExistsAsync(ISessionDetails details) { var sessionSpecification = TherapySessionSpecification.ByDetailsOrderDesc(details); var therapySession = await _therapySessionRepository.GetSingleOrDefaultAsync(sessionSpecification); if (therapySession != null) { return(therapySession); } var timeSlotSpecification = TimeSlotSpecification.ByDetailsOrderByDateDesc(details); var timeSlot = await _timeSlotRepository.GetFirstOrDefaultAsync(timeSlotSpecification); Check.NotNull(timeSlot, nameof(timeSlot)); therapySession = new TherapySession(details.DateTime, timeSlot); _therapySessionRepository.Add(therapySession); _logger.LogInformation($"Created therapySession with Id = {therapySession.Id}"); return(therapySession); }