public JsonResult EditPermissionLine()
        {
            Guid platformGuid = GetPlatformId();

            if (!string.IsNullOrEmpty(Request.Form["Id"]))
            {
                Guid id = Guid.Parse(Request.Form["Id"]);

                using (FlyDbContext ctx = new FlyDbContext())
                {
                    PermissionLine pl = ctx.PermissionLines.Where(o => o.Group.PlatformId == platformGuid && o.Id == id).FirstOrDefault();
                    UpdateModel(pl);
                    ctx.SaveChanges();
                    var PermissionLines = System.Web.HttpContext.Current.Session["PermissionLines"] as List <ViewPermissionLine>;
                    var i = (from t in PermissionLines where t.Id == id select t).Count();
                    if (i > 0)
                    {
                        PermissionParticle.SetPermission();
                    }
                    return(new JsonResult()
                    {
                        Data = new { resultCode = 1, message = "操作完成" }
                    });
                }
            }
            else
            {
                return(new JsonResult()
                {
                    Data = new { resultCode = 0, message = "非法请求" }
                });
            }
        }
        public JsonResult EditPermissionGroup(PermissionGroup pg)
        {
            Guid platformGuid = GetPlatformId();

            if (!string.IsNullOrEmpty(Request.Form["Id"]))
            {
                Guid            id       = Guid.Parse(Request.Form["Id"]);
                PermissionGroup targetpg = DbContext.PermissionGroups.Where(o => o.PlatformId == platformGuid && o.Id == id).FirstOrDefault();
                targetpg.DisplayName = pg.DisplayName;
                targetpg.Tag         = pg.Tag;
                targetpg.Url         = pg.Url;
                targetpg.SN          = pg.SN;
                targetpg.Headshot    = pg.Headshot;
                if (targetpg.Platform.PermissionGroups.Count(p => p.Id == pg.ParentId) > 0 && targetpg.Id != pg.ParentId)
                {
                    if (pg.ParentId == Guid.Empty)
                    {
                        targetpg.ParentId = null;
                    }
                    else
                    {
                        targetpg.ParentId = pg.ParentId;
                    }
                }
                else
                {
                    targetpg.ParentId = null;
                }

                DbContext.SaveChanges();
                var PermissionGroups = System.Web.HttpContext.Current.Session["PermissionGroups"] as List <ViewPermissionGroup>;
                var i = (from t in PermissionGroups where t.Id == targetpg.Id select t).Count();
                if (i > 0)
                {
                    PermissionParticle.SetPermission();
                }
                return(new JsonResult()
                {
                    Data = new { resultCode = 1, message = "操作完成" }
                });
            }
            else
            {
                return(new JsonResult()
                {
                    Data = new { resultCode = 0, message = "非法请求" }
                });
            }
        }
Esempio n. 3
0
        public JsonResult Edit(Role role, List <Guid> permissionlineIds)
        {
            if (role.Id != Guid.Empty)
            {
                Guid platformId = GetPlatformId();
                Role targetRole = DbContext.Roles.Where(p => p.PlatformId == platformId && p.Id == role.Id).FirstOrDefault();
                if (targetRole != null)
                {
                    targetRole.Name            = role.Name;
                    targetRole.CustomAttribute = role.CustomAttribute;
                    targetRole.Remark          = role.Remark;

                    var oldRolePermissions = DbContext.RolePermissions.Where(p => p.RoleId == targetRole.Id);
                    DbContext.RolePermissions.RemoveRange(oldRolePermissions);

                    if (permissionlineIds != null && permissionlineIds.Count > 0)
                    {
                        List <RolePermission> rolePsermissionList = new List <RolePermission>();
                        foreach (Guid pid in permissionlineIds)
                        {
                            rolePsermissionList.Add(new RolePermission()
                            {
                                PermissionLineId = pid, RoleId = role.Id
                            });
                        }
                        DbContext.RolePermissions.AddRange(rolePsermissionList);
                    }
                    DbContext.SaveChanges();
                    if (User.IsInRole(targetRole.Name))
                    {
                        PermissionParticle.SetPermission();
                    }
                }
                return(Json(new { resultCode = 1, message = "操作完成" }));
            }
            else
            {
                return(Json(new { resultCode = 0, message = "非法的请求" }));
            }
        }
        public async Task<JsonResult> Edit(Employee emp, List<Guid> roleIds)
        {

            Employee targetEmp = await UserManager.FindByIdAsync(emp.Id);
            targetEmp.Job = emp.Job;
            targetEmp.Address = emp.Address;
            targetEmp.CustomAttribute = emp.CustomAttribute;
            targetEmp.Email = emp.Email;
            targetEmp.Name = emp.Name;
            targetEmp.OrganizationId = emp.OrganizationId;
            targetEmp.PhoneNumber = emp.PhoneNumber;
            targetEmp.QQ = emp.QQ;
            targetEmp.Remark = emp.Remark;
            targetEmp.Sex = emp.Sex;
            targetEmp.Status = emp.Status;
            targetEmp.ZipCode = emp.ZipCode;
            while (targetEmp.Roles.Count > 0)
            {
                targetEmp.Roles.Remove(targetEmp.Roles.ToList()[0]);
            }
            if (roleIds.Count > 0)
            {
                foreach (var roleId in roleIds)
                {
                    targetEmp.Roles.Add(new EmployeeRole() { RoleId = roleId });
                }
            }
            var result = await UserManager.UpdateAsync(targetEmp);
            if (result.Succeeded)
            {
                if (roleIds.Count > 0 && User.Identity.GetUserId() == targetEmp.Id.ToString())
                    PermissionParticle.SetPermission();
                return Json(new { resultCode = 1, message = "修改成功" });
            }
            else
            {
                return Json(new { resultCode = 0, message = "修改失败" });
            }
        }