/// <summary> /// Retrieves a learning scenario by a provided id parameter and updates /// the scenario with data provided in a learning scenario binding model. /// </summary> /// <param name="id"></param> /// <param name="model"></param> /// <returns>Id of updated scenario</returns> public async Task <int> UpdateScenario(int id, LsBM model) { var ls = await context.Ls.FindAsync(id); if (ls == null) { throw new NotFoundException($"Scenario {id} does not exist."); } if (ls.UserId.ToString() != httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value) { logger.LogError($"Not authorized to view scenario with id { id }"); throw new NotAuthorizedException($"You are not authorized to view this resource."); } ls = mapper.Map <Ls>(model); ls.LearningOutcomeCtid = await learningOutcomeCtRepository.CreateLearningOutcomeCts(model.LearningOutcomeCts); ls.LearningOutcomeSubjectId = await learningOutcomeSubjectRepository.CreateLearningOutcomeSubject(model.LearningOutcomeSubjects); context.Ls.Update(ls); await context.SaveChangesAsync(); await keywordRepository.RemoveKeywords(model.Keywords, ls.Idls); await keywordRepository.CreateKeywords(model.Keywords, ls.Idls); await lsCorrelationRepository.RemoveLsCorr(ls.Idls); await lsCorrelationRepository.CreateTeachingCorrelationSubjects(model.CorrelationSubjectIds, ls.Idls); return(id); }