public ActionResult OnPostGridUpdateUserInfo([C1JsonRequest] CollectionViewEditRequest <UserInfo> requestData) { return(JsonConvertHelper.C1Json(CollectionViewHelper.Edit <UserInfo>(requestData, item => { string error = string.Empty; bool success = true; try { var resultItem = Users.Find(u => u.Id == item.Id); var index = Users.IndexOf(resultItem); Users.Remove(resultItem); Users.Insert(index, item); } catch (Exception e) { error = e.Message; success = false; } return new CollectionViewItemResult <UserInfo> { Error = error, Success = success, Data = item }; }, () => Users))); }
public ActionResult OnPostBind([C1JsonRequest] CollectionViewRequest <Sale> requestData) { var extraData = requestData.ExtraRequestData .ToDictionary(kvp => kvp.Key, kvp => new StringValues(kvp.Value.ToString())); var data = new FormCollection(extraData); _gridDataModel.LoadPostData(data); var model = Sale.GetData(Convert.ToInt32(_gridDataModel.Options["items"].CurrentValue)); return(JsonConvertHelper.C1Json(CollectionViewHelper.Read(requestData, model))); }
public ActionResult OnPostGridCreateUserInfo([C1JsonRequest] CollectionViewEditRequest <UserInfo> requestData) { return(JsonConvertHelper.C1Json(CollectionViewHelper.Edit <UserInfo>(requestData, item => { string error = string.Empty; bool success = true; try { Users.Add(item); item.Id = Users.Max(u => u.Id) + 1; } catch (Exception e) { error = e.Message; success = false; } return new CollectionViewItemResult <UserInfo> { Error = error, Success = success, Data = item }; }, () => Users))); }
public ActionResult OnPostGridBatchEdit([C1JsonRequest] CollectionViewBatchEditRequest <Category> requestData) { return(JsonConvertHelper.C1Json(CollectionViewHelper.BatchEdit(requestData, batchData => { var itemresults = new List <CollectionViewItemResult <Category> >(); string error = string.Empty; bool success = true; try { if (batchData.ItemsCreated != null) { batchData.ItemsCreated.ToList().ForEach(st => { st.CategoryID = _categories.Count == 0 ? 1 : _categories.Max(c => c.CategoryID) + 1; _categories.Add(st); itemresults.Add(new CollectionViewItemResult <Category> { Error = "", Success = success, Data = st }); }); } if (batchData.ItemsDeleted != null) { batchData.ItemsDeleted.ToList().ForEach(category => { var removeItemIndex = _categories.FindIndex(c => c.CategoryID == category.CategoryID); _categories.RemoveAt(removeItemIndex); itemresults.Add(new CollectionViewItemResult <Category> { Error = "", Success = success, Data = category }); }); } if (batchData.ItemsUpdated != null) { batchData.ItemsUpdated.ToList().ForEach(category => { var updateItem = _categories.Find(c => c.CategoryID == category.CategoryID); updateItem.CategoryName = category.CategoryName; updateItem.Description = category.Description; itemresults.Add(new CollectionViewItemResult <Category> { Error = "", Success = success, Data = category }); }); } } catch (Exception e) { error = e.Message; success = false; } return new CollectionViewResponse <Category> { Error = error, Success = success, OperatedItemResults = itemresults }; }, () => _categories))); }
public ActionResult OnPostBatchEditing_Bind([C1JsonRequest] CollectionViewRequest <Category> requestData) { return(JsonConvertHelper.C1Json(CollectionViewHelper.Read(requestData, _categories))); }