コード例 #1
0
        public IHttpActionResult ToggleActivity(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            var applicationRole = applicationRoleRepository.GetApplicationRoleById(id);

            applicationRole.ToggleActivity();
            unitOfWork.Complete();

            return(Ok(applicationRole.Active));
        }
コード例 #2
0
        public IHttpActionResult ChangeRole([FromBody] JObject data)
        {
            var userId = data["userId"].ToString();
            var roleId = data["roleId"].ToString();

            var user      = applicationUserRepository.GetApplicationUserById(userId);
            var role      = applicationRoleRepository.GetApplicationRoleById(roleId);
            var roleNames = userManager.GetRoles(user.Id).ToArray();

            if (roleNames.Count() > 0)
            {
                userManager.RemoveFromRoles(user.Id, roleNames);
            }

            userManager.AddToRole(user.Id, role.Name);
            unitOfWork.Complete();

            return(Ok(role.Name));
        }