public async Task <ApiResult> Insert(ModuleReq req) { if (req == null) { return(Error("请求参数不能为空")); } var treePath = await GetPathByParentId(req.ParentId); SysModule module = new SysModule { Name = req.Name, ParentId = req.ParentId, ParentName = req.ParentName, TreePath = treePath, Url = req.Url, IsLeaf = req.IsLeaf, IsAutoExpand = req.IsAutoExpand, Icon = req.Icon, Component = req.Component, FuncPermission = req.FuncPermission, Sort = req.Sort, Remark = req.Remark, CreateBy = CurrentUser.UserId }; var res = await _sysModuleService.InsertAsync(module); if (res > 0) { return(Success("添加成功")); } return(Success("添加失败")); }
public async Task <ApiResult> Update(ModuleReq req) { if (req == null) { return(Error("请求参数不能为空")); } if (req.Id == 0) { return(await Insert(req)); } var model = await _sysModuleService.GetByIdAsync(req.Id); if (model == null) { return(Error("请求参数传递错误")); } var treePath = await GetPathByParentId(req.ParentId); model.Name = req.Name; model.ParentId = req.ParentId; model.ParentName = req.ParentName; model.TreePath = treePath; model.Url = req.Url; model.IsLeaf = req.IsLeaf; model.IsAutoExpand = req.IsAutoExpand; model.Icon = req.Icon; model.Component = req.Component; model.FuncPermission = req.FuncPermission; model.Sort = req.Sort; model.Remark = req.Remark; model.UpdateBy = CurrentUser.UserId; model.UpdateTime = DateTime.Now; var res = await _sysModuleService.UpdateAsync(model); if (res > 0) { return(Success("更新成功")); } return(Success("更新失败")); }