コード例 #1
0
        public Role GetRole(string RoleTitle)
        {
            using (var context = new SecurityContext())
            {
                var  repo = new RoleRepository(context);
                Role role = repo.Find(x => x.RoleTitle == RoleTitle, null).FirstOrDefault();

                if (role == null)
                {
                    role = new Role()
                    {
                        RoleTitle = RoleTitle
                    };
                    repo.Add(role);
                    repo.Save();
                }
                else
                {
                    //throw new ArgumentException("Пользователь с таки именем существует", "User");
                }


                return(role);
            }
        }
コード例 #2
0
        public ActionResult CreateRole(NewAppRoleViewModel model)
        {
            var context                  = new AppSecurityContext();
            var rolRepository            = new RoleRepository(context);
            var permissionRepository     = new PermissionRepository(context);
            var rolePermissionRepository = new RolePermissionRepository(context);

            if (ModelState.IsValid)
            {
                var role = mapper.Map <AppRole>(model);
                role.Id = Guid.NewGuid().ToString();
                rolRepository.Add(role);
                if (model.SelectedPermissions == null)
                {
                    model.SelectedPermissions = new int[0];
                }

                foreach (var permissionId in model.SelectedPermissions)
                {
                    rolePermissionRepository.Add(new AppRolePermission {
                        PermissionId = permissionId, RoleId = role.Id
                    });
                }
                context.SaveChanges();
                return(RedirectToAction("Roles", "SecuritySettings"));
            }

            var permissions = permissionRepository.GetAll();

            model.AvailablePermissions = mapper.Map <ICollection <AppPermissionViewModel> >(permissions);
            return(View(model));
        }
コード例 #3
0
        public async Task <IdentityResult> CreateAsync(Role role, CancellationToken cancellationToken)
        {
            _roleRepository.Add(role);

            await _dapperTransactionService.RunOperations(cancellationToken);

            return(IdentityResult.Success);
        }
コード例 #4
0
        public RoleDto AddRole(RoleDto roleDto)
        {
            Role role = _mapper.Map <Role>(roleDto);

            _roleRepo.Add(role);
            _context.SaveChanges();
            return(_mapper.Map <RoleDto>(role));
        }
コード例 #5
0
        public int RoleAdd(mRole mrole)
        {
            Role role = new Role();

            role_repo.Add(mrole.ToDb(role));
            SubmitChanges();
            return(role.id);
        }
コード例 #6
0
 public void Add(Role model)
 {
     /* using (var entities = new QuanLyKhachSanDbContext())
      * {
      *   entities.Roles.Add(model);
      *   entities.SaveChanges();
      * }*/
     roleRepository.Add(model);
 }
コード例 #7
0
        public async Task <IdentityResult> CreateAsync(Role role, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var repoRole = _mapper.Map <Role, RepoNs.Role>(role);
            var result   = await _roleRepository.Add(repoRole);

            return(result > 0 ? IdentityResult.Success : IdentityResult.Failed());
        }
コード例 #8
0
        public UnitOfWork(LibraryDbContext context)
        {
            DbContext = context;
            Books     = new BookRepository(context);
            Users     = new UserRepository(context);
            Rents     = new RentRepository(context);
            Roles     = new RoleRepository(context);

            if (Roles.FindByCondition(role => role.Name == "Admin").Count() == 0)
            {
                Roles.Add(new Role("Admin"));
            }

            if (Roles.FindByCondition(role => role.Name == "Reader").Count() == 0)
            {
                Roles.Add(new Role("Reader"));
            }
        }
コード例 #9
0
        private static void Create(string name)
        {
            var result = RoleRepository.Get(name);

            if (result != null)
            {
                throw new HttpException(409, "Role is already in use");
            }
            RoleRepository.Add(name);
        }
コード例 #10
0
        public ActionResult Index([Bind(Include = "Id,role")] Role role)
        {
            if (ModelState.IsValid)
            {
                db.Add(role);
                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
コード例 #11
0
ファイル: RoleService.cs プロジェクト: AnTTSE61258/NetCafeWeb
 public bool addRole(Role role)
 {
     RoleRepository repository = new RoleRepository();
     if(role != null)
     {
         repository.Add(role);
         return true;
     }
     return false;
 }
コード例 #12
0
        public void Add(RoleViewModels model)
        {
            AspNetRole role = new AspNetRole();

            role    = Mapper.ModelToData(role, model);
            role.Id = Guid.NewGuid().ToString();

            Repository.Add(role);
            Repository.Save();
        }
コード例 #13
0
        public void AddTest()
        {
            Role role = new Role();

            role.Name = "SysAdmin";


            var roleRepository = new RoleRepository();

            role = roleRepository.Add(role);
        }
コード例 #14
0
        private static void CreateRole()
        {
            Role role = new Role();

            role.Id       = Guid.NewGuid();
            role.RoleName = "Engineer";
            IRoleRepository roleRepository = new RoleRepository();

            roleRepository.Add(role);
            roleRepository.Save();
        }
コード例 #15
0
    private static void Create(string name)
    {
        // trying if post with specific slug exists
        var result = RoleRepository.Get(name);

        if (result != null)
        {
            throw new HttpException(409, "Role allready exists");
        }

        RoleRepository.Add(name);
    }
コード例 #16
0
        public Task CreateAsync(TRole role)
        {
            if (role == null)
            {
                throw new ArgumentNullException("role");
            }

            RoleRepository.Add(role);


            return(Task.FromResult <object>(null));
        }
コード例 #17
0
        public ActionResult Create(RoleViewModel role)
        {
            if (ModelState.IsValid)
            {
                var roleDomain = _mapper.Map <RoleViewModel, Role>(role);
                _roleRepository.Add(roleDomain);
                _roleRepository.Save();

                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
コード例 #18
0
        public bool Add(string roleName, string description, bool status)
        {
            var role = new Role()
            {
                RoleID   = Guid.NewGuid(),
                RoleName = roleName,
                Memo     = description,
                IsLock   = status
            };

            RoleRepository.Add(role);
            RoleRepository.SaveChanges();
            return(true);
        }
コード例 #19
0
        public void Add_GivenArgumentIsNotRole_ExpectArgumentException()
        {
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase($"DataContext{Guid.NewGuid()}")
                          .Options;

            var mediator = new Mock <IMediator>();

            using var context = new DataContext(options, mediator.Object);
            var roleRepository = new RoleRepository(context);
            var exception      = Assert.Throws <ArgumentException>(() => roleRepository.Add(new Mock <IRole>().Object));

            Assert.Equal("role", exception.Message);
        }
コード例 #20
0
ファイル: RoleBL.cs プロジェクト: alonsodev/SSR
        public void Agregar(RoleViewModel pRoleViewModel)
        {
            roles oroles = new roles
            {
                role_id         = 0,
                role            = pRoleViewModel.role,
                manual_file     = pRoleViewModel.manual_file,
                date_created    = DateTime.Now,
                user_id_created = pRoleViewModel.user_id_created
            };

            oRepositorio.Add(oroles);
            oUnitOfWork.SaveChanges();
        }
コード例 #21
0
 public ActionResult <Role> CreateRole(Role role)
 {
     IRoleRepository roleRepository = new RoleRepository();
     {
         if (role != null)
         {
             roleRepository.Add(role);
             return(Ok(role.Name));
         }
         else
         {
             return(NoContent());
         }
     }
 }
コード例 #22
0
        public bool Add(string roleName, string description, bool status)
        {
            var role = new AUTH_ROLE()
            {
                //ROLE_ID = Guid.NewGuid().ToString(),
                ROLE_ID   = RoleRepository.GetNewID("AUTH_ROLE", "ROLE_ID"),
                ROLE_NAME = roleName,
                MEMO      = description,
                IS_LOCK   = status == true?"1":"0"
            };

            RoleRepository.Add(role);
            RoleRepository.SaveChanges();
            return(true);
        }
コード例 #23
0
        private void SeesRoles()
        {
            var roleRepository = new RoleRepository(UnitOfWork);
            var values         = typeof(Roles).GetFields(BindingFlags.Static | BindingFlags.Public)
                                 .Where(x => x.IsLiteral && !x.IsInitOnly)
                                 .Select(x => x.GetValue(null)).Cast <string>();
            Type type = typeof(Roles); // MyClass is static class with static properties

            foreach (var value in values)
            {
                var defaultRole = new Role(value.ToString());
                roleRepository.Add(defaultRole);
            }
            UnitOfWork.Commit();
        }
コード例 #24
0
        public OpResult SaveOrUpdate(SysRoles obj, string menuIds, string limitIds)
        {
            if (RoleRepository.IsExists(o => o.Title == obj.Title && o.Id != obj.Id))
            {
                return(OpResult.Fail("角色名称已存在!"));
            }
            obj.Limitids = limitIds;
            var mids = menuIds.ToIntArray();

            if (obj.Id == 0)
            {
                obj.RoleId    = RoleRepository.GetMaxInt(o => (int?)o.RoleId, 100);
                obj.UpdateDT  = obj.CreateDT = DateTime.Now;
                obj.UpdateUID = obj.CreateUID = CurrentUser.UID;
                obj.Status    = true;
                var menus = MenuRepository.GetQuery(o => o.Status).ToList();
                obj.SysRoleDatas = new List <SysRoleData>();
                menus.Each(o =>
                {
                    var data = new SysRoleData()
                    {
                        MenuId    = o.MenuId,
                        PMenuId   = o.PMenuId,
                        SortOrder = o.SortOrder,
                    };
                    data.HasSelected = mids.Any(i => i == o.MenuId);
                    obj.SysRoleDatas.Add(data);
                });
                RoleRepository.Add(obj, false);
            }
            else
            {
                var menu = Get(obj.Id);
                obj.ToCopyProperty(menu, new List <string>()
                {
                    "CreateDT", "CreateUID", "Status", "RoleId"
                });
                menu.UpdateDT  = DateTime.Now;
                menu.UpdateUID = CurrentUser.UID;
                menu.SysRoleDatas.Each(o =>
                {
                    o.HasSelected = mids.Any(i => i == o.MenuId);
                });
            }
            RoleRepository.SaveChanges();
            return(OpResult.Success(data: new { id = obj.Id, roleId = obj.RoleId }));
        }
コード例 #25
0
        public async Task AddToRoleAsync(ConscienceAccount user, string roleName)
        {
            var role = await _rolesRepo.GetAll().FirstOrDefaultAsync(r => r.Name.ToLower() == roleName.ToLower());

            if (role == null)
            {
                role = new Role {
                    Name = roleName
                };
                _rolesRepo.Add(role);
            }

            var userToModify = _accountsRepo.GetAll().First(a => a.Id == user.Id);

            userToModify.Roles.Add(role);
            _accountsRepo.Modify(userToModify);
        }
コード例 #26
0
 public override void CreateRole(string roleName)
 {
     if (!string.IsNullOrEmpty(roleName))
     {
         Role Role = null;
         Role = RoleRepository.GetAll().FirstOrDefault(Rl => Rl.RoleName == roleName);
         if (Role == null)
         {
             Role NewRole = new Role
             {
                 RoleId   = Guid.NewGuid(),
                 RoleName = roleName
             };
             RoleRepository.Add(NewRole);
         }
     }
 }
コード例 #27
0
        public void Add_GivenArgumentIsRole_ExpectRoleToBeAddedToTheContext()
        {
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase($"DataContext{Guid.NewGuid()}")
                          .Options;

            var mediator = new Mock <IMediator>();

            using var context = new DataContext(options, mediator.Object);
            var roleRepository = new RoleRepository(context);
            var role           = new Role(TestVariables.RoleId, "name", new List <Guid>());

            roleRepository.Add(role);
            var roleInContext = context.ChangeTracker.Entries <Role>().FirstOrDefault(x => x.Entity.Id == TestVariables.RoleId);

            Assert.NotNull(roleInContext);
            Assert.Equal(EntityState.Added, roleInContext.State);
        }
コード例 #28
0
        public void TestGetRoles()
        {
            /*
             * UserRepository.Add(user);
             * Role role = roleRepository.getBySlug("listner");
             * UserRoleRepository.Add(new UserRole { UserId = user.UserId, User = user, Role = role, RoleId = role.RoleId });
             */

            userRepository.Add(user);
            roleRepository.Add(role);
            userRole = new UserRole {
                UserId = user.UserId, User = user, Role = role, RoleId = role.RoleId
            };
            userRoleRepository.Add(userRole);
            Assert.AreEqual(1, userRepository.GetRoles(user).Count);
            userRoleRepository.Delete(userRole);
            roleRepository.Delete(role);
            userRepository.Delete(user);
        }
コード例 #29
0
        public async Task AddToRoleAsync(User user, string roleName, CancellationToken cancellationToken)
        {
            var roleRepository     = new RoleRepository(_connectionFactory);
            var roleNormalizedName = roleName.ToUpper();
            var role = (await roleRepository.Search(new RepoNs.RoleSearchCriteria {
                NormalizedName = roleNormalizedName
            })).FirstOrDefault();
            int roleId;

            if (role == null)
            {
                roleId = await roleRepository.Add(new RepoNs.Role
                {
                    Name           = roleName,
                    NormalizedName = roleNormalizedName
                });
            }
            else
            {
                roleId = role.Id;
            }

            var existingUser = (await _userRoleRepository.Search(new RepoNs.UserRoleSearchCriteria {
                UserId = user.Id
            })).FirstOrDefault();

            if (existingUser != null)
            {
                await _userRoleRepository.Add(new RepoNs.UserRole
                {
                    UserId    = existingUser.Id,
                    RoleId    = roleId,
                    StampDate = user.StampDate,
                    StampUser = user.StampUser
                });
            }
        }
コード例 #30
0
        public void SubmitForm(RoleInputDto roleInputDto, string[] resourceIdsArray, string keyValue)
        {
            Role role = new Role();
            long id   = Convert.ToInt64(keyValue);

            if (!string.IsNullOrEmpty(keyValue))
            {
                role = roleRepository.Get(id);
                AutoMapper.Mapper.Map <RoleInputDto, Role>(roleInputDto, role);
                role.LastModificationTime = DateTime.Now;
                roleRepository.Update(role);
            }
            else
            {
                AutoMapper.Mapper.Map <RoleInputDto, Role>(roleInputDto, role);
                role.Id           = IdWorkerHelper.GenId64();
                role.CreationTime = DateTime.Now;
                roleRepository.Add(role);
            }
            permissionRepository.Delete(new Specification <Permission>(p => p.ObjectId.Equals(id)));
            List <Permission> permissionList = new List <Permission>();

            foreach (var resourceId in resourceIdsArray)
            {
                Permission permission = new Permission();
                permission.Id           = IdWorkerHelper.GenId64();
                permission.ResourceId   = Convert.ToInt64(resourceId);
                permission.ObjectId     = id;
                permission.ObjectType   = "RolePermission";
                permission.CreationTime = DateTime.Now;
                permission.DeletedMark  = false;
                permissionList.Add(permission);
                Debug.WriteLine(permission.Id);
            }
            permissionRepository.Add(permissionList);
        }
コード例 #31
0
ファイル: RoleService.cs プロジェクト: qkxyk/hxplatform
        public ResponseData CreateRole(RoleViewModel rvm)
        {
            ResponseData rd = new ResponseData();
            //只有管理员才能添加角色
            //bool bRet = new UserService().IsAdmin(rvm.a)
            //RoleListViewModel ravm = new RoleListViewModel();
            RoleModel rm = new RoleModel()
            {
                IsAdmin = rvm.IsAdmin, Token = rvm.Token, RoleName = rvm.RoleName
            };

            try
            {
                _rr.Add(rm);
                rd.Success = true;
                rd.Message = "添加角色成功";
            }
            catch (Exception ex)
            {
                rd.Success = false;
                rd.Message = "添加角色失败。" + ex.Message;
            }
            return(rd);
        }
コード例 #32
0
        public string Save()
        {
            string result = "";
            try
            {
                var repo = new RoleRepository();
                var roleInput = JsonConvert.DeserializeObject<DAL.Role>(Request["role"]);
                var roleActions = JsonConvert.DeserializeObject<List<DAL.RoleAction>>(Request["roleActions"]);
                if (roleInput != null)
                {
                    if (repo.IsExist(roleInput.ID, roleInput.Name))
                        return JsonResult(false, "1");
                    else
                    {

                        if (roleInput.ID == 0)
                            repo.Add(roleInput, roleActions);
                        else
                        {
                            repo.Save(roleInput, roleActions);
                        }
                        result = JsonResult(true, Resources.Messages.Save);
                    }
                }
                else
                    result = JsonResult(true, Resources.Messages.Save);
            }
            catch (Exception ex)
            {
                result = JsonResult(false, ex.Message);
            }
            return result;
        }