public void AddRoleTest() { #region arrange RoleVO roleVO = new RoleVO() { RoleName = "Admin", Description = "最高權限" }; int reNumber = 1; _dataAccess.Stub(o => o.ExcuteSQL(Arg <string> .Is.Anything, Arg <object[]> .Is.Anything)).Return(reNumber); #endregion #region act var result = _target.AddRole(roleVO); #endregion #region assert Assert.AreEqual(result, reNumber); #endregion }
public void AddRole_Test() { SeedData(); using (var context = new AppDbContext(ContextOptions)) { RoleRepository roleRepository = new RoleRepository(context); var role = new AspNetRole { Name = "Testing", Id = Guid.NewGuid().ToString(), NormalizedName = "TESTING" }; var result = roleRepository.AddRole(role); var savedResult = context.AspNetRoles.FirstOrDefault(e => e.Id == role.Id); Assert.Equal("Testing", savedResult.Name); result = roleRepository.AddRole(role); Assert.Null(result); } }
protected void btnSaveRole_Click(object sender, EventArgs e) { RoleRepository rl = new RoleRepository(); RoleTable l = new RoleTable(); l.RoleName = txtName.Text; rl.AddRole(l); }
public async Task <IActionResult> Create(List <UserAccessSubmitViewModel> vm, RoleInsertViewModel role) { // اضافه کردن نقش جدید var roleId = await _roleRepository.AddRole(role); // اضافه کردن دسترسی های نقش جاری _usersAccessRepository.AddAccessRole(vm, roleId); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(List <UserAccessSubmitViewModel> vm, RoleInsertViewModel role) { // اضافه کردن نقش جدید var roleId = await _roleRepository.AddRole(role); vm.Add(new UserAccessSubmitViewModel { Actions = new List <string> { "Index", "Profile" }, Controller = "HomeController" }); // اضافه کردن دسترسی های نقش جاری _usersAccessRepository.AddAccessRole(vm, roleId); return(RedirectToAction("Index")); }
static void Seed() { var GameRepo = new GameRepository(); var UserRepo = new UserProfileRepository(); var WordRepo = new WordBankRepository(); var RoleRepo = new RoleRepository(); var DicRepo = new DictionaryRepository(); DicRepo.AddDictionary(DictionaryList.OrderBy(d => d.Word).Distinct().ToList()); foreach (var item in Roles) { RoleRepo.AddRole(item); } UserRepo.AddUserProfile(UserProfile); Console.WriteLine("User Added"); GameRepo.AddGame(Game); Console.WriteLine("Game Added"); WordRepo.AddWordBank(WordBank); Console.WriteLine("Word Added"); }
/// <summary> /// To add the role details. /// </summary> /// <param name="role"></param> /// <param name="accessToken"></param> /// <returns></returns> public bool AddRole(Role role, string accessToken) { try { dynamic session = null; if (!string.IsNullOrEmpty(accessToken)) { session = _sessionManager.GetSessionValues(accessToken); } if (!string.IsNullOrEmpty(session.DatabaseId()) || _isNonPCR) { using (var repository = new RoleRepository(session.DatabaseId())) { int existroleCount = repository.ExistRoleName(role.RoleName); if (existroleCount == 0) { role.IsActive = true; role.CreatedDate = DateTime.Now; role.UpdatedDate = DateTime.Now; repository.AddRole(role); return(true); } else { return(false); } } } else { throw new Exception("Unable to get database connection."); } } catch { throw; } }
public bool AddRole(RoleModel entity) { if (entity == null) { return(false); } RoleModel role; if (entity.ID == 0) { role = new RoleModel(); } else { role = roleRepo.GetByID(entity.ID); } role.Rolee = entity.Rolee; return(roleRepo.AddRole(role)); }
public bool AddRole(Role R) { RoleRepo.AddRole(R); return(true); }