Example #1
0
        public string SaveTeamSiteHierarchy(IEnumerable <AppDivisions> paramDes)
        {
            // Break the teamsite and segement relation
            teamRepository.UnrelateTeamSitesWithSegment();
            // teamRepository.UnitOfWork.Commit();
            var subSegments = segRepository.GetFiltered(_ => _.ParentSegement != null);

            foreach (var sub in subSegments)
            {
                segRepository.RemoveSegementById(sub.Id);
                segRepository.UnitOfWork.Commit();
            }

            repository.RemoveAllDivisions();
            repository.UnitOfWork.Commit();


            // Division save
            var divisions = paramDes.FirstOrDefault().children;

            if (divisions == null)
            {
                return("succeed");
            }
            else
            {
                foreach (var d in divisions)
                {
                    var addedDivision = repository.AddNewDivision(new Division()
                    {
                        Id = d.Id.GetValueOrDefault(), Name = d.title, DivisionGuid = Guid.NewGuid()
                    });
                    // Add segments for this division
                    if (addedDivision != null && d.children != null)
                    {
                        foreach (var s in d.children)
                        {
                            var segment = segRepository.AddSegment(new Segment()
                            {
                                Name = s.title, DivisionId = addedDivision.Id, SegmentGuid = Guid.NewGuid()
                            });

                            // Add sub segment
                            if (segment != null && s.children != null)
                            {
                                foreach (var sub in s.children)
                                {
                                    if (sub.tooltip == "subsegment")
                                    {
                                        // add sub segment
                                        var subsegment = segRepository.AddSegment(new Segment()
                                        {
                                            Name = sub.title, SegmentGuid = Guid.NewGuid(), ParentId = segment.Id
                                        });

                                        if (subsegment != null)
                                        {
                                            // Add team site relation with the
                                            foreach (var t in sub.children)
                                            {
                                                teamRepository.RelateTeamSiteWithSegement(Guid.Parse(t.key), subsegment.Id);
                                                teamRepository.UnitOfWork.Commit();
                                            }
                                        }
                                    }

                                    else if (sub.tooltip == "team")
                                    {
                                        teamRepository.RelateTeamSiteWithSegement(Guid.Parse(sub.key), segment.Id);
                                        teamRepository.UnitOfWork.Commit();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return("{\"Result\":succeed}");
        }