Example #1
0
        public async Task <ActionResult> Update([FromBody] SysRoleView model)
        {
            var resdata = await AutoException.Excute <SysRole>(async (result) =>
            {
                model.UpdateBy = "admin";
                model.UpdateDt = DateTime.Now;
                var res        = await SysRoleDAL.UpdateAsync(model);
                result.Data    = model;
                if (!res)
                {
                    throw new Exception("数据修改异常,JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model));
                }
                else
                {
                    if (!string.IsNullOrEmpty(model.authids))
                    {
                        string[] idstr = model.authids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        List <SysRoleMenu> rolelist = (from p in idstr
                                                       select new SysRoleMenu
                        {
                            RoleId = model.Id,
                            MenuId = Convert.ToInt32(p),
                            Status = 1,
                            CreateDt = DateTime.Now,
                            CreateBy = model.UpdateBy
                        }).ToList();
                        await SysRoleMenuDAL.BatchInsertAsync(rolelist);
                    }
                }
            }, false);

            return(Json(resdata));
        }
Example #2
0
        public async Task <ActionResult> Auth([FromBody] SysRoleView model)
        {
            var resdata = await AutoException.Excute <SysRole>(async (result) =>
            {
                //删除
                SysRoleMenuDAL.Delete(del => del.RoleId == model.Id);
                SysRoleButtonDAL.Delete(del => del.RoleId == model.Id);

                if (!string.IsNullOrEmpty(model.authids))
                {
                    string[] idstr = model.authids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    List <SysRoleMenu> rolelist = (from p in idstr
                                                   select new SysRoleMenu
                    {
                        RoleId = model.Id,
                        MenuId = Convert.ToInt32(p),
                        Status = 1,
                        CreateDt = DateTime.Now,
                        CreateBy = model.UpdateBy
                    }).ToList();
                    await SysRoleMenuDAL.BatchInsertAsync(rolelist);

                    string[] btnids = model.btnids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    List <SysRoleButton> btnlist = (from p in btnids
                                                    select new SysRoleButton
                    {
                        RoleId = model.Id,
                        ButtonId = Convert.ToInt32(p),
                        Status = 1,
                        CreateDt = DateTime.Now,
                        CreateBy = model.UpdateBy
                    }).ToList();
                    await SysRoleButtonDAL.BatchInsertAsync(btnlist);
                }
            }, false);

            return(Json(resdata));
        }