- Timestamp:
- 05/09/11 22:13:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Controllers/FilterController.cs
r6163 r6170 35 35 } 36 36 37 38 37 39 public ActionResult Filters(CombinedFilter f) 38 40 { … … 50 52 /// <returns></returns> 51 53 public ActionResult AddFilterAnd(FormCollection collection) 52 { 53 Response.Write("AddFilterAnd"); 54 55 CombinedFilter content = (CombinedFilter)Session["Content"]; 56 FilterModel fm = new FilterModel(content); 57 58 59 54 { 55 FilterModel fm = new FilterModel((CombinedFilter)Session["Content"]); 56 57 58 // Add Filter 59 60 60 String idKey = null; 61 61 String parentIdKey = null; … … 63 63 foreach (string key in collection.AllKeys) 64 64 { 65 if (key.StartsWith( "filtersCombobox"))65 if (key.StartsWith(FilterModel.ComboboxName)) 66 66 { 67 67 idKey = key; 68 68 } 69 if (key.StartsWith( "parentId"))69 if (key.StartsWith(FilterModel.ParentIdName)) 70 70 { 71 71 parentIdKey = key; … … 75 75 Guid parentId = new Guid(collection.Get(parentIdKey)); 76 76 string filterTypeName = collection.Get(idKey); 77 78 // get selected filter (combobox) 79 Filter filter = fm.Filters.Where(x => x.FilterTypeName.Equals(filterTypeName)).FirstOrDefault(); 80 81 82 83 // find the partent filterr 84 List<Filter> orFilters = content.Filters.ToList<Filter>(); ; 85 CombinedFilter parent = (CombinedFilter)orFilters.Where(e => e.Id.Equals(parentId)).FirstOrDefault(); 86 87 // remove 88 orFilters.Remove(parent); 89 90 List<Filter> filterList = parent.Filters.ToList<Filter>(); 77 fm.AddFilter(filterTypeName, parentId); 78 91 79 92 80 … … 102 90 { 103 91 104 if (!key.StartsWith( "filtersCombobox") && !key.StartsWith("parentId"))92 if (!key.StartsWith(FilterModel.ComboboxName) && !key.StartsWith(FilterModel.ParentIdName)) 105 93 { 106 94 int idx = key.IndexOf("."); … … 124 112 } 125 113 126 127 // Set values for the existing Filters 128 foreach (Filter f in filterList) 129 { 130 131 Dictionary<string, string> dict = postValues.Where(x => x.Key.Equals(f.Id)).FirstOrDefault().Value; 132 if (dict != null) 133 { 134 foreach (KeyValuePair<string, string> kvp in dict) 135 { 136 if ("StringComparisonFilter".Equals(f.GetType().Name)) 137 { 138 if (kvp.Key.Equals("valueTextbox")) 139 { 140 ((StringComparisonFilter)f).Value = kvp.Value; 141 } 142 143 } 144 else 145 { 146 // To this for all filters 147 } 148 } 149 } 150 151 } 152 153 154 // Add the new filter 155 filterList.Add(filter); 156 Response.Write("addx:" + filter.Id); 157 158 parent.Filters = filterList.ToArray<Filter>(); 159 160 // Add the current filter (AND) 161 orFilters.Add(parent); 162 163 content.Filters = orFilters.ToArray<Filter>(); 164 165 166 167 Response.Write("content add:" + content.Filters[0].Id); 114 // Update filters with posted data 115 fm.UpdateWithPostValues(postValues); 168 116 169 117 170 118 // Set Content 171 Session["Content"] = content;119 Session["Content"] = fm.Content; 172 120 173 121 … … 177 125 178 126 127 128 129 /// <summary> 130 /// Delete a filter with given id. 131 /// </summary> 132 /// <param name="id"></param> 133 /// <returns></returns> 179 134 public ActionResult DeleteFilter(Guid id) 180 135 { 181 //Response.Write("Delete id:" + id); 182 183 CombinedFilter masterFilter = (CombinedFilter)Session["Content"]; 184 185 Response.Write("content del:" + masterFilter.Filters[0].Id); 186 187 FilterModel fm = new FilterModel(masterFilter); 188 RemoveFilterFromFilterModel(fm, id); 189 190 masterFilter.Filters = ((CombinedFilter)fm.Content).Filters.ToArray<Filter>(); 191 136 // Get Content from Session 137 FilterModel fm = new FilterModel((CombinedFilter)Session["Content"]); 138 139 // Remove Filter 140 bool filterRemoved = fm.RemoveFilter(id); 141 192 142 // Set Content 193 Session["Content"] = masterFilter; 194 195 // Response.Write("Delete id3:" + masterFilter.Filters.Length); 143 Session["Content"] = fm.Content; 196 144 197 145 return View("Index", fm); … … 199 147 200 148 201 private Filter GetFilterForId(Filter [] activeFilters, Guid id)202 {203 foreach (Filter f in activeFilters)204 {205 Response.Write(f.Id + " " + id);206 207 if (f.Id.Equals(id))208 {209 return f;210 }211 }212 return null;213 }214 215 private FilterModel RemoveFilterFromFilterModel(FilterModel fm, Guid id)216 {217 Response.Write("content :" + fm.Content.Id);218 Filter filterToRemove = GetFilterForId(fm.Content.Filters, id);219 if (filterToRemove != null)220 {221 Response.Write("rrrrr:" + id);222 fm.Filters.Remove(filterToRemove);223 }224 225 return fm;226 }227 149 228 150 … … 233 155 public ActionResult AddFilterOr() 234 156 { 235 236 237 CombinedFilter content = (CombinedFilter)Session["Content"]; 238 FilterModel fm = new FilterModel(content); 239 240 List<Filter> orFilters = content.Filters.ToList<Filter>(); ; 241 242 CombinedFilter andFilter = fm.Filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault(); 157 FilterModel fm = new FilterModel((CombinedFilter)Session["Content"]); 158 159 List<Filter> orFilters = fm.Content.Filters.ToList<Filter>(); ; 160 161 CombinedFilter andFilter = fm.AvailableFilters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault(); 243 162 orFilters.Add(andFilter); 244 content.Filters = orFilters.ToArray<Filter>();245 246 247 Session["Content"] = content;163 fm.Content.Filters = orFilters.ToArray<Filter>(); 164 165 166 Session["Content"] = fm.Content; 248 167 249 168 return View("Index", fm); … … 272 191 { 273 192 // Add first Filter 274 CombinedFilter orFilter = fm. Filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.Or).FirstOrDefault();275 CombinedFilter andFilter = fm. Filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault();193 CombinedFilter orFilter = fm.AvailableFilters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.Or).FirstOrDefault(); 194 CombinedFilter andFilter = fm.AvailableFilters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault(); 276 195 orFilter.Filters = new Filter[] { andFilter }; // 1st filter 277 196
Note: See TracChangeset
for help on using the changeset viewer.