public void setCreatureHPandDamage(EntityAbs creature, int damageDemod, int hpDemod) { if (creature.IsDead == false) { creature.hitPoints = hpDemod; creature.Weapon.Damage = hpDemod; } throw new ArgumentException("Creature is dead or doesn't exist"); }
public static async Task <dynamic> CreateNewRole(string adminId, string name, int priority, int?pid) { var maxp = await MemberAdminContext.GetMaxPriority(adminId); if (maxp.Major < priority) { return new { ok = false, msg = string.Format(ResourceUtils.GetString("0452f93e5e52c7eae26c4fac7aa2d5d7", "Denined! Your role priority: {0} is less than the requested one."), maxp.Major), role = new { } } } ; RoleServiceProxy rsvc = new RoleServiceProxy(); if (pid != null) { var prole = await rsvc.LoadEntityByKeyAsync(Cntx, pid.Value); if (prole.RolePriority >= priority) { return new { ok = false, msg = string.Format(ResourceUtils.GetString("b1ac4f163f802b8cb0c9216a2845c96b", "Denined! The role priority: {0} is less than or equals to the one for the parent role."), priority), role = new { } } } ; } Role r = new Role { RoleName = name, RolePriority = priority, ApplicationID = ApplicationContext.App.ID, DisplayName = name, ParentID = pid }; var result = await rsvc.AddOrUpdateEntitiesAsync(Cntx, new RoleSet(), new Role[] { r }); if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Added) > 0) { var rabs = new EntityAbs <Role>(result.ChangedEntities[0].UpdatedItem); rabs.ParentExists = pid != null; return(new { ok = true, msg = "", role = MakeJsonRole(rabs, maxp) }); } else { if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Duplication) > 0) { return new { ok = false, msg = ResourceUtils.GetString("a1794e1f262706c9409389bcfcff7499", "An existing role with the same name exists!"), role = new { } } } ; else { return new { ok = false, msg = ResourceUtils.GetString("aa1d969415687af8bf4e3ba5e4e3bc14", "Add failed, try again?"), role = new { } } }; } }
internal static dynamic MakeJsonRole(EntityAbs <Role> rabs, RolePriority admMax) { return(new { id = rabs.DataBehind.ID, name = rabs.DataBehind.RoleName, path = Utils.GetHtmlRolePath(rabs.DataBehind.DistinctString), priority = rabs.DataBehind.RolePriority, hasParents = rabs.ParentExists, hasChilds = rabs.ChildExists, childsLoaded = rabs.IsChildsLoaded, pid = rabs.DataBehind.ParentID == null ? new Nullable <int>() : rabs.DataBehind.ParentID, op = admMax.Major >= rabs.DataBehind.RolePriority }); }
private Role findMatch(EntityAbs <Role> ra, string[] path, int lev, ref Role last) { if (ra.ChildEntities != null) { foreach (var c in ra.ChildEntities) { if (c.DataBehind.RoleName == path[lev]) { c.DataBehind.UpperRef = last; last = c.DataBehind; if (lev == path.Length - 1) { return(c.DataBehind); } else { return(findMatch(c, path, lev + 1, ref last)); } } } } return(null); }
private async Task _getUserInRoleAsync(CallContext cctx, EntityAbs <Role> ra, List <string> usersinrole) { UserServiceProxy usvc = new UserServiceProxy(); QueryExpresion qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "Username" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "UsersInRole." }, new QToken { TkName = "RoleID" }, new QToken { TkName = "==" }, new QToken { TkName = "" + ra.DataBehind.ID + "" } }); var users = await usvc.QueryDatabaseAsync(cctx, new UserSet(), qexpr); foreach (User u in users) { usersinrole.Add(u.Username); } if (ra.ChildEntities != null) { foreach (var c in ra.ChildEntities) { await _getUserInRoleAsync(cctx, c, usersinrole); } } }
public static async Task<dynamic> UpdateRole(string adminId, int id, int priority, int? pid) { var maxp = await MemberAdminContext.GetMaxPriority(adminId); if (maxp.Major < priority) return new { ok = false, msg = string.Format(ResourceUtils.GetString("0452f93e5e52c7eae26c4fac7aa2d5d7", "Denined! Your role priority: {0} is less than the requested one."), maxp.Major), role = new { } }; RoleServiceProxy rsvc = new RoleServiceProxy(); if (pid != null) { var prole = await rsvc.LoadEntityByKeyAsync(Cntx, pid.Value); if (prole.RolePriority >= priority) return new { ok = false, msg = string.Format(ResourceUtils.GetString("b1ac4f163f802b8cb0c9216a2845c96b", "Denined! The role priority: {0} is less than or equals to the one for the parent role."), priority), role = new { } }; } var r = await rsvc.LoadEntityByKeyAsync(Cntx, id); if (r == null) return new { ok = false, msg = ResourceUtils.GetString("2dcb0c4ea3d378571beac6927e1a4a99", "The role is not found!") }; if (r.RolePriority == priority) return new { ok = true, msg = "" }; var _r = await rsvc.LoadEntityHierarchyRecursAsync(Cntx, r, 0, -1); if (_r.ChildEntities != null) { if (!checkRolePrior(priority, _r.ChildEntities)) return new { ok = false, msg = string.Format(ResourceUtils.GetString("680d7ee4f668b8eac69d8153e3e25293", "The attempted role priority: {0} is greater than or equals to one of child role priorities."), priority) }; } r.RolePriority = priority; var result = await rsvc.AddOrUpdateEntitiesAsync(Cntx, new RoleSet(), new Role[] { r }); if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Updated) > 0) { var rabs = new EntityAbs<Role>(result.ChangedEntities[0].UpdatedItem); rabs.ParentExists = pid != null; return new { ok = true, msg = "" }; } else { if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Duplication) > 0) return new { ok = false, msg = ResourceUtils.GetString("a1794e1f262706c9409389bcfcff7499", "An existing role with the same name exists!"), role = new { } }; else return new { ok = false, msg = ResourceUtils.GetString("a91c35ceb071295cf0c07ef4acc9424e", "Update failed, try again?") }; } }
public static async Task<dynamic> CreateNewRole(string adminId, string name, int priority, int? pid) { var maxp = await MemberAdminContext.GetMaxPriority(adminId); if (maxp.Major < priority) return new { ok = false, msg = string.Format(ResourceUtils.GetString("0452f93e5e52c7eae26c4fac7aa2d5d7", "Denined! Your role priority: {0} is less than the requested one."), maxp.Major), role = new { } }; RoleServiceProxy rsvc = new RoleServiceProxy(); if (pid != null) { var prole = await rsvc.LoadEntityByKeyAsync(Cntx, pid.Value); if (prole.RolePriority >= priority) return new { ok = false, msg = string.Format(ResourceUtils.GetString("b1ac4f163f802b8cb0c9216a2845c96b", "Denined! The role priority: {0} is less than or equals to the one for the parent role."), priority), role = new { } }; } Role r = new Role { RoleName = name, RolePriority = priority, ApplicationID = ApplicationContext.App.ID, DisplayName = name, ParentID = pid }; var result = await rsvc.AddOrUpdateEntitiesAsync(Cntx, new RoleSet(), new Role[] { r }); if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Added) > 0) { var rabs = new EntityAbs<Role>(result.ChangedEntities[0].UpdatedItem); rabs.ParentExists = pid != null; return new { ok = true, msg = "", role = MakeJsonRole(rabs, maxp) }; } else { if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Duplication) > 0) return new { ok = false, msg = ResourceUtils.GetString("a1794e1f262706c9409389bcfcff7499", "An existing role with the same name exists!"), role = new { } }; else return new { ok = false, msg = ResourceUtils.GetString("aa1d969415687af8bf4e3ba5e4e3bc14", "Add failed, try again?"), role = new { } }; } }
internal static dynamic MakeJsonRole(EntityAbs<Role> rabs, RolePriority admMax) { return new { id = rabs.DataBehind.ID, name = rabs.DataBehind.RoleName, path = Utils.GetHtmlRolePath(rabs.DataBehind.DistinctString), priority = rabs.DataBehind.RolePriority, hasParents = rabs.ParentExists, hasChilds = rabs.ChildExists, childsLoaded = rabs.IsChildsLoaded, pid = rabs.DataBehind.ParentID == null ? new Nullable<int>() : rabs.DataBehind.ParentID, op = admMax.Major >= rabs.DataBehind.RolePriority }; }
public static async Task <dynamic> UpdateRole(string adminId, int id, int priority, int?pid) { var maxp = await MemberAdminContext.GetMaxPriority(adminId); if (maxp.Major < priority) { return new { ok = false, msg = string.Format(ResourceUtils.GetString("0452f93e5e52c7eae26c4fac7aa2d5d7", "Denined! Your role priority: {0} is less than the requested one."), maxp.Major), role = new { } } } ; RoleServiceProxy rsvc = new RoleServiceProxy(); if (pid != null) { var prole = await rsvc.LoadEntityByKeyAsync(Cntx, pid.Value); if (prole.RolePriority >= priority) { return new { ok = false, msg = string.Format(ResourceUtils.GetString("b1ac4f163f802b8cb0c9216a2845c96b", "Denined! The role priority: {0} is less than or equals to the one for the parent role."), priority), role = new { } } } ; } var r = await rsvc.LoadEntityByKeyAsync(Cntx, id); if (r == null) { return new { ok = false, msg = ResourceUtils.GetString("2dcb0c4ea3d378571beac6927e1a4a99", "The role is not found!") } } ; if (r.RolePriority == priority) { return new { ok = true, msg = "" } } ; var _r = await rsvc.LoadEntityHierarchyRecursAsync(Cntx, r, 0, -1); if (_r.ChildEntities != null) { if (!checkRolePrior(priority, _r.ChildEntities)) { return new { ok = false, msg = string.Format(ResourceUtils.GetString("680d7ee4f668b8eac69d8153e3e25293", "The attempted role priority: {0} is greater than or equals to one of child role priorities."), priority) } } ; } r.RolePriority = priority; var result = await rsvc.AddOrUpdateEntitiesAsync(Cntx, new RoleSet(), new Role[] { r }); if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Updated) > 0) { var rabs = new EntityAbs <Role>(result.ChangedEntities[0].UpdatedItem); rabs.ParentExists = pid != null; return(new { ok = true, msg = "" }); } else { if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Duplication) > 0) { return new { ok = false, msg = ResourceUtils.GetString("a1794e1f262706c9409389bcfcff7499", "An existing role with the same name exists!"), role = new { } } } ; else { return new { ok = false, msg = ResourceUtils.GetString("a91c35ceb071295cf0c07ef4acc9424e", "Update failed, try again?") } }; } }
private static async Task _groupMembersRecurs(string hubId, CallContext cntx, EntityAbs <UserGroup> g, List <MemberCallback> callbacks, bool drillDown = false) { MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); var qexpr = getConnectedGroupMemberFilter(hubId, g.DataBehind.ID); var list = await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr); if (list.Count() > 0) { callbacks.AddRange(list); } if (drillDown && g.ChildEntities != null) { foreach (var c in g.ChildEntities) { await _groupMembersRecurs(hubId, cntx, c, callbacks); } } }
private static async Task _groupMembersRecurs(string hubId, CallContext cntx, EntityAbs<UserGroup> g, List<MemberCallback> callbacks, bool drillDown = false) { MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); var qexpr = getConnectedGroupMemberFilter(hubId, g.DataBehind.ID); var list = await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr); if (list.Count() > 0) { callbacks.AddRange(list); } if (drillDown && g.ChildEntities != null) { foreach (var c in g.ChildEntities) await _groupMembersRecurs(hubId, cntx, c, callbacks); } }