public async Task <SessionDetailsModel> CreateAsync(SessionCreateModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            var session = Mapper.Map <Session>(model);

            // verify speaker id and audience id are valid
            var speaker = await SpeakersRepository.GetByIdAsync(session.SpeakerId);

            var audience = await AudiencesRepository.GetByIdAsync(session.AudienceId);

            if (speaker == null || audience == null)
            {
                throw new IndexOutOfRangeException();
            }

            session.Speaker  = speaker;
            session.Audience = audience;
            var created = await Repository.CreateAsync(session);

            await Audit.AuditCreatedAsync($"Session {session.Title} has been created");

            return(Mapper.Map <SessionDetailsModel>(created));
        }
        public async Task <SessionDetailsModel> UpdateAsync(Guid id, SessionUpdateModel model)
        {
            if (id.Equals(Guid.Empty))
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var found = await Repository.GetByIdAsync(id);

            if (found == null)
            {
                return(null);
            }


            Mapper.Map <SessionUpdateModel, Session>(model, found);
            // verify speaker id and audience id are valid
            var speaker = await SpeakersRepository.GetByIdAsync(found.SpeakerId);

            var audience = await AudiencesRepository.GetByIdAsync(found.AudienceId);

            if (speaker == null || audience == null)
            {
                throw new IndexOutOfRangeException();
            }

            found.Speaker  = speaker;
            found.Audience = audience;

            var updated = await Repository.UpdateAsync(found);

            await Audit.AuditCreatedAsync($"Session {updated.Title} has been updated");

            return(Mapper.Map <SessionDetailsModel>(updated));
        }