Skip to content

Commit 0c789cd

Browse files
changes
1 parent c9361de commit 0c789cd

File tree

1 file changed

+1
-122
lines changed

1 file changed

+1
-122
lines changed

Complex-databinding/Controllers/HomeController.cs

Lines changed: 1 addition & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -56,128 +56,7 @@ public ActionResult DataSource(DataManagerRequest dm)
5656

5757
}
5858

59-
private void AppendChildren(DataManagerRequest dm, List<TreeData> ChildRecords, TreeData ParentValue, Dictionary<string, List<TreeData>> GroupData, List<TreeData> data) // Getting child records for the respective parent
60-
{
61-
string TaskId = ParentValue.TaskID.ToString();
62-
var index = data.IndexOf(ParentValue);
63-
DataOperations operation = new DataOperations();
64-
foreach (var Child in ChildRecords)
65-
{
66-
//Based on the provided condition, the child records are retained and the value is passed from the server to the client.
67-
if (ParentValue.IsExpanded)
68-
{
69-
string ParentId = Child.ParentValue.ToString();
70-
if (TaskId == ParentId)
71-
{
72-
((IList)data).Insert(++index, Child);
73-
if (GroupData.ContainsKey(Child.TaskID.ToString()))
74-
{
75-
var DeepChildRecords = GroupData[Child.TaskID.ToString()];
76-
if (DeepChildRecords?.Count > 0)
77-
{
78-
if (dm.Sorted != null && dm.Sorted.Count > 0 && dm.Sorted[0].Name != null) // sorting the child records
79-
{
80-
IEnumerable ChildSort = DeepChildRecords;
81-
ChildSort = operation.PerformSorting(ChildSort, dm.Sorted);
82-
DeepChildRecords = new List<TreeData>();
83-
foreach (var rec in ChildSort)
84-
{
85-
DeepChildRecords.Add(rec as TreeData);
86-
}
87-
}
88-
if (dm.Search != null && dm.Search.Count > 0) // searching the child records
89-
{
90-
IEnumerable ChildSearch = DeepChildRecords;
91-
ChildSearch = operation.PerformSearching(ChildSearch, dm.Search);
92-
DeepChildRecords = new List<TreeData>();
93-
foreach (var rec in ChildSearch)
94-
{
95-
DeepChildRecords.Add(rec as TreeData);
96-
}
97-
}
98-
AppendChildren(dm, DeepChildRecords, Child, GroupData, data);
99-
if (Child.IsExpanded)
100-
{
101-
index += DeepChildRecords.Count;
102-
}
103-
}
104-
}
105-
}
106-
}
107-
}
108-
109-
}
110-
111-
public ActionResult Update(CRUDModel<TreeData> value)
112-
{
113-
List<TreeData> data = new List<TreeData>();
114-
data = TreeData.GetTree();
115-
var val = data.Where(ds => ds.TaskID == value.Value.TaskID).FirstOrDefault();
116-
val.TaskName = value.Value.TaskName;
117-
val.Duration = value.Value.Duration;
118-
return Json(val);
119-
}
120-
121-
public ActionResult Insert(CRUDModel<TreeData> value)
122-
{
123-
var c = 0;
124-
for (; c < TreeData.GetTree().Count; c++)
125-
{
126-
if (TreeData.GetTree()[c].TaskID == value.RelationalKey)
127-
{
128-
if (TreeData.GetTree()[c].isParent == null)
129-
{
130-
TreeData.GetTree()[c].isParent = true;
131-
}
132-
break;
133-
}
134-
}
135-
c += FindChildRecords(value.RelationalKey);
136-
TreeData.GetTree().Insert(c + 1, value.Value);
137-
138-
return Json(value.Value);
139-
}
140-
141-
public int FindChildRecords(int? id)
142-
{
143-
var count = 0;
144-
for (var i = 0; i < TreeData.GetTree().Count; i++)
145-
{
146-
if (TreeData.GetTree()[i].ParentValue == id)
147-
{
148-
count++;
149-
count += FindChildRecords(TreeData.GetTree()[i].TaskID);
150-
}
151-
}
152-
return count;
153-
}
154-
155-
public object Delete(CRUDModel<TreeData> value)
156-
{
157-
if (value.deleted != null)
158-
{
159-
for (var i = 0; i < value.deleted.Count; i++)
160-
{
161-
TreeData.GetTree().Remove(TreeData.GetTree().Where(ds => ds.TaskID == value.deleted[i].TaskID).FirstOrDefault());
162-
}
163-
}
164-
else
165-
{
166-
TreeData.GetTree().Remove(TreeData.GetTree().Where(or => or.TaskID == int.Parse(value.Key.ToString())).FirstOrDefault());
167-
}
168-
return Json(value);
169-
}
170-
171-
public class CRUDModel<T> where T : class
172-
{
173-
174-
public TreeData Value;
175-
public int Key { get; set; }
176-
public int RelationalKey { get; set; }
177-
public List<T> added { get; set; }
178-
public List<T> changed { get; set; }
179-
public List<T> deleted { get; set; }
180-
}
59+
18160
public class TaskDetails
18261
{
18362
public string Name { get; set; }

0 commit comments

Comments
 (0)