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("添加成功"))); }
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())); }
private void saveLocation_Click(object sender, System.EventArgs e) { if (locations.Items.Count == 0) { var location = FileLocation.Create(friendlyName.Text, watchFolder.Text, copyToFolder.Text, pattern.Text); Settings.Locations.Add(location); } SaveSettings(); }
private static List <Models.DataTableItemModel> GetDataSource() { if (DataSource != null) { return(DataSource); } var list = new List <Models.DataTableItemModel>(); for (var i = 0; i < 100; i++) { var item = new Models.DataTableItemModel { Id = i + 1, Name = "Hello" + (i + 1), Password = "******", Content = "### heading text", States = new List <Models.DataTableItemState>() }; item.States.Add(Models.DataTableItemState.Low); item.States.Add(Models.DataTableItemState.Hight); item.CreateTime = DateTime.UtcNow; item.File = FileLocation.Create("file.jpg", "image/jpg", "https://avatars.githubusercontent.com/u/1279501"); item.Files = new List <HttpPostedFileBase> { FileLocation.Create("file1.jpg", "image/jpg", "https://avatars.githubusercontent.com/u/1279501"), FileLocation.Create("file2.jpg", "image/jpg", "https://avatars.githubusercontent.com/u/1279501") }; if (i == 0) { item.Tags = new List <string> { "hello", "world", "hello" }; } item.Sub = new Models.SubClass() { First = "1", Second = "2" }; list.Add(item); } DataSource = list; return(DataSource); }
public JsonResult IndexDataSource(DataTable.Request request) { var list = new List <Models.TableListModel>(); foreach (var item in DataService.Instance.List()) { var model = new Models.TableListModel { Id = item.Id, Name = item.Name, }; if (item.Avatar != null) { model.Avatar = FileLocation.Create(item.Avatar.Name, item.Avatar.Type, string.Format("/File/Get/{0}", item.Id)); } list.Add(model); } return(Json(DataTable.Source(list, request, list.Count))); }
public IActionResult Change(Guid selectedId) { var data = DataService.Instance.Get(selectedId); if (data == null) { return(new HtmlResult()); } var model = new Models.TableEditModel() { Id = data.Id, Name = data.Name, File = FileLocation.Create(data.Avatar.Name, data.Avatar.Type, string.Format("/File/Get/{0}", data.Id)) }; var form = FormHorizontal.Create(model, Url.Location <Models.TableEditModel>(ChangeResult)); var panel = new Panel(); panel.ConfigLocation(); panel.Append(form); return(new HtmlResult(panel)); }
public ActionResult Show(int id) { var data = GetDataSource().FirstOrDefault(o => o.Id == id); var model = data.MapTo(new Models.ShowModel()); model.Id = data.Id; model.Name = data.Name; model.File = FileLocation.Create("file.jpg", "image/jpg", "https://avatars.githubusercontent.com/u/1279501"); model.Files = new List <HttpPostedFileBase> { FileLocation.Create("file1.jpg", "image/jpg", "https://avatars.githubusercontent.com/u/1279501"), FileLocation.Create("file2.jpg", "image/jpg", "https://avatars.githubusercontent.com/u/1279501") }; var panel = new Panel(); panel.ConfigLocation(); var form = FormHorizontal.Create(model, Url.Location(new Func <Models.ShowModel, JsonResult>(ShowResult)), GetListSource()); panel.Append(form); return(new HtmlResult(panel)); }
private void createNewLocation_Click(object sender, System.EventArgs e) { Settings.Locations.Add(FileLocation.Create("New Location " + locations.Items.Count)); locations.SelectedIndex = locations.Items.Count - 1; }