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> CreateNew(SessionCreateModel newSession) { var session = Domain.Session.Create(newSession.LaboratoryId, GenerateConfirmationCode(), newSession.Duration); await _writeRepository.AddNewAsync(session); await _writeRepository.SaveAsync(); return(await FindById(session.Id)); }
public async Task <IActionResult> CreateSession([FromBody] SessionCreateModel sessionCreateModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var session = await _sessionService.CreateNew(sessionCreateModel); return(Ok(session)); }
public async Task <IActionResult> CreateSessionAsync([FromBody] SessionCreateModel model) { try { var created = await Service.CreateAsync(model); return(CreatedAtRoute("GetSessionById", new { id = created.Id }, created)); } catch (IndexOutOfRangeException) { return(BadRequest()); } }