public IActionResult Post([FromBody] RoleCreation role)
        {
            if (role == null)
            {
                return(BadRequest());
            }
            if (role.Name == "管理员")
            {
                ModelState.AddModelError("Name", "角色名称不能是管理员!");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var maxId   = UserinfoService.Current.Roles.Max(x => x.Id);
            var newRole = new Role
            {
                Id   = ++maxId,
                Name = role.Name,
                Des  = role.Des,
            };

            UserinfoService.Current.Roles.Add(newRole);
            return(CreatedAtRoute("GetRole", new { id = newRole.Id }, newRole));
        }
Example #2
0
        public async Task Populate()
        {
            if (!(await InstanceCheck() && await OperatorCheck(Context.Message.Author.Id)))
            {
                return;
            }

            await RoleCreation.CreateMissingRoles(Context.Guild);
        }
Example #3
0
 /*Role*/
 public static Role VersRole(this RoleCreation e)
 {
     if (e == null)
     {
         return(null);
     }
     return(new Role {
         description = e.description, nom = e.nom
     });
 }
        public async Task <Message> PostRole([FromBody] Dictionary <string, object> dictionary)
        {
            if (!dictionary.ContainsKey("role") || !dictionary.ContainsKey("roleModuleIdString"))
            {
                return(Message.Fail().Add("content", "参数错误"));
            }
            JObject      jrole              = (JObject)dictionary["role"];
            RoleCreation roleCreation       = jrole.ToObject <RoleCreation>();
            string       roleModuleIdString = (string)dictionary["roleModuleIdString"];

            var dbitem = await _roleRepository.GetSingleAsync(x => x.RoleName == roleCreation.RoleName);

            if (dbitem != null)
            {
                return(Message.Fail().Add("content", "角色名已存在"));
            }

            string roleid = roleCreation.RoleId = Method.GetGuid32();

            if (string.IsNullOrEmpty(roleCreation.ParentRoleId))
            {
                roleCreation.ParentRoleId = "0";
            }
            if (string.IsNullOrEmpty(roleCreation.RoleLevel.ToString()))
            {
                roleCreation.RoleLevel = 0;
            }
            roleCreation.RoleStatus   = "1";
            roleCreation.RoleOrderNum = await _roleRepository.CountAsync() + 1;

            string[]            moduleIds   = roleModuleIdString.Split('_');
            List <TbRoleModule> roleModules = new List <TbRoleModule>();

            foreach (string moduleid in moduleIds)
            {
                roleModules.Add(new TbRoleModule()
                {
                    RoleModuleId = Method.GetGuid32(), RoleId = roleid, ModuleId = moduleid
                });
            }
            var newItem = _mapper.Map <TbRole>(roleCreation);

            _roleRepository.Add(newItem);
            _roleModuleRepository.AddRange(roleModules);
            if (!await _unitOfWork.SaveAsync())
            {
                return(Message.ServerError());
            }
            return(Message.Ok());
        }
Example #5
0
        public ActionResult Creer(RoleCreation e)
        {
            if (ModelState.IsValid)
            {
                RoleServiceAPI rsa = new RoleServiceAPI();

                int i = rsa.Creer(e.VersRole());
                if (i > 0)
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(e));
        }
Example #6
0
        public async Task <IActionResult> PostRole([FromBody] RoleCreation roleCreation)
        {
            if (roleCreation == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newItem = _mapper.Map <Role>(roleCreation);

            _roleRepository.Add(newItem);
            if (!await _unitOfWork.SaveAsync())
            {
                return(StatusCode(500, "添加角色出错"));
            }
            return(Ok());
        }
Example #7
0
        public ActionResult Creer()
        {
            RoleCreation r = new RoleCreation();

            return(View(r));
        }