Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates new Ls (learning scenario) and its corresponding
        /// objects such as keywords, teachingcorrelationsubjects and learningoutcomes.
        /// </summary>
        /// <param name="model"></param>
        /// <returns>Id of newly created scenario</returns>
        public async Task <int> CreateScenario(LsBM model)
        {
            var ls = mapper.Map <Ls>(model);

            ls.UserId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            ls.LearningOutcomeCtid = await learningOutcomeCtRepository.CreateLearningOutcomeCts(model.LearningOutcomeCts);

            ls.LearningOutcomeSubjectId = await learningOutcomeSubjectRepository.CreateLearningOutcomeSubject(model.LearningOutcomeSubjects);

            ls.Lsduration = TimeSpan.Zero;
            context.Ls.Add(ls);
            await context.SaveChangesAsync();

            await keywordRepository.CreateKeywords(model.Keywords, ls.Idls);

            await lsCorrelationRepository.CreateTeachingCorrelationSubjects(model.CorrelationSubjectIds, ls.Idls);

            logger.LogInformation($"Successfully created learning scenario with id { ls.Idls }");
            return(ls.Idls);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateScenario([FromRoute] int id, [FromBody] LsBM model)
        {
            var result = await scenariosService.UpdateScenario(id, model);

            return(Ok($"Scenario {result} successfully updated."));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CreateScenario([FromBody] LsBM model)
        {
            var result = await scenariosService.CreateScenario(model);

            return(Ok(new { scenarioId = result }));
        }