public ActionResult Create(Area area, string nextStep) { if (ModelState.IsValid) { db.Area.Add(area); db.SaveChanges(); return Redirect(nextStep); } ViewBag.ParentId = new SelectList(db.Area, "Id", "Name", area.ParentId); CreateFrame(title); return View(area); }
public static Node<Area> CreateTree(Area[] areas, Area current) { Dictionary<int, Node<Area>> lookup = new Dictionary<int, Node<Area>>(); Dictionary<int?, List<Node<Area>>> children = new Dictionary<int?, List<Node<Area>>>(); List<Node<Area>> roots = new List<Node<Area>>(); foreach (var area in areas) { Node<Area> node = new Node<Area>(); node.Data = area; node.Children = new List<Node<Area>>(); lookup.Add(area.Id, node); if (area.ParentId != null) { if (!children.ContainsKey(area.ParentId)) { children[area.ParentId] = new List<Node<Area>>(); } children[area.ParentId].Add(node); } if (area.ParentId == null) { node.Parent = null; roots.Add(node); } } foreach (var node in lookup.Values) { var area = node.Data; Node<Area> parent = null; if (area.ParentId != null) { parent = lookup[(int)area.ParentId]; } node.Parent = parent; if (children.ContainsKey(area.Id)) { node.Children = children[area.Id]; } } return lookup[current.Id]; }
public ActionResult Edit(Area area, string nextStep) { if (ModelState.IsValid) { db.Entry(area).State = EntityState.Modified; db.SaveChanges(); return Redirect(nextStep); } ViewBag.ParentId = new SelectList(db.Area, "Id", "Name", area.ParentId); return View(area); }