public void Two_keys_with_same_value() { var one = new RoleKey("one"); var two = new RoleKey("one"); one.ShouldBe(two); }
public void Two_different_keys() { var one = new RoleKey("one"); var two = new RoleKey("two"); one.ShouldNotBe(two); }
public void Two_keys_with_different_values_by_case() { var one = new RoleKey("one"); var two = new RoleKey("ONE"); one.ShouldBe(two); }
public ActionResult Index() { ViewBag.Feature = "Danh sách"; ViewBag.Element = KeyElement; if (Request.Url != null) { ViewBag.BaseURL = Request.Url.LocalPath; } using (var workScope = new UnitOfWork(new PatientManagementDbContext())) { var lstRole = RoleKey.GetDic(); ViewBag.Roles = new SelectList(lstRole, "Value", "Text"); List <Patient> patients = new List <Patient>(); patients = new PatientManagementDbContext().Database.SqlQuery <Patient>("exec getPatient").ToList(); ViewBag.Patients = new SelectList(patients, "Id", "FullName"); List <BELibrary.Entity.Doctor> doctors = new List <BELibrary.Entity.Doctor>(); doctors = new PatientManagementDbContext().Database.SqlQuery <BELibrary.Entity.Doctor>("exec getDoctor").ToList(); ViewBag.Doctors = new SelectList(doctors, "Id", "Name"); var listData = workScope.Accounts.GetAll().ToList(); return(View(listData)); } }
private async Task GetRoleDetails(IOwinContext context) { var key = new RoleKey(context.GetRouteValue("key")); var role = _collectionsReadModel.Roles.Single(r => r.Key == key); await context.WriteJson(role, _settings); }
public IActionResult Edit(UserViewModel viewModel) { if (ModelState.IsValid) { // Verify not exist on id var key = new UserKey() { Id = viewModel.Id }; var user = _usersService.GetUser(key); if (user != null) { user.Id = viewModel.Id; user.Name = viewModel.Name; user.Email = viewModel.Email; user.Suspended = viewModel.Suspended; //Verify role exist var roleKey = new RoleKey(); roleKey.Id = viewModel.RoleId; var role = _rolesService.GetRole(roleKey); if (role != null) { user.Role = role; user = _usersService.UpdateUser(user); return(RedirectToAction("Index")); } } } // Populate SelectListItem of roles ViewBag.Roles = ControllerUtils.CreateSelectRoleItemList(_rolesService.FindRoles(), viewModel.Id); return(View(viewModel)); }
public CreateRoleCommand(Operator user, RoleKey key, string name, string description) { Operator = user; Key = key; Name = name; Description = description; }
protected override void Seed(BELibrary.Entity.ELearningDBContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. var role = new Role { Id = RoleKey.Admin, Name = RoleKey.GetRole(RoleKey.Admin) }; context.Roles.AddOrUpdate(c => c.Id, role); context.SaveChanges(); var passwordFactory = VariableExtensions.DefautlPassword + VariableExtensions.KeyCryptor; var passwordCrypto = CryptorEngine.Encrypt(passwordFactory, true); context.Users.AddOrUpdate(c => c.Username, new User() { FullName = "Quản Trị", Phone = "0973 642 032", Username = "******", Password = passwordCrypto, RoleId = role.Id, IsLocked = false, LinkAvata = "/FileUploads/images/28618678.png", DateOfBirth = new DateTime(1997, 01, 01), Status = true, Email = "*****@*****.**" }); }
public RoleCreatedEvent(Operator @operator, Guid id, RoleKey key, string name, string description) : base(@operator) { ID = id; Key = key; Name = name; Description = description; }
//根據RoleKey取得相關的AllChild public static List<User> GetAllChilds(User Child, RoleKey RoleKey, bool WithSelf = true) { List<User> Childs = new List<User>(); if (WithSelf == true) { Childs.Add(Child); } FindAllChilds(ref Childs, Child); return Childs.Where(c => c.Roles.Contains(RoleKey)).ToList(); }
public Role GetRole(RoleKey key) { Role role = null; string cacheKey = key == null ? "RoleKey_null" : key.GetCacheKey(); if (key != null && !TryGetCacheData(cacheKey, out role)) { role = GetRoleManager().GetRole(key); SetCacheData(_cacheName, cacheKey, role); } return(role); }
public ActionResult Create(int role) { ViewBag.key = "Thêm mới"; ViewBag.Element = RoleKey.GetRoleText(role); ViewBag.isEdit = false; ViewBag.Role = role; ViewBag.Genders = new SelectList(GenderKey.GetDic(), "Key", "Value"); ViewBag.Roles = new SelectList(RoleKey.GetDic(), "Key", "Value"); return(View()); }
public async Task <IActionResult> ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return(View("Error")); } var applicationUser = await _identityUserManager.FindByIdAsync(userId); if (applicationUser == null) { return(View("Error")); } var result = await _identityUserManager.ConfirmEmailAsync(applicationUser, code); if (result.Succeeded) { // add role to user //await _userManager.AddToRoleAsync(user, "user"); //don't work on rc2??? // Verify not exist on id var key = new UserKey() { Id = applicationUser.Id }; var user = _usersService.GetUser(key); if (user != null) { //Verify role exist var roleKey = new RoleKey(); roleKey.Id = "1"; //User var role = _rolesService.GetRole(roleKey); if (role != null) { user.Role = role; user = _usersService.UpdateUser(user); } if (user != null) { //Add empty user profil (for correct connect error on mobile application) var userInfo = new UserInfo() { UserId = user.Id, Unit = TUnitType.Metric }; _userInfosService.UpdateUserInfo(userInfo); } return(RedirectToAction("Index", "Home", new { area = "Site" })); } } return(View(result.Succeeded ? "ConfirmEmail" : "Error")); }
public ActionResult Index(int role) { if (!RoleKey.Any(role)) { return(Redirect("/admin")); } ViewBag.Element = RoleKey.GetRoleText(role); ViewBag.Role = role; using (var workScope = new UnitOfWork(new ELearningDBContext())) { var listData = workScope.Account.GetAll().Where(x => x.RoleId == role).ToList(); return(View(listData)); } }
/// <summary> /// Get data in database /// </summary> /// <param name="key">Primary Key</param> /// <returns>read data</returns> public Role Get(RoleKey key) { if (key == null || string.IsNullOrWhiteSpace(key.Id)) { return(null); } var row = _dbContext.Roles.Where(m => m.Id == key.Id).FirstOrDefault(); if (row != null) { return(RoleTransformer.ToBean(row)); } return(null); }
/// <summary> /// Delete data in database /// </summary> /// <param name="key">Primary Key</param> public void Delete(RoleKey key) { if (key == null || string.IsNullOrWhiteSpace(key.Id)) { return; } var row = _dbContext.Roles.Where(m => m.Id == key.Id).FirstOrDefault(); if (row != null) { _dbContext.Roles.Remove(row); _dbContext.SaveChanges(); } }
private async Task UpdateRoleName(IOwinContext context) { var key = new RoleKey(context.GetRouteValue("key")); var dto = context.ReadJson<EditRoleDto>(); var role = _collectionsReadModel.Roles.Single(r => r.Key == key); _mediator.Publish(new ChangeRoleNameCommand( context.GetOperator(), role.ID, dto.Name )); await Task.Yield(); }
public IActionResult Delete(string id) { if (!string.IsNullOrWhiteSpace(id)) { var key = new RoleKey() { Id = id }; var role = _rolesService.GetRole(key); if (role != null) { _rolesService.DeleteRole(key); } } return(RedirectToAction("Index")); }
public ActionResult Update(string username, int role) { ViewBag.isEdit = true; ViewBag.Role = role; ViewBag.key = "Cập nhật"; ViewBag.Element = RoleKey.GetRoleText(role); ViewBag.Genders = new SelectList(GenderKey.GetDic(), "Key", "Value"); ViewBag.Roles = new SelectList(RoleKey.GetDic(), "Key", "Value"); using (var workScope = new UnitOfWork(new ELearningDBContext())) { var acc = workScope.Account.FirstOrDefault(x => x.Username == username); acc.Password = ""; return(View("Create", acc)); } }
public IActionResult Edit(string id) { if (!string.IsNullOrWhiteSpace(id)) { var key = new RoleKey() { Id = id }; var role = _rolesService.GetRole(key); if (role != null) { var viewModel = new RoleViewModel(); viewModel.Id = role.Id; viewModel.Name = role.Name; viewModel.NormalizedName = role.NormalizedName; return(View(viewModel)); } } return(RedirectToAction("Index")); }
public void DeleteRole(RoleKey key) { BeginTransaction(); try { GetRoleManager().DeleteRole(key); CommitTransaction(); //invalidate cache InvalidateCache(_cacheName); } catch (Exception exception) { _logger.LogCritical("Unable to delete role", exception); RollbackTransaction(); throw exception; } finally { EndTransaction(); } }
public IActionResult Edit(RoleViewModel viewModel) { if (ModelState.IsValid) { // Verify not exist on id var key = new RoleKey() { Id = viewModel.Id }; var role = _rolesService.GetRole(key); if (role != null) { role.Name = viewModel.Name; role.NormalizedName = viewModel.NormalizedName; role = _rolesService.UpdateRole(role); return(RedirectToAction("Index")); } } return(View(viewModel)); }
public ActionResult Index() { ViewBag.Feature = "Danh sách"; ViewBag.Element = KeyElement; if (Request.Url != null) { ViewBag.BaseURL = Request.Url.LocalPath; } using (var workScope = new UnitOfWork(new PatientManagementDbContext())) { var lstRole = RoleKey.GetDic(); ViewBag.Roles = new SelectList(lstRole, "Value", "Text"); var patients = workScope.Patients.GetAll().ToList(); ViewBag.Patients = new SelectList(patients, "Id", "FullName"); var listData = workScope.Accounts.GetAll().ToList(); return(View(listData)); } }
/// <summary> /// Create data in database /// </summary> /// <param name="role">Data</param> /// <returns>insert data</returns> public Role Create(Role role) { if (role == null) { return(null); } if (string.IsNullOrWhiteSpace(role.Id)) { int newId; var key = new RoleKey(); var sequencerManager = new SequencerManager(); do { newId = sequencerManager.GetNextValue(_dbContext, 3, "role"); key.Id = newId.ToString(); }while (Get(key) != null); // Test Record exist if (newId > 0) { role.Id = newId.ToString(); } } if (string.IsNullOrWhiteSpace(role.Id)) { return(null); } var row = new IdentityRole(); RoleTransformer.ToRow(role, row); _dbContext.Roles.Add(row); _dbContext.SaveChanges(); return(RoleTransformer.ToBean(row)); }
internal void DeleteRole(RoleKey key) { _roleModule.Delete(key); }
internal Role GetRole(RoleKey key) { return _roleModule.Get(key); }
private async Task RemovePermissions(IOwinContext context) { var key = new RoleKey(context.GetRouteValue("key")); var role = _collectionsReadModel.Roles.Single(r => r.Key == key); var permissions = context .ReadJson<PermissionKey[]>() .Select(pk => _collectionsReadModel.Permissions.Single(p => p.Key == pk)) .Select(p => p.ID); _mediator.Publish(new RemovePermissionsFromRoleCommand( context.GetOperator(), role.ID, permissions )); await Task.Yield(); }
internal Role GetRole(RoleKey key) { return(_roleModule.Get(key)); }
public IActionResult Edit(RoleViewModel viewModel) { if (ModelState.IsValid) { // Verify not exist on id var key = new RoleKey() { Id = viewModel.Id }; var role = _rolesService.GetRole(key); if (role != null) { role.Name = viewModel.Name; role.NormalizedName = viewModel.NormalizedName; role = _rolesService.UpdateRole(role); return RedirectToAction("Index"); } } return View(viewModel); }
public Role GetRole(RoleKey key) { Role role = null; string cacheKey = key == null ? "RoleKey_null" : key.GetCacheKey(); if (key != null && !TryGetCacheData(cacheKey, out role)) { role = GetRoleManager().GetRole(key); SetCacheData(_cacheName, cacheKey, role); } return role; }
//取得Role中所有包含的User public static List<User> GetRoleUsers(RoleKey RoleKey) { return UserCache.Values .Where(u => u.Roles.Contains(RoleKey)) .ToList(); }
public async Task<IActionResult> ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return View("Error"); } var applicationUser = await _identityUserManager.FindByIdAsync(userId); if (applicationUser == null) { return View("Error"); } var result = await _identityUserManager.ConfirmEmailAsync(applicationUser, code); if(result.Succeeded) { // add role to user //await _userManager.AddToRoleAsync(user, "user"); //don't work on rc2??? // Verify not exist on id var key = new UserKey() { Id = applicationUser.Id }; var user = _usersService.GetUser(key); if (user != null) { //Verify role exist var roleKey = new RoleKey(); roleKey.Id = "1"; //User var role = _rolesService.GetRole(roleKey); if (role != null) { user.Role = role; user = _usersService.UpdateUser(user); } if (user != null) { //Add empty user profil (for correct connect error on mobile application) var userInfo = new UserInfo() { UserId = user.Id, Unit = TUnitType.Metric }; _userInfosService.UpdateUserInfo(userInfo); } return RedirectToAction("Index", "Home", new { area = "Site" }); } } return View(result.Succeeded ? "ConfirmEmail" : "Error"); }
public IActionResult Edit(UserViewModel viewModel) { if (ModelState.IsValid) { // Verify not exist on id var key = new UserKey() { Id = viewModel.Id }; var user = _usersService.GetUser(key); if (user != null) { user.Id = viewModel.Id; user.Name = viewModel.Name; user.Email = viewModel.Email; user.Suspended = viewModel.Suspended; //Verify role exist var roleKey = new RoleKey(); roleKey.Id = viewModel.RoleId; var role = _rolesService.GetRole(roleKey); if (role != null) { user.Role = role; user = _usersService.UpdateUser(user); return RedirectToAction("Index"); } } } // Populate SelectListItem of roles ViewBag.Roles = ControllerUtils.CreateSelectRoleItemList(_rolesService.FindRoles(), viewModel.Id); return View(viewModel); }
public async Task<IActionResult> ConfirmUserEmail(string id) { if (!string.IsNullOrWhiteSpace(id)) { var appUser = await _identityUserManager.FindByIdAsync(id); if (appUser != null && !appUser.EmailConfirmed) { appUser.EmailConfirmed = true; await _identityUserManager.UpdateAsync(appUser); //Add user role var userKey = new UserKey() { Id = id }; var user = _usersService.GetUser(userKey); if (user != null) { //Verify role exist var roleKey = new RoleKey(); roleKey.Id = "1"; //User var role = _rolesService.GetRole(roleKey); if (role != null) { user.Role = role; user = _usersService.UpdateUser(user); } } //Add empty user profil (for correct connect error on mobile application) var userInfoKey = new UserInfoKey() { UserId = id }; var userInfo = _userInfosService.GetUserInfo(userInfoKey); if (userInfo == null) { userInfo = new UserInfo() { UserId = id, Unit = TUnitType.Metric }; _userInfosService.UpdateUserInfo(userInfo); } try { await _emailSender.SendEmailAsync(appUser.Email, "Account validated", "Your account validated by admin"); } catch(Exception except) { _logger.LogError(0, except, "can't send email"); } } } return RedirectToAction("Index"); }
public List <User> GetUsersByRole(RoleKey role) { throw new NotImplementedException(); }
public IActionResult Delete(string id) { if (!string.IsNullOrWhiteSpace(id)) { var key = new RoleKey() { Id = id }; var role = _rolesService.GetRole(key); if (role != null) { _rolesService.DeleteRole(key); } } return RedirectToAction("Index"); }
public bool CanCreateRole(RoleKey key) { return _keys.Contains(key) == false; }
public async Task <IActionResult> ConfirmUserEmail(string id) { if (!string.IsNullOrWhiteSpace(id)) { var appUser = await _identityUserManager.FindByIdAsync(id); if (appUser != null && !appUser.EmailConfirmed) { appUser.EmailConfirmed = true; await _identityUserManager.UpdateAsync(appUser); //Add user role var userKey = new UserKey() { Id = id }; var user = _usersService.GetUser(userKey); if (user != null) { //Verify role exist var roleKey = new RoleKey(); roleKey.Id = "1"; //User var role = _rolesService.GetRole(roleKey); if (role != null) { user.Role = role; user = _usersService.UpdateUser(user); } } //Add empty user profil (for correct connect error on mobile application) var userInfoKey = new UserInfoKey() { UserId = id }; var userInfo = _userInfosService.GetUserInfo(userInfoKey); if (userInfo == null) { userInfo = new UserInfo() { UserId = id, Unit = TUnitType.Metric }; _userInfosService.UpdateUserInfo(userInfo); } try { string reportData = await _reportService.CreateReportForAdminNewUserAccountCreatedAsync(user.Id); await _emailSender.SendEmailAsync(appUser.Email, Translation.CONFIRM_USER_ACCOUNT, reportData); await _emailSender.SendEmailAsync(appUser.Email, "Account validated", "Your account validated by admin"); } catch (Exception except) { _logger.LogError(0, except, "can't send email"); } } } return(RedirectToAction("Index")); }
public void When_serializing() { var input = new RoleKey("one"); var json = JsonConvert.SerializeObject(input); var output = JsonConvert.DeserializeObject<RoleKey>(json); output.ShouldBe(input); }
public DuplicateRoleException(RoleKey key) : base($"There is already a Role with the key '{key}'") { }
public IActionResult Edit(string id) { if (!string.IsNullOrWhiteSpace(id)) { var key = new RoleKey() { Id = id }; var role = _rolesService.GetRole(key); if (role != null) { var viewModel = new RoleViewModel(); viewModel.Id = role.Id; viewModel.Name = role.Name; viewModel.NormalizedName = role.NormalizedName; return View(viewModel); } } return RedirectToAction("Index"); }