|
| 1 | +using Microsoft.AspNetCore.Http; |
| 2 | +using Microsoft.AspNetCore.Mvc; |
| 3 | +using System; |
| 4 | +using WalkingTec.Mvvm.Core; |
| 5 | +using WalkingTec.Mvvm.Mvc; |
| 6 | +using WalkingTec.Mvvm.Core.Extensions; |
| 7 | +using WalkingTec.Mvvm.Demo.ViewModels.不要用中文模型名VMs; |
| 8 | + |
| 9 | +namespace WalkingTec.Mvvm.Demo.Controllers |
| 10 | +{ |
| 11 | + |
| 12 | + [ActionDescription("123")] |
| 13 | + public partial class 不要用中文模型名Controller : BaseController |
| 14 | + { |
| 15 | + #region 搜索 |
| 16 | + [ActionDescription("搜索")] |
| 17 | + public ActionResult Index() |
| 18 | + { |
| 19 | + var vm = CreateVM<不要用中文模型名ListVM>(); |
| 20 | + return PartialView(vm); |
| 21 | + } |
| 22 | + |
| 23 | + [ActionDescription("搜索")] |
| 24 | + [HttpPost] |
| 25 | + public string Search(不要用中文模型名ListVM vm) |
| 26 | + { |
| 27 | + return vm.GetJson(false); |
| 28 | + } |
| 29 | + |
| 30 | + #endregion |
| 31 | + |
| 32 | + #region 新建 |
| 33 | + [ActionDescription("新建")] |
| 34 | + public ActionResult Create() |
| 35 | + { |
| 36 | + var vm = CreateVM<不要用中文模型名VM>(); |
| 37 | + return PartialView(vm); |
| 38 | + } |
| 39 | + |
| 40 | + [HttpPost] |
| 41 | + [ActionDescription("新建")] |
| 42 | + public ActionResult Create(不要用中文模型名VM vm) |
| 43 | + { |
| 44 | + if (!ModelState.IsValid) |
| 45 | + { |
| 46 | + return PartialView(vm); |
| 47 | + } |
| 48 | + else |
| 49 | + { |
| 50 | + vm.DoAdd(); |
| 51 | + if (!ModelState.IsValid) |
| 52 | + { |
| 53 | + vm.DoReInit(); |
| 54 | + return PartialView(vm); |
| 55 | + } |
| 56 | + else |
| 57 | + { |
| 58 | + return FFResult().CloseDialog().RefreshGrid(); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + #endregion |
| 63 | + |
| 64 | + #region 修改 |
| 65 | + [ActionDescription("修改")] |
| 66 | + public ActionResult Edit(string id) |
| 67 | + { |
| 68 | + var vm = CreateVM<不要用中文模型名VM>(id); |
| 69 | + return PartialView(vm); |
| 70 | + } |
| 71 | + |
| 72 | + [ActionDescription("修改")] |
| 73 | + [HttpPost] |
| 74 | + [ValidateFormItemOnly] |
| 75 | + public ActionResult Edit(不要用中文模型名VM vm) |
| 76 | + { |
| 77 | + if (!ModelState.IsValid) |
| 78 | + { |
| 79 | + return PartialView(vm); |
| 80 | + } |
| 81 | + else |
| 82 | + { |
| 83 | + vm.DoEdit(); |
| 84 | + if (!ModelState.IsValid) |
| 85 | + { |
| 86 | + vm.DoReInit(); |
| 87 | + return PartialView(vm); |
| 88 | + } |
| 89 | + else |
| 90 | + { |
| 91 | + return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID); |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + #endregion |
| 96 | + |
| 97 | + #region 删除 |
| 98 | + [ActionDescription("删除")] |
| 99 | + public ActionResult Delete(string id) |
| 100 | + { |
| 101 | + var vm = CreateVM<不要用中文模型名VM>(id); |
| 102 | + return PartialView(vm); |
| 103 | + } |
| 104 | + |
| 105 | + [ActionDescription("删除")] |
| 106 | + [HttpPost] |
| 107 | + public ActionResult Delete(string id, IFormCollection nouse) |
| 108 | + { |
| 109 | + var vm = CreateVM<不要用中文模型名VM>(id); |
| 110 | + vm.DoDelete(); |
| 111 | + if (!ModelState.IsValid) |
| 112 | + { |
| 113 | + return PartialView(vm); |
| 114 | + } |
| 115 | + else |
| 116 | + { |
| 117 | + return FFResult().CloseDialog().RefreshGrid(); |
| 118 | + } |
| 119 | + } |
| 120 | + #endregion |
| 121 | + |
| 122 | + #region 详细 |
| 123 | + [ActionDescription("详细")] |
| 124 | + public ActionResult Details(string id) |
| 125 | + { |
| 126 | + var vm = CreateVM<不要用中文模型名VM>(id); |
| 127 | + return PartialView(vm); |
| 128 | + } |
| 129 | + #endregion |
| 130 | + |
| 131 | + #region 批量修改 |
| 132 | + [HttpPost] |
| 133 | + [ActionDescription("批量修改")] |
| 134 | + public ActionResult BatchEdit(string[] IDs) |
| 135 | + { |
| 136 | + var vm = CreateVM<不要用中文模型名BatchVM>(Ids: IDs); |
| 137 | + return PartialView(vm); |
| 138 | + } |
| 139 | + |
| 140 | + [HttpPost] |
| 141 | + [ActionDescription("批量修改")] |
| 142 | + public ActionResult DoBatchEdit(不要用中文模型名BatchVM vm, IFormCollection nouse) |
| 143 | + { |
| 144 | + if (!ModelState.IsValid || !vm.DoBatchEdit()) |
| 145 | + { |
| 146 | + return PartialView("BatchEdit",vm); |
| 147 | + } |
| 148 | + else |
| 149 | + { |
| 150 | + return FFResult().CloseDialog().RefreshGrid().Alert("操作成功,共有"+vm.Ids.Length+"条数据被修改"); |
| 151 | + } |
| 152 | + } |
| 153 | + #endregion |
| 154 | + |
| 155 | + #region 批量删除 |
| 156 | + [HttpPost] |
| 157 | + [ActionDescription("批量删除")] |
| 158 | + public ActionResult BatchDelete(string[] IDs) |
| 159 | + { |
| 160 | + var vm = CreateVM<不要用中文模型名BatchVM>(Ids: IDs); |
| 161 | + return PartialView(vm); |
| 162 | + } |
| 163 | + |
| 164 | + [HttpPost] |
| 165 | + [ActionDescription("批量删除")] |
| 166 | + public ActionResult DoBatchDelete(不要用中文模型名BatchVM vm, IFormCollection nouse) |
| 167 | + { |
| 168 | + if (!ModelState.IsValid || !vm.DoBatchDelete()) |
| 169 | + { |
| 170 | + return PartialView("BatchDelete",vm); |
| 171 | + } |
| 172 | + else |
| 173 | + { |
| 174 | + return FFResult().CloseDialog().RefreshGrid().Alert("操作成功,共有"+vm.Ids.Length+"条数据被删除"); |
| 175 | + } |
| 176 | + } |
| 177 | + #endregion |
| 178 | + |
| 179 | + #region 导入 |
| 180 | + [ActionDescription("导入")] |
| 181 | + public ActionResult Import() |
| 182 | + { |
| 183 | + var vm = CreateVM<不要用中文模型名ImportVM>(); |
| 184 | + return PartialView(vm); |
| 185 | + } |
| 186 | + |
| 187 | + [HttpPost] |
| 188 | + [ActionDescription("导入")] |
| 189 | + public ActionResult Import(不要用中文模型名ImportVM vm, IFormCollection nouse) |
| 190 | + { |
| 191 | + if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData()) |
| 192 | + { |
| 193 | + return PartialView(vm); |
| 194 | + } |
| 195 | + else |
| 196 | + { |
| 197 | + return FFResult().CloseDialog().RefreshGrid().Alert("成功导入 " + vm.EntityList.Count.ToString() + " 行数据"); |
| 198 | + } |
| 199 | + } |
| 200 | + #endregion |
| 201 | + |
| 202 | + [ActionDescription("导出")] |
| 203 | + [HttpPost] |
| 204 | + public IActionResult ExportExcel(不要用中文模型名ListVM vm) |
| 205 | + { |
| 206 | + vm.SearcherMode = vm.Ids != null && vm.Ids.Count > 0 ? ListVMSearchModeEnum.CheckExport : ListVMSearchModeEnum.Export; |
| 207 | + var data = vm.GenerateExcel(); |
| 208 | + return File(data, "application/vnd.ms-excel", $"Export_不要用中文模型名_{DateTime.Now.ToString("yyyy-MM-dd")}.xls"); |
| 209 | + } |
| 210 | + |
| 211 | + } |
| 212 | +} |
0 commit comments