Пример #1
0
        /// <summary>
        /// Adds the new session to a code camp.
        /// </summary>
        /// <param name="moniker">The moniker.</param>
        /// <param name="sessionModel">The session model.</param>
        /// <exception cref="InvalidOperationException"></exception>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">moniker</exception>
        public async Task <SessionModel> AddNewSessionToACodeCamp(string moniker, SessionModel sessionModel)
        {
            if (moniker == null)
            {
                throw new ArgumentNullException(nameof(moniker));
            }

            var camp = await _codeCampRepository.GetCampByMonikerAsync(moniker);

            if (camp == null)
            {
                throw new InvalidOperationException("Cannot find a code camp by given moniker");
            }

            var session = _mapper.Map <Session>(sessionModel);

            if (sessionModel.Speaker?.Id != null)
            {
                var speaker = await _speakerRepository.GetByIdAsync(sessionModel.Speaker.Id);

                if (speaker == null)
                {
                    throw new InvalidOperationException("Cannot find a speaker for given Identifier");
                }

                session.Speaker = speaker;
            }

            session.CodeCamp = camp;
            _repository.Insert(session);
            await _repository.SaveAsync();

            return(_mapper.Map <SessionModel>(await _repository.GetSessionByMonikerAsync(moniker, session.Id, false)));
        }