public static async Task <OperationResult> AdjustUserRoleLevel(string adminId, string uid, int rid, int del) { OperationResult OpResult = new OperationResult(); var maxp = await MemberAdminContext.GetMaxPriority(adminId); var cntx = Cntx; UserServiceProxy usvc = new UserServiceProxy(); var u = usvc.LoadEntityByKey(cntx, uid); if (u == null) { OpResult.Result = new { ok = false, msg = string.Format(ResourceUtils.GetString("b66098049404e4de1356242e8aa6444a", "User \"{0}\" is not found."), uid) }; return(OpResult); } UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy(); var uir = await uirsvc.LoadEntityByKeyAsync(cntx, rid, u.ID); if (uir == null) { OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("78257cace857db766d54e6568d7f912b", "The user is not in this role.") }; return(OpResult); } uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(cntx, uir); if (maxp.Major < uir.RoleRef.RolePriority || maxp.Major == uir.RoleRef.RolePriority && uir.SubPriority + del > maxp.Major) { OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("5986d63fe301793ee7f5b2134a8f8787", "Modifying more priviledged role is not authorized.") }; return(OpResult); } var oldPrio = uir.SubPriority; uir.SubPriority += del; uir.LastModified = DateTime.UtcNow; uir.AdminID = adminId; await uirsvc.AddOrUpdateEntitiesAsync(cntx, new UsersInRoleSet(), new UsersInRole[] { uir }); uir.UserID = u.ID; uir.RoleID = rid; await AddUserRoleHistory(uir, UserRoleOperations.Modified); UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy(); var memb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, uid); var notice = new SimpleMessage { TypeId = 1, Title = string.Format(ResourceUtils.GetString("54da39696e8014b5ded7a0eaeac1dfc4", "The relative priority of your role: [{0}] is changed from {1} to {2}.", memb.AcceptLanguages), uir.RoleRef.DistinctString, oldPrio, uir.SubPriority), Data = "{ id=\"" + rid + "\", type=\"role\", name=\"" + uir.RoleRef.DistinctString + "\" }" }; OpResult.Result = new { ok = true, msg = "" }; OpResult.notices = new SimpleMessage[] { notice }; return(OpResult); }
public static async Task<OperationResult> AdjustUserRoleLevel(string adminId, string uid, int rid, int del) { OperationResult OpResult = new OperationResult(); var maxp = await MemberAdminContext.GetMaxPriority(adminId); var cntx = Cntx; UserServiceProxy usvc = new UserServiceProxy(); var u = usvc.LoadEntityByKey(cntx, uid); if (u == null) { OpResult.Result = new { ok = false, msg = string.Format(ResourceUtils.GetString("b66098049404e4de1356242e8aa6444a", "User \"{0}\" is not found."), uid) }; return OpResult; } UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy(); var uir = await uirsvc.LoadEntityByKeyAsync(cntx, rid, u.ID); if (uir == null) { OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("78257cace857db766d54e6568d7f912b", "The user is not in this role.") }; return OpResult; } uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(cntx, uir); if (maxp.Major < uir.RoleRef.RolePriority || maxp.Major == uir.RoleRef.RolePriority && uir.SubPriority + del > maxp.Major) { OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("5986d63fe301793ee7f5b2134a8f8787", "Modifying more priviledged role is not authorized.") }; return OpResult; } var oldPrio = uir.SubPriority; uir.SubPriority += del; uir.LastModified = DateTime.UtcNow; uir.AdminID = adminId; await uirsvc.AddOrUpdateEntitiesAsync(cntx, new UsersInRoleSet(), new UsersInRole[] { uir }); uir.UserID = u.ID; uir.RoleID = rid; await AddUserRoleHistory(uir, UserRoleOperations.Modified); UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy(); var memb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, uid); var notice = new SimpleMessage { TypeId = 1, Title = string.Format(ResourceUtils.GetString("54da39696e8014b5ded7a0eaeac1dfc4", "The relative priority of your role: [{0}] is changed from {1} to {2}.", memb.AcceptLanguages), uir.RoleRef.DistinctString, oldPrio, uir.SubPriority), Data = "{ id=\"" + rid + "\", type=\"role\", name=\"" + uir.RoleRef.DistinctString + "\" }" }; OpResult.Result = new { ok = true, msg = "" }; OpResult.notices = new SimpleMessage[] { notice }; return OpResult; }
public static async Task<dynamic> AdjustUserRoleLevel(string adminId, string uid, int rid, int del) { var maxp = await MemberAdminContext.GetMaxPriority(adminId); UserServiceProxy usvc = new UserServiceProxy(); var u = usvc.LoadEntityByKey(Cntx, uid); if (u == null) return new { ok = false, msg = string.Format(ResourceUtils.GetString("b66098049404e4de1356242e8aa6444a", "User \"{0}\" is not found."), uid) }; UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy(); var uir = await uirsvc.LoadEntityByKeyAsync(Cntx, rid, u.ID); if (uir == null) return new { ok = false, msg = ResourceUtils.GetString("78257cace857db766d54e6568d7f912b", "The user is not in this role.") }; uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(Cntx, uir); if (maxp.Major < uir.RoleRef.RolePriority || maxp.Major == uir.RoleRef.RolePriority && uir.SubPriority + del > maxp.Major) return new { ok = false, msg = ResourceUtils.GetString("5986d63fe301793ee7f5b2134a8f8787", "Modifying more priviledged role is not authorized.") }; uir.SubPriority += del; uir.LastModified = DateTime.UtcNow; uir.AdminID = adminId; await uirsvc.AddOrUpdateEntitiesAsync(Cntx, new UsersInRoleSet(), new UsersInRole[] { uir }); uir.UserID = u.ID; uir.RoleID = rid; await AddUserRoleHistory(uir, UserRoleOperations.Modified); return new { ok = true, msg = "" }; }