コード例 #1
0
        public async Task <IActionResult> UpdateRoleAndPermissionAsync(Role_Permission role_Permission)
        {
            try
            {
                //判断传过来的数据是否存在
                if (await dbContext.role_PermissionRepository.IsExistAsync(role_Permission.ConnectionID))
                {
                    //找到这条数据
                    Role_Permission _Permission = await dbContext.role_PermissionRepository.GetFirstInfo(role_Permission.ConnectionID);

                    //修改数据信息
                    _Permission.RoleID       = role_Permission.RoleID;
                    _Permission.PermissionID = role_Permission.PermissionID;
                    //保存当前修改的数据
                    dbContext.role_PermissionRepository.UpdateInfo(_Permission);
                    if (await dbContext.role_PermissionRepository.SaveAsync())
                    {
                        return(Ok(1));
                    }
                }
                _logger.LogInformation($"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}修改角色和菜单信息");
                //如果不存在返回错误信息
                return(NotFound());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #2
0
        public async Task <IActionResult> Add(Role_Permission Role_Permission)
        {
            ResponseHelper objHelper = new ResponseHelper();

            if (!ModelState.IsValid)
            {
                objHelper.Status  = StatusCodes.Status424FailedDependency;
                objHelper.Message = ModelException.Errors(ModelState);
                return(BadRequest(objHelper));
            }

            try
            {
                if (role_permissionRepository.Exists(Role_Permission))
                {
                    objHelper.Status  = StatusCodes.Status200OK;
                    objHelper.Message = "Data already available";
                    return(Ok(objHelper));
                }
                await role_permissionRepository.Insert(Role_Permission);

                objHelper.Status  = StatusCodes.Status200OK;
                objHelper.Message = "Saved Successfully";
                objHelper.Data    = Role_Permission;
                return(Ok(objHelper));
            }
            catch (Exception ex)
            {
                objHelper.Status  = StatusCodes.Status500InternalServerError;
                objHelper.Message = ex.Message;
                return(StatusCode(StatusCodes.Status500InternalServerError, objHelper));
            }
        }
コード例 #3
0
        public async Task <IActionResult> DeleteRoleAndPermissionAsync(int connectionId)
        {
            try
            {
                //判断传过来的值是否存在
                if (await dbContext.role_PermissionRepository.IsExistAsync(connectionId))
                {
                    //找到这条数据
                    Role_Permission role_Permission = await dbContext.role_PermissionRepository.GetFirstInfo(connectionId);

                    //删除数据
                    dbContext.role_PermissionRepository.DeleteInfo(role_Permission);
                    if (await dbContext.role_PermissionRepository.SaveAsync())
                    {
                        return(Ok(1));
                    }
                }
                _logger.LogInformation($"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}删除角色和菜单信息");
                //如果不存在返回错误信息
                return(NotFound());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #4
0
        public void role_permissionTEST()
        {
            Role_Permission role = role_permissionRepo.getById(new Role_Permission
            {
                Role_Permission_Combo_ID = 2
            }
                                                               );

            Assert.AreNotEqual(null, role, "");
        }
コード例 #5
0
 public async Task Update(Role_Permission entity)
 {
     try
     {
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #6
0
 public async Task Insert(Role_Permission entity)
 {
     try
     {
         entity.AddedOn = DateTime.Now;
         adbContext.role_permission.Add(entity);
         await Task.FromResult(adbContext.SaveChanges());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #7
0
        public async Task <IActionResult> AddRoleAndPermissionAsync(RoleAndPermissionDto model)
        {
            try
            {
                DateTime date = DateTime.Now;
                //分割获取到的权限Id,分为数组类型
                string[] PermissionIds = model.PermissionIds.Split(',');
                //实例化初始化器赋值
                RoleInfo roleInfo = new RoleInfo()
                {
                    RoleName = model.Role_Name, CreateDate = date
                };
                //添加角色,返回受影响行数
                dbContext.roleInfoRepository.CreateInfo(roleInfo);
                if (await dbContext.roleInfoRepository.SaveAsync() == false)
                {
                    throw new Exception("没有添加成功");
                }
                //获取所有的角色列表
                IEnumerable <RoleInfo> role = await dbContext.roleInfoRepository.GetAllInfoAsync();

                //通过时间判断刚添加进去的数据
                RoleInfo info = role.ToList().Where(s => s.CreateDate.Equals(date)).FirstOrDefault();
                //赋值
                int code = info.RoleID;
                //循环添加角色权限表
                Role_Permission role_Permission = null;
                for (int i = 0; i < PermissionIds.Length; i++)
                {
                    role_Permission = new Role_Permission()
                    {
                        PermissionID = int.Parse(PermissionIds[i]), RoleID = code
                    };
                    dbContext.role_PermissionRepository.CreateInfo(role_Permission);
                }
                if (await dbContext.role_PermissionRepository.SaveAsync())
                {
                    return(Ok(1));
                }
                //记录日志
                _logger.LogInformation($"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}添加角色和权限");
                return(Ok("添加失败"));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #8
0
 public async Task <IActionResult> InsertRoleAndPermissionAsync(Role_Permission role_Permission)
 {
     try
     {
         dbContext.role_PermissionRepository.CreateInfo(role_Permission);
         if (await dbContext.role_PermissionRepository.SaveAsync())
         {
             return(Ok(1));
         }
         _logger.LogInformation($"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}添加角色和菜单信息");
         return(Ok("添加失败"));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
コード例 #9
0
 public bool Exists(Role_Permission entity)
 {
     try
     {
         int intCount = 0;
         if (entity.Id > 0)
         {
             intCount = adbContext.role_permission.Where(w => w.Id != entity.Id && (w.Role_Id == entity.Role_Id && w.Module_Per_Id == entity.Module_Per_Id)).Count();
         }
         else
         {
             intCount = adbContext.role_permission.Where(w => w.Role_Id == entity.Role_Id && w.Module_Per_Id == entity.Module_Per_Id).Count();
         }
         return(intCount > 0 ? true : false);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #10
0
        public void ConfigureFullProduct()
        {
            if (String.IsNullOrWhiteSpace(ErrorUserName) && String.IsNullOrWhiteSpace(ErrorUserEmail) &&
                String.IsNullOrWhiteSpace(ErrorPassword) && String.IsNullOrWhiteSpace(ErrorConfirmPassword))
            {
                using (var ctx = new Choukash_Revamp_DemoEntities())
                {
                    ctx.Companies.Add(Company);
                    ctx.Roles.Add(UserRole);

                    foreach (var _permission in UserPermissions)
                    {
                        var rolepermission = new Role_Permission()
                        {
                            roles_id       = UserRole.id,
                            permissions_id = _permission.id
                        };
                        ctx.Role_Permission.Add(rolepermission);
                    }
                    var admin = new User()
                    {
                        name         = UserName,
                        email        = UserEmail,
                        password     = Password,
                        companies_id = Company.id,
                        roles_id     = UserRole.id
                    };
                    ctx.Users.Add(admin);
                    ctx.SaveChanges();

                    MessageBox.Show("New User Created");

                    this.EventAggregator.PublishOnUIThread("Operation complete");
                }
            }
        }
コード例 #11
0
ファイル: ProfileTEST.cs プロジェクト: JakeEllis/CIS411
        public void Profile_TEST()
        {
            Song song = songrepo.getById(new Song
            {
                Song_ID = 11111
            }
                                         );

            Assert.AreNotEqual(null, song, "");

            Playlist playlist = playlistrepo.getById(new Playlist
            {
                Playlist_ID = 4
            }
                                                     );

            Assert.AreNotEqual(null, playlist, "");

            Party party = partyrepo.getById(new Party
            {
                Party_ID = 4
            }
                                            );

            Assert.AreNotEqual(null, party, "");

            Role_Permission role_permission = role_permissionrepo.getById(new Role_Permission
            {
                Role_Permission_Combo_ID = 4
            }
                                                                          );

            Assert.AreNotEqual(null, role_permission, "");

            Person_Role person_role = personrolerepo.getById(new Person_Role
            {
                Person_Role_ID = 4
            }
                                                             );

            Assert.AreNotEqual(null, person_role, "");

            Person person = personrepo.getById(new Person
            {
                Person_ID = 4
            }
                                               );

            Assert.AreNotEqual(null, person, "");

            Profile profile = profilerepo.getById(new Profile
            {
                Profile_ID = 4
            });


            IQueryable <Song> songs = songrepo.query(a => a.Song_ID == 11111);

            Assert.AreEqual(1, songs.Count());

            IQueryable <Playlist> playlists = playlistrepo.query(a => a.Playlist_ID == 4);

            Assert.AreEqual(1, playlists.Count());

            IQueryable <Party> parties = partyrepo.query(a => a.Party_ID == 4);

            Assert.AreEqual(1, parties.Count());

            IQueryable <Role_Permission> roles = role_permissionrepo.query(a => a.Role_Permission_Combo_ID == 4);

            Assert.AreEqual(1, roles.Count());

            IQueryable <Person_Role> p_roles = personrolerepo.query(a => a.Person_Role_ID == 4);

            Assert.AreEqual(1, p_roles.Count());

            IQueryable <Person> persons = personrepo.query(a => a.Person_ID == 4);

            Assert.AreEqual(1, persons.Count());

            IQueryable <Profile> profiles = profilerepo.query(a => a.Profile_ID == 4);

            Assert.AreEqual(1, profiles.Count());
        }