Ejemplo n.º 1
0
        private StructuralGroup CreateStructure()
        {
            var root = new StructuralGroup(StructuralGroupType.Root, "Joe's Primary");

            foreach (var gradeNumber in Enumerable.Range(1, 7))
            {
                var grade = new StructuralGroup(StructuralGroupType.Intermediate, "Grade " + gradeNumber);
                foreach (var classLetter in Enumerable.Range(65, 4).Select(i => ((char)i).ToString()))
                {
                    var className = string.Format("{0}{1}", gradeNumber, classLetter);
                    var @class    = new StructuralGroup(StructuralGroupType.Leaf, className);
                    @class.Parent = grade;
                    grade.ChildGroups.Add(@class);

                    foreach (var studentNumber in Enumerable.Range(1, 5))
                    {
                        var member = CreateStudent(className, studentNumber);
                        @class.Members.Add(member);
                    }
                }
                grade.Parent = root;
                root.ChildGroups.Add(grade);
            }

            return(root);
        }
Ejemplo n.º 2
0
 private void PopulateChildren(StructuralGroup group, List <StructuralGroup> allGroups)
 {
     group.ChildGroups = allGroups.Where(g => g.ParentId == group.Id).ToList();
     foreach (var child in group.ChildGroups)
     {
         PopulateChildren(child, allGroups);
     }
 }
Ejemplo n.º 3
0
 private void PopulateStructureIds(StructuralGroup root, List <int> ids)
 {
     ids.Add(root.Id);
     if (root.ChildGroups.Any())
     {
         foreach (var child in root.ChildGroups)
         {
             PopulateStructureIds(child, ids);
         }
     }
 }
Ejemplo n.º 4
0
 public static StructuralGroupViewModel FromModel(StructuralGroup model)
 {
     return(new StructuralGroupViewModel {
         Id = model.Id,
         Type = model.Type,
         Name = model.Name,
         ParentId = model.ParentId,
         ParentGroupName = model.Parent == null ? string.Empty : model.Parent.Name,
         TypeDescription = Enum.GetName(typeof(StructuralGroupType), model.Type)
     });
 }
Ejemplo n.º 5
0
        private void CreateStructureFromTable(DataTable table)
        {
            VerifyTableOrThrow(table, new[] { "Name", "Parent" });
            var db = ApplicationContext.DatabaseContext.Database;

            foreach (var row in table.AsEnumerable())
            {
                var parent = row.Field <string>("Parent");
                var isLeaf = int.Parse(row.Field <string>("IsLeaf").Trim());
                var type   = isLeaf == 1 ? StructuralGroupType.Leaf : string.IsNullOrWhiteSpace(parent) ? StructuralGroupType.Root : StructuralGroupType.Intermediate;
                var group  = new StructuralGroup(type, row.Field <string>("Name"));

                if (!string.IsNullOrWhiteSpace(parent))
                {
                    var p = GetStructuralGroupByName(parent);
                    group.Parent   = p;
                    group.ParentId = p.Id;
                }
                db.Insert(group);
            }
        }
Ejemplo n.º 6
0
        public StructuralGroupViewModel InsertGroup(StructuralGroupViewModel viewModel)
        {
            var root = GetRoot();

            if (!viewModel.ValidateNew(root))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var type = root == null ? StructuralGroupType.Root
                : viewModel.TypeDescription == "Class" ? StructuralGroupType.Leaf : StructuralGroupType.Intermediate;

            var model = new StructuralGroup(type, viewModel.Name);

            model.ParentId = viewModel.ParentId;

            using (var structureRepository = new StructureRepository(ApplicationContext.DatabaseContext.Database, ApplicationContext.Services.MemberService))
            {
                structureRepository.Insert(model);
            }

            return(StructuralGroupViewModel.FromModel(model));
        }
Ejemplo n.º 7
0
 public bool ValidateUpdate(StructuralGroup root)
 {
     return(ValidateNew(root) && Id != null);
 }
Ejemplo n.º 8
0
 public bool ValidateNew(StructuralGroup root)
 {
     return(!string.IsNullOrEmpty(Name) && (ParentId > 0 || root == null));
 }