示例#1
0
        public IHttpActionResult GetMainActivities([FromUri] SearchActivityCriteria criteria)
        {
            try
            {
                if (criteria.IsNull())
                {
                    return(BadRequest("Invalid criteria received."));
                }

                if (criteria.StartTime.IsNull() || criteria.StartTime == default(DateTime))
                {
                    return(BadRequest("Start time is required."));
                }

                return(Ok(_activitiesService.GetActivities(criteria)));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        /// <summary>
        /// Retrieves scenario data with provided id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Learning scenario data transfer model</returns>
        public async Task <LsDTO> GetScenario(int id)
        {
            var ls = await context.Ls.FindAsync(id);

            if (ls == null)
            {
                logger.LogError($"Scenario with id { id } not found.");
                throw new NotFoundException($"Learning scenario with id {id} not found.");
            }
            if (ls.LstypeId == (int)LsTypeEnum.Private && ls.UserId != httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                logger.LogError($"Not authorized to update scenario { id }");
                throw new NotAuthorizedException($"You are not authorized to view this resource.");
            }

            var lsDTO = mapper.Map <LsDTO>(ls);

            // Add user
            lsDTO.UserId = ls.UserId;
            var keywords = context.Lskeyword.Where(x => x.Lsid == ls.Idls)
                           .ToList();

            foreach (var keyword in keywords)
            {
                var kwrd = await context.Keyword.FindAsync(keyword.Keywordid);

                lsDTO.Keywords.Add(kwrd.KeywordName);
            }


            var correlations = context.LscorrelationInterdisciplinarity.Where(x => x.Lsid == ls.Idls)
                               .Select(x => x.TeachingSubjectId)
                               .ToList();

            foreach (var correlation in correlations)
            {
                var corr = await context.TeachingSubject.FindAsync(correlation);

                lsDTO.CorrelationInterdisciplinaritySubjects.Add(corr.TeachingSubjectName);
            }

            var taName = await context.TeachingSubject.FindAsync(ls.TeachingSubjectId);

            lsDTO.TeachingSubjectName = taName.TeachingSubjectName;

            // Add learningOutcomeCt
            var learningOutcomeCt = await context.LearningOutcomeCt.FindAsync(ls.LearningOutcomeCtid);

            var learningOutcomeCts = learningOutcomeCt.LearningOutcomeCtstatement.Trim().Split("||");

            learningOutcomeCts       = learningOutcomeCts.Take(learningOutcomeCts.Count() - 1).ToArray();
            lsDTO.LearningOutcomeCts = learningOutcomeCts;

            //Add learningOutcomeSubject
            var learningOutcomeSubject = await context.LearningOutcomeSubject.FindAsync(ls.LearningOutcomeSubjectId);

            var learningOutcomeSubjects = learningOutcomeSubject.LearningOutcomeSubjectStatement.Trim().Split("||");

            learningOutcomeSubjects       = learningOutcomeSubjects.Take(learningOutcomeSubjects.Count() - 1).ToArray();
            lsDTO.LearningOutcomeSubjects = learningOutcomeSubjects;
            lsDTO.Las = await activityService.GetActivities(id);

            lsDTO.Las = lsDTO.Las.OrderBy(x => x.OrdinalNumber).ToList();

            var teachingAidsTeacher = new List <TeachingAid>();
            var teachingAidsStudent = new List <TeachingAid>();
            var strategyMethodsList = new List <StrategyMethodBM>();

            // Strategy method, Collaboration and Teaching Aids from LA
            foreach (var la in lsDTO.Las)
            {
                lsDTO.CollaborationNames.Add(la.Lacollaboration);
                lsDTO.CollaborationNames = lsDTO.CollaborationNames.Union(lsDTO.CollaborationNames).ToList();
                lsDTO.StrategyMethods    = lsDTO.StrategyMethods.Union(la.StrategyMethods).ToList();

                var strategyMethods = context.LastrategyMethod.Where(x => x.Laid == la.Idla);
                foreach (var sM in strategyMethods)
                {
                    var strategyM = await context.StrategyMethod.Where(x => x.IdstrategyMethod == sM.StrategyMethodId).ToListAsync();

                    foreach (var s in strategyM)
                    {
                        var sMExists = strategyMethodsList.FirstOrDefault(x => x.IdstrategyMethod == s.IdstrategyMethod);
                        if (sMExists == null)
                        {
                            strategyMethodsList.Add(mapper.Map <StrategyMethodBM>(s));
                        }
                    }
                }

                var teachingAidTeacher = context.LateachingAid.Where(x => x.Laid == la.Idla && x.LateachingAidUser == false);
                foreach (var tat in teachingAidTeacher)
                {
                    var tats = await context.TeachingAid.Where(x => x.IdteachingAid == tat.TeachingAidId).ToListAsync();

                    foreach (var t in tats)
                    {
                        var tExists = teachingAidsTeacher.FirstOrDefault(x => x.TeachingAidName == t.TeachingAidName);
                        if (tExists == null)
                        {
                            teachingAidsTeacher.Add(t);
                        }
                    }
                }
                var teachingAidStudent = context.LateachingAid.Where(x => x.Laid == la.Idla && x.LateachingAidUser == true);
                foreach (var tas in teachingAidStudent)
                {
                    var tass = await context.TeachingAid.Where(x => x.IdteachingAid == tas.TeachingAidId).ToListAsync();

                    foreach (var t in tass)
                    {
                        var tExists = teachingAidsStudent.FirstOrDefault(x => x.TeachingAidName == t.TeachingAidName);
                        if (tExists == null)
                        {
                            teachingAidsStudent.Add(t);
                        }
                    }
                }
            }

            if (teachingAidsTeacher.Count > 0)
            {
                lsDTO.TeachingAidTeacher = teachingAidsTeacher;
            }

            if (teachingAidsStudent.Count > 0)
            {
                lsDTO.TeachingAidUser = teachingAidsStudent;
            }

            if (strategyMethodsList.Count > 0)
            {
                lsDTO.StrategyMethods = strategyMethodsList;
            }

            return(lsDTO);
        }
        public async Task <IActionResult> GetActivities([FromRoute] int scenarioId)
        {
            var result = await activitiesService.GetActivities(scenarioId);

            return(Ok(result));
        }