public async Task <ActionResult <AttendeeResponse> > AddSession(string username, int sessionId) { var attendee = await _attendeesRepository.GetByUsernameAsync(username); if (attendee == null) { return(NotFound()); } var session = await _sessionsRepository.GetByIdAsync(sessionId); if (session == null) { return(BadRequest()); } var newAttendee = await _attendeesRepository.AddSessionAsync(username, sessionId); if (!newAttendee.ConferenceAttendees.Any(ca => ca.ConferenceId == session.ConferenceId)) { newAttendee = await _attendeesRepository.AddConferenceAsync(username, session.ConferenceId); } var result = newAttendee.MapAttendeeResponse(); return(CreatedAtAction(nameof(GetByUsername), new { username = result.UserName }, result)); }
public async Task <ActionResult <SessionResponse> > Get(int id) { var cacheKey = $"{_getSessions}{id}"; var cachedValue = await _cache.GetAsync(cacheKey); var result = cachedValue.FromByteArray <SessionResponse>(); if (result == null) { var session = await _sessionsRepository.GetByIdAsync(id); if (session == null) { return(NotFound()); } result = session.MapSessionResponse(); await CacheValue(cacheKey, result); } return(result); }
public async Task <ActionResult <ConferenceDTO.SpeakerResponse> > DeleteSpeaker(int id) { var speaker = await _speakersRepository.DeleteAsync(id); if (speaker == null) { return(NotFound()); } foreach (var sessionId in speaker.SessionSpeakers.Select(ss => ss.SessionId)) { var session = await _sessionsRepository.GetByIdAsync(sessionId); if (!session.SessionSpeakers.Any()) { await _sessionsRepository.DeleteAsync(sessionId); } } return(speaker.MapSpeakerResponse()); }