Beispiel #1
0
        public IActionResult ModuleDetail(int id, int pid = 0)
        {
            var data  = new RBAC.Module();
            var model = new Model <RBAC.Module, int>(data, pid);

            if (id > 0)
            {
                model.Data = DefaultStorage.ModuleGet(id);
            }
            return(PartialView(model));
        }
Beispiel #2
0
 ///<summary>
 /// 模块 更新
 ///</summary>
 ///<param name="o">Module</param>
 ///<returns></returns>
 public bool ModuleUpdate(RBAC.Module o)
 {
     return(Try(nameof(ModuleUpdate), () =>
     {
         var cmd = SqlBuilder.Update("Module")
                   .Column("Name", o.Name)
                   .Column("Icon", o.Icon ?? string.Empty)
                   .Column("Link", o.Link ?? string.Empty)
                   .Column("Priority", o.Priority)
                   .Column("Status", o.Status)
                   .Where("Id=@id", new { o.Id })
                   .ToCommand();
         return RbacConn.Execute(cmd) > 0;
     }));
 }
Beispiel #3
0
 ///<summary>
 /// 模块 创建
 ///</summary>
 ///<param name="o">Module</param>
 ///<returns></returns>
 public int ModuleCreate(RBAC.Module o)
 {
     return(Try(nameof(ModuleCreate), () =>
     {
         var cmd = SqlBuilder.Insert("Module")
                   .Column("Pid", o.Pid)
                   .Column("Name", o.Name)
                   .Column("Path", o.Path ?? string.Empty)
                   .Column("Icon", o.Icon ?? string.Empty)
                   .Column("Link", o.Link ?? string.Empty)
                   .Column("Depth", o.Depth)
                   .Column("Priority", o.Priority)
                   .Column("Status", o.Status)
                   .ToCommand(true);
         return RbacConn.ExecuteScalar <int>(cmd);
     }));
 }
Beispiel #4
0
        public async Task <IActionResult> ModuleDetail(int id, RBAC.Module model, int pid = 0)
        {
            var now = DateTime.Now;

            var result = new Result();

            if (model.Name.IsNullOrEmpty())
            {
                result.Error("请输入名称");
                return(Json(result));
            }

            if (id > 0 && pid == 0)
            {
                var old = DefaultStorage.ModuleGet(id);
                if (old == null)
                {
                    result.Message = "数据不存在";
                    return(Json(result));
                }

                var status = await TryUpdateModelAsync(old);

                if (status)
                {
                    result.Status = DefaultStorage.ModuleUpdate(old);
                    if (!result.Status)
                    {
                        result.Message = "更新失败";
                    }
                }
                else
                {
                    result.Message = "参数有误";
                }
                return(Json(result));
            }

            if (id == 0 && pid == 0)
            {
                result.Message = "参数错误";
                return(Json(result));
            }
            model.Pid = pid;


            var hs = GetParendIds(pid);

            model.Depth = hs.Count + 1;
            model.Path  = string.Join(",", hs);

            var newId = DefaultStorage.ModuleCreate(model);

            if (result.Status = newId > 0)
            {
                hs.Add(newId);//补全path
                var path = string.Join(",", hs);
                DefaultStorage.ModulePathUpdate(newId, path);
                result.Success();
            }

            return(Json(result));
        }