public JsonResult EditResult(Models.DataTableItemModel model) { if (ModelState.ValidateFail()) { return(Json(DealResult.Wrong(ModelState.ValidateMessage()))); } var data = GetDataSource().FirstOrDefault(o => o.Id == model.Id); if (data != null) { model.MapTo(data); model.DealUpload((file) => { data.File = FileLocation.Create(file.FileName, file.ContentType, ""); }, () => { data.File = null; }, o => o.File); model.DealUpload((file) => { data.Files.Add(FileLocation.Create(file.FileName, file.ContentType, "")); }, (index) => { data.Files.RemoveAt(index); }, o => o.Files); } return(Json(DealResult.Refresh())); }
public JsonResult Create(int parentId, Models.DataTableItemModel model) { if (ModelState.ValidateFail()) { return(Json(DealResult.Wrong(ModelState.ValidateMessage()))); } var data = new Models.DataTableItemModel(); model.MapTo(data); if (GetDataSource(parentId).Count == 0) { data.Id = 1; } else { data.Id = GetDataSource(parentId).Max(o => o.Id) + 1; } model.DealUpload((file) => { data.File = FileLocation.Create(file.FileName, file.ContentType, ""); }, o => o.File); data.Files = new List <HttpPostedFileBase>(); model.DealUpload((file) => { data.Files.Add(FileLocation.Create(file.FileName, file.ContentType, "")); }, o => o.Files); GetDataSource(parentId).Insert(0, data); return(Json(DealResult.Refresh("添加成功"))); }