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); }
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); } }
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); } } }
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) }); }
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); } }
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)); }
public bool ValidateUpdate(StructuralGroup root) { return(ValidateNew(root) && Id != null); }
public bool ValidateNew(StructuralGroup root) { return(!string.IsNullOrEmpty(Name) && (ParentId > 0 || root == null)); }