Beispiel #1
0
 public async Task <ActionResult> AddRole(Models.RoleViewModel model)
 {
     if (ModelState.IsValid)
     {
         string[]      names        = model.Name.Trim().Split(';', ';');
         IAdminManager adminManager = new AdminManager();
         try
         {
             if (names.Length > 1)
             {
                 await adminManager.AddGroupRole(names);
             }
             else
             {
                 await adminManager.AddRole(model.Name);
             }
         }
         catch (Exception)
         {
             return(Content("<script>alert('操作失败!');history.go(-1);</script>"));
         }
         return(Content("<script>alert('操作成功!');history.go(-1);</script>"));
     }
     else
     {
         return(Content("<script>alert('操作失败!');history.go(-1);</script>"));
     }
 }
Beispiel #2
0
        public async Task <IHttpActionResult> Post([FromBody] Models.RoleViewModel value)
        {
            Role _role = null;

            if (NullHandlers.NGUID(value.Id) != Guid.Empty)
            {
                _role = await UnitOfWork.RoleStore.FindByIdAsync(value.Id);
            }
            if (_role == null)
            {
                _role = new Role();
            }
            _role.Name        = value.RoleName;
            _role.Description = value.RoleDescription;
            UnitOfWork.BeginWork();
            if (_role.Id == Guid.Empty)
            {
                await UnitOfWork.RoleStore.CreateAsync(_role);
            }
            else
            {
                await UnitOfWork.RoleStore.UpdateAsync(_role);
            }
            foreach (Models.ApiViewModel _assignedApi in value.AssignedApis)
            {
                if (_assignedApi.Id == Guid.Empty)
                {
                    RoleApiPath _newPath = new RoleApiPath()
                    {
                        RoleId = _role.Id, ActionPath = _assignedApi.Path, ActionMethod = _assignedApi.HttpMethod
                    };
                    await UnitOfWork.RoleStore.CreateRoleApiPathAsync(_newPath);
                }
            }
            foreach (Models.ApiViewModel _availableApi in value.AvailableApis)
            {
                if (_availableApi.Id != Guid.Empty)
                {
                    await UnitOfWork.RoleStore.DeleteRoleApiPathAsync(_availableApi.Id);;
                }
            }
            foreach (Models.ClientPathViewModel _assignedClientPath in value.AssignedClientPaths)
            {
                if (_assignedClientPath.Id == Guid.Empty)
                {
                }
            }
            foreach (Models.ClientPathViewModel _availableClientPath in value.AvailableClientPaths)
            {
                if (_availableClientPath.Id != Guid.Empty)
                {
                }
            }
            UnitOfWork.CommitWork();
            return(Ok());
        }
Beispiel #3
0
 public RoleViewModel GetRoleByID(int id)
 {
     using (SATEntities db = new SATEntities())
     {
         var           data  = db.tb_Role.Where(x => x.RoleID == id).FirstOrDefault();
         RoleViewModel model = new Models.RoleViewModel();
         model.RoleID     = data.RoleID;
         model.RoleName   = data.RoleName;
         model.RoleDesc   = data.RoleDesc;
         model.RoleStatus = data.RoleStatus;
         return(model);
     }
 }