Esempio n. 1
0
        public static ConceptResult GetConceptResultTreeInViews(Concept concept, List <WatchingTimeResult> views)
        {
            if (concept == null || (concept.Children == null || concept.Children.Count == 0) &&
                views.All(x => x.ConceptId != concept.Id))
            {
                return(null);
            }

            var currentConcept = new ConceptResult
            {
                Name   = concept.Name,
                IsFile = true
            };

            if (concept.Children != null && concept.Children.Count != 0)
            {
                currentConcept.Children = new List <ConceptResult>();
                foreach (var child in concept.Children)
                {
                    var childConceptResult = GetConceptResultTreeInViews(child, views);
                    if (childConceptResult == null)
                    {
                        continue;
                    }
                    currentConcept.Children.Add(childConceptResult);
                }

                if (currentConcept.Children.Count == 0)
                {
                    return(null);
                }

                currentConcept.IsFile = false;
            }
            else
            {
                var viewInfo = views.Find(x => x.ConceptId == concept.Id).Views;
                if (viewInfo != null)
                {
                    currentConcept.ViewTime = viewInfo.Time;
                }
                else
                {
                    currentConcept.ViewTime = null;
                }

                currentConcept.Estimated = WatchingTimeService.GetEstimatedTime(concept.Container);
            }

            currentConcept.ConceptId = concept.Id;
            return(currentConcept);
        }
Esempio n. 2
0
        public IActionResult Get(int id)
        {
            var rootId      = -1;
            var studentId   = -1;
            var queryParams = Request.Query
                              .ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);

            if (queryParams.ContainsKey("root"))
            {
                int.TryParse(queryParams["root"], out rootId);
            }

            if (queryParams.ContainsKey("studentId"))
            {
                int.TryParse(queryParams["studentId"], out studentId);
            }

            var studentInfo = StudentManagementService.GetStudent(studentId);
            var concepts    = ConceptManagementService.GetElementsBySubjectId(id).Where(x => x.Container != null).ToList();
            var viewsResult = new List <WatchingTimeResult>();

            foreach (var concept in concepts)
            {
                if (GetConceptParentId(concept) == rootId)
                {
                    var views = WatchingTimeService.GetAllRecords(concept.Id, studentId).FirstOrDefault();
                    viewsResult.Add(new WatchingTimeResult
                    {
                        ConceptId = concept.Id,
                        ParentId  = concept.ParentId,
                        Name      = concept.Name,
                        Views     = views,
                        Estimated = WatchingTimeService.GetEstimatedTime(concept.Container)
                    });
                }
            }

            var tree       = ConceptManagementService.GetTreeConceptByElementId(rootId);
            var treeresult = ConceptResult.GetConceptResultTreeInViews(tree, viewsResult);

            var result = new StudentInfoResult
            {
                Tree            = treeresult.Children,
                StudentFullName = studentInfo.FullName,
                GroupNumber     = studentInfo.Group.Name
            };

            return(Ok(result));
        }