public async Task WarnPunish(int number, AddRole _, IRole role, StoopidTime time = null) { var punish = PunishmentAction.AddRole; var success = _service.WarnPunish(ctx.Guild.Id, number, punish, time, role); if (ctx.Guild.OwnerId != ctx.User.Id && role.Position >= ((IGuildUser)ctx.User).GetRoles().Max(x => x.Position)) { await ReplyErrorLocalizedAsync("role_too_high"); return; } if (!success) { return; } if (time is null) { await ReplyConfirmLocalizedAsync("warn_punish_set", Format.Bold(punish.ToString()), Format.Bold(number.ToString())).ConfigureAwait(false); } else { await ReplyConfirmLocalizedAsync("warn_punish_set_timed", Format.Bold(punish.ToString()), Format.Bold(number.ToString()), Format.Bold(time.Input)).ConfigureAwait(false); } }
static int RunAddRole(AddRole opts) { var sp = GetServiceProvider(); ConsoleTasks.GiveUserRole(sp, opts.Email, opts.Role).GetAwaiter().GetResult(); return(0); }
protected void btnAdd_Click(object sender, EventArgs e) { try { AddRole ar = new AddRole(); ar.Role = txtRole.Text; ar.UserName = Session["un"].ToString(); db.AddRoles.Add(ar); db.SaveChanges(); lblId.Text = ar.Id.ToString(); ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Data Save Sucessfully!!!')", true); lblId.Text = ""; txtRole.Text = ""; } catch (Exception ex1) { Literal1.Text = ex1.Message; } }
public async Task AddRole(AddRole model) { var transaction = _dbContext.Database.BeginTransaction(); try { var entity = new Data_Access_Layer.Role() { Name = model.Name, NormalizedName = model.Name.ToUpper() }; await RoleRepository.Add(entity); Save(); await RoleClaimRepository .AddRange(model.Claims.Select(cl => new RoleClaim { Role = entity, ClaimType = cl.Type, ClaimValue = cl.Value })); Save(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } }
public void CanAdd_should_not_throw_exception_if_success() { var command = new AddRole { Name = roleName }; GuardAppRoles.CanAdd(roles_0, command); }
public void CanAdd_should_not_throw_exception_if_command_is_valid() { var command = new AddRole { Name = roleName }; GuardAppRoles.CanAdd(command, App(roles_0)); }
public async Task <IActionResult> CreateRoleAsync([FromBody] AddRole newRole) { var role = new IdentityRole { Name = newRole.Name }; await _roleManager.CreateAsync(role); return(Ok()); }
public void CanAdd_should_throw_exception_if_name_empty() { var command = new AddRole { Name = null }; ValidationAssert.Throws(() => GuardAppRoles.CanAdd(roles_0, command), new ValidationError("Name is required.", "Name")); }
/// <summary> /// 新建角色 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bntAddRole_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { AddRole addRole = new AddRole(); if (DialogResult.OK == addRole.ShowDialog()) { InitRoleTree(); } }
public void CanAdd_should_throw_exception_if_name_exists() { var roles_1 = roles_0.Add(roleName); var command = new AddRole { Name = roleName }; ValidationAssert.Throws(() => GuardAppRoles.CanAdd(roles_1, command), new ValidationError("A role with the same name already exists.")); }
public async Task <IActionResult> AddRole([FromBody] AddRole addRole) { var role = _mapper.Map <IdentityRole>(addRole); var result = await _adminService.AddRoleAsync(role); if (result.IsSuccess) { return(CreatedAtAction(nameof(GetRoleById), new { id = role.Id }, role)); } return(BadRequest(result)); }
public async Task <IActionResult> GiveUserRoleAsync(int idUser, AddRole role) { var user = _context.Users .SingleOrDefault(u => u.UserID == idUser); if (user == null) { return(NotFound()); } var identityUser = await _userManager.FindByIdAsync(user.IdentityID); await _userManager.AddToRoleAsync(identityUser, role.Name); return(Ok()); }
public static void CanAdd(Roles roles, AddRole command) { Guard.NotNull(command, nameof(command)); Validate.It(e => { if (string.IsNullOrWhiteSpace(command.Name)) { e(Not.Defined(nameof(command.Name)), nameof(command.Name)); } else if (roles.Contains(command.Name)) { e(T.Get("apps.roles.nameAlreadyExists")); } }); }
public static void CanAdd(Roles roles, AddRole command) { Guard.NotNull(command, nameof(command)); Validate.It(() => "Cannot add role.", e => { if (string.IsNullOrWhiteSpace(command.Name)) { e(Not.Defined("Name"), nameof(command.Name)); } else if (roles.ContainsKey(command.Name)) { e("A role with the same name already exists."); } }); }
public ActionResult Add(AddRole model) { try { if (ModelState.IsValid) { using (DBContext db = new DBContext()) { // role name already existed? var role = db.Roles.Where(r => string.Compare(r.RoleName, model.RoleName) == 0).FirstOrDefault(); if (role == null) { // role not existed, create new role role = new Role(); role.RoleName = model.RoleName; role.Description = model.Description; db.Roles.Add(role); db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", ""); return(View(model)); } } } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); // Write error log var log = new Log(); log.LogDate = DateTime.Now; log.Action = "Role - Add()"; log.Tags = "Error"; log.Message = ex.ToString(); db.Logs.Add(log); db.SaveChanges(); } return(View(model)); }
public async void NewRole() { Value = true; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { await Application.Current.MainPage.DisplayAlert( Languages.Warning, Languages.CheckConnection, Languages.Ok); return; } if (string.IsNullOrEmpty(Name)) { Value = true; return; } var role = new AddRole { name = Name }; var response = await apiService.Save <AddRole>( "https://app.smart-path.it", "/md-core", "/medial/role", role); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert("Error", response.Message, "ok"); return; } Value = false; MessagingCenter.Send((App)Application.Current, "OnSaved"); DependencyService.Get <INotification>().CreateNotification("Medial", "Role Added"); await App.Current.MainPage.Navigation.PopPopupAsync(true); }
public async Task <HttpResult <bool> > AddRole(Role entity, CancellationToken token = default(CancellationToken)) { var result = new HttpResult <bool>(); var model = new AddRole { Name = entity.Name, Claims = entity.Claims .Select(cl => new Common.DTO.Claim { Type = cl.Type, Value = cl.Value }) .ToList() }; await _unitOfWork.AddRole(model); return(result); }
public async Task <string> AddRoleAsync(AddRole addRole) { var user = await _userManager.FindByEmailAsync(addRole.Email); if (user == null) { return($"No Accounts Registered with {addRole.Email}."); } Type type = typeof(UserRole); var validRole = type.GetFields().Select(x => x.GetValue(addRole.Role).ToString()).FirstOrDefault(); if (!string.IsNullOrEmpty(validRole)) { await _userManager.AddToRoleAsync(user, validRole); return($"Added {addRole.Role} to user {addRole.Email}."); } return($"Role {addRole.Role} not found."); }
public async Task AddRole_should_create_events_and_update_state() { var command = new AddRole { Name = roleName }; await ExecuteCreateAsync(); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(1, sut.Snapshot.Roles.CustomCount); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppRoleAdded { Name = roleName }) ); }
public async Task AddRole(AddRole model) { await RunTaskInTransaction(async() => { var entity = new Data_Access_Layer.Role() { Name = model.Name }; await RoleRepository.Add(entity); await RoleClaimRepository .AddRange(model.Claims.Select(cl => new RoleClaim { Role = entity, ClaimType = cl.Type, ClaimValue = cl.Value })); return(string.Empty); }); }
public async Task <string> AddRoleAsync(AddRole model) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { return($"No Accounts Registered with {model.Email}."); } if (await _userManager.CheckPasswordAsync(user, model.Password)) { var roleExists = Enum.GetNames(typeof(Authorize.Roles)).Any(x => x.ToLower() == model.Role.ToLower()); if (roleExists) { var validRole = Enum.GetValues(typeof(Authorize.Roles)).Cast <Authorize.Roles>().Where(x => x.ToString().ToLower() == model.Role.ToLower()).FirstOrDefault(); await _userManager.AddToRoleAsync(user, validRole.ToString()); return($"Added {model.Role} to user {model.Email}."); } return($"Role {model.Role} not found."); } return($"Incorrect Credentials for user {user.Email}."); }
public ActionResult AddRole() { var userRoles = new List <AddRole>(); var context = new ApplicationDbContext(); var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); var allroles = new List <string>(); foreach (var i in context.Roles.ToList()) { if (i.Name != "Admin") { allroles.Add(i.Name); } } //Get all the usernames foreach (var user in userStore.Users) { if (!UserManager.IsInRole(user.Id, "Admin")) { var r = new AddRole { UserName = user.UserName }; userRoles.Add(r); } } //Get all the Roles for our users foreach (var user in userRoles) { user.RoleNames = userManager.GetRoles(userStore.Users.First(s => s.UserName == user.UserName).Id); user.AllRoles = allroles; } return(View(userRoles)); }
public async Task WarnPunish(int number, AddRole _, IRole role, StoopidTime time = null) { var punish = PunishmentAction.AddRole; var success = _service.WarnPunish(ctx.Guild.Id, number, punish, time, role); if (!success) { return; } if (time is null) { await ReplyConfirmLocalizedAsync("warn_punish_set", Format.Bold(punish.ToString()), Format.Bold(number.ToString())).ConfigureAwait(false); } else { await ReplyConfirmLocalizedAsync("warn_punish_set_timed", Format.Bold(punish.ToString()), Format.Bold(number.ToString()), Format.Bold(time.Input)).ConfigureAwait(false); } }
public void AddRole(AddRole command) { Raise(command, new AppRoleAdded()); }
public async Task <IActionResult> AddRoleAsync(AddRole model) { var result = await _userService.AddRoleAsync(model); return(Ok(result)); }
public UserReactedEvent(AddRole addRole, DiscordSocketClient client) { _addRole = addRole; _client = client; }
public UserJoinedEvent(AddRole addRole) { _addRole = addRole; }
public void AddRole(AddRole command) { RaiseEvent(SimpleMapper.Map(command, new AppRoleAdded())); }
private void AddRole(AddRole command) { Raise(command, new AppRoleAdded()); }
public async Task <Role> AddRole(AddRole addRole) { addRole.TenantId = User.Identity.GetTenantId().ToString(); return(await NexusService.Tenant.AddRole(addRole)); }