public async Task <TaskResult <RolesDto> > SaveAsync(RolesDto roleDto) { var guid = Guid.NewGuid(); var role = new IdentityRole { Id = guid.ToString(), Name = roleDto.Name }; var result = new TaskResult <RolesDto>(); try { _context.Roles.Add(role); await _context.SaveChangesAsync(); result.Message = $"Se agregó el role {role.Name}"; } catch (Exception e) { result.Success = false; result.Message = $"Error al intentar agregar al Role: {e.Message}"; } return(result); }
private static RolesDto ConvertFromRepositoryEntity(Roles accountRoles) { if (accountRoles == null) { return(null); } var rolesDto = new RolesDto { Id = accountRoles.Id, HotelID = accountRoles.HotelID, RoleID = accountRoles.RoleID, Title = accountRoles.Title, Description = accountRoles.Description }; if (accountRoles.CreateTime != null) { rolesDto.CreateTime = accountRoles.CreateTime.Value; } else { rolesDto.CreateTime = DateTime.MinValue; } if (accountRoles.UpdateTime != null) { rolesDto.UpdateTime = accountRoles.UpdateTime.Value; } else { rolesDto.UpdateTime = DateTime.MinValue; } return(rolesDto); }
private static Roles ConvertFromDto(RolesDto rolesDto) { if (rolesDto == null) { return(null); } var accountRole = new Roles { Id = rolesDto.Id, HotelID = rolesDto.HotelID, RoleID = rolesDto.RoleID, Title = rolesDto.Title, Description = rolesDto.Description }; if ((rolesDto?.CreateTime ?? DateTime.MinValue) > DateTime.MinValue) { accountRole.CreateTime = rolesDto.CreateTime; } if ((rolesDto?.UpdateTime ?? DateTime.MinValue) > DateTime.MinValue) { accountRole.UpdateTime = rolesDto.UpdateTime; } return(accountRole); }
public async Task <TaskResult <RolesDto> > UpdateAsync(RolesDto roleDto) { var roles = new IdentityRole { Id = roleDto.Id, Name = roleDto.Name }; var result = new TaskResult <RolesDto>(); try { _context.Roles.Add(roles); _context.Entry(roles).State = System.Data.Entity.EntityState.Modified; await _context.SaveChangesAsync(); result.Data = roleDto; result.Message = "El registro fue actualizado correctamente"; } catch (Exception e) { result.Success = false; result.Message = $"Error al intentar actualizar información del role: {e.Message}"; } return(result); }
public async Task <int> AddRoles(RolesDto model) { return(await _service.AddAsync(new Roles() { RolesName = model.RolesName })); }
public ActionResult <RolesDto> GetRights() { var claimsIdentity = User.Identity as ClaimsIdentity; var roles = new RolesDto(); if (claimsIdentity == null || !claimsIdentity.IsAuthenticated) { return(roles); } else { roles.IsConnected = true; } var userRole = claimsIdentity.FindFirst(ClaimTypes.Role).Value; switch (userRole) { case "admin": roles.IsAdmin = true; break; case "groom": roles.IsGroom = true; break; case "secretary": roles.IsSecretary = true; break; } return(roles); }
public async Task <IActionResult> UpdateUserRoles(Guid userID, RolesDto userRoles) { var user = await this.Repository.GetUserWithRoles(userID); var addedRoles = userRoles.Roles; var removedRoles = new List <string>(); foreach (var role in user.UserRoles) { if (userRoles.Roles.Any(roleName => roleName.Equals(role.Role.Name, StringComparison.InvariantCultureIgnoreCase))) { addedRoles.Remove(role.Role.Name); } else { removedRoles.Add(role.Role.Name); } } var addResult = await this.UserManager.AddToRolesAsync(user, addedRoles); if (addResult.Succeeded == false) { return(this.BadRequest(addResult.Errors)); } var removeResult = await this.UserManager.RemoveFromRolesAsync(user, removedRoles); if (removeResult.Succeeded == false) { return(this.BadRequest(removeResult.Errors)); } return(this.Ok()); }
public async Task <bool> UpdateAsync(RolesDto role) { var rolemapp = _mapper.Map <AppRole>(role); //for some strange reason it doesn not work since it give a tracking error... var rs = await _roleManager.UpdateAsync(rolemapp); return(rs.Succeeded); }
public async Task <bool> CreateAsync(RolesDto model) { var role = new AppRole(); var map = _mapper.Map(model, role); var rs = await _roleManager.CreateAsync(map); return(rs.Succeeded); }
//编辑 public static int Update(RolesDto model) { // UsersDto users; using (IDbConnection conn = MySqlConnection()) { return(conn.Execute("update role set Name=@Name where Id=@Id", model)); } }
public IActionResult GetRoles(string app) { var response = RolesDto.FromApp(App); Response.Headers[HeaderNames.ETag] = App.Version.ToString(); return(Ok(response)); }
private async Task <RolesDto> InvokeCommandAsync(ICommand command) { var context = await CommandBus.PublishAsync(command); var result = context.Result <IAppEntity>(); var response = RolesDto.FromApp(result, this); return(response); }
public async Task <ActionResult> Update([FromBody] RolesDto role) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var rs = await _rolesService.UpdateAsync(role); return(Ok(rs)); }
public IActionResult GetRoles(string app) { var response = Deferred.Response(() => { return(RolesDto.FromApp(App, this)); }); Response.Headers[HeaderNames.ETag] = App.ToEtag(); return(Ok(response)); }
//插入 public static int Insert(RolesDto model) { int result; using (IDbConnection conn = MySqlConnection()) { result = conn.Execute("Insert into role values (@Id,@Name)", model); } return(result); }
public int Update(RolesDto model) { if (model == null) { return(0); } else { var accountRole = ConvertFromDto(model); return(_userRepository.UpdateNonDefaults(accountRole, x => x.Id == accountRole.Id)); } }
public bool Add(RolesDto model) { if (model == null) { return(false); } else { var account = ConvertFromDto(model); return(_userRepository.Insert(account) > 0); } }
public async Task <ActionResult> Edit(RolesDto Data) { if (!ModelState.IsValid) { return(View(new TaskResult <RolesDto> { Data = Data })); } var model = await _rolesRepository.UpdateAsync(Data); return(View(model)); }
public async Task <IActionResult> Post([FromBody] RolesDto roleDto) { if (!User.Identity.IsAuthenticated) { throw new AuthenticationException(); } var role = _mapper.Map <Roles>(roleDto); await _roleService.InsertRole(role); roleDto = _mapper.Map <RolesDto>(role); var response = new ApiResponse <RolesDto>(roleDto); return(Ok(response)); }
public async Task <IActionResult> Put(int id, RolesDto roleDto) { if (!User.Identity.IsAuthenticated) { throw new AuthenticationException(); } var role = _mapper.Map <Roles>(roleDto); role.Id = id; var result = await _roleService.UpdateRole(role); var response = new ApiResponse <bool>(result); return(Ok(response)); }
public async Task <IActionResult> EditRoles(string username, RolesDto roles) { var user = await _userManager.FindByNameAsync(username); var currentRoles = _userManager.GetRolesAsync(user); if (roles.isAdmin && !currentRoles.Result.Contains("Admin")) { var result = await _userManager.AddToRoleAsync(user, "Admin"); if (!result.Succeeded) { return(BadRequest("Failed to add admin role")); } } else if (!roles.isAdmin && currentRoles.Result.Contains("Admin")) { var result = await _userManager.RemoveFromRoleAsync(user, "Admin"); if (!result.Succeeded) { return(BadRequest("Failed to remove admin role")); } } if (roles.isModerator && !currentRoles.Result.Contains("Moderator")) { var result = await _userManager.AddToRoleAsync(user, "Moderator"); if (!result.Succeeded) { return(BadRequest("Failed to add moderator role")); } } else if (!roles.isModerator && currentRoles.Result.Contains("Moderator")) { var result = await _userManager.RemoveFromRoleAsync(user, "Moderator"); if (!result.Succeeded) { return(BadRequest("Failed to remove moderator role")); } } var x = await _userManager.GetRolesAsync(user); return(Ok(x)); }
public TeamEmployeeDto TeamEmployeeDetails(int teamID) { TeamEmployeeDto teamEmpDetail = new TeamEmployeeDto(); List <EmployeeDto> teamEmp = new List <EmployeeDto>(); try { var Team = Context.TeamDetails .FirstOrDefault(td => td.TeamID == teamID); var TeamEmployee = Context.Employees .Include(emp => emp.employeeRoles) .Where(emp => emp.TeamDetails.TeamID == Team.TeamID) .ToList(); teamEmpDetail.TeamId = Team.TeamID; teamEmpDetail.TeamName = Team.TeamName; teamEmpDetail.LeadName = Team.TeamLeadName; teamEmpDetail.TeamDiscription = Team.TeamDiscription; foreach (Employee emp in TeamEmployee) { EmployeeDto empDto = new EmployeeDto(); RolesDto roleDto = new RolesDto(); empDto.EmployeeId = emp.EmployeeId; empDto.FirstName = emp.FirstName; empDto.LastName = emp.LastName; empDto.PhotoUrl = emp.EmployeePhotoURL; empDto.Dob = emp.Dob; empDto.JoiningDate = emp.JoiningDate; empDto.EmailId = emp.EmailID; roleDto.RoleName = emp.employeeRoles.RoleName; empDto.Role = roleDto; teamEmp.Add(empDto); } teamEmpDetail.TeamEmployees = teamEmp; } catch (SqlException expSql) { throw expSql; } catch (NullReferenceException expNull) { throw expNull; } return(teamEmpDetail); }
public JsonResult Create(RolesDto item) { OperationResult r = new OperationResult(); try { item.Id = Guid.NewGuid().ToString(); Roles.Insert(item); r.ResultType = OperationResultType.Success; } catch (Exception ex) { r.Message = "新增失败,请检查所填数据是否正确。"; r.ResultType = OperationResultType.Error; } return(Json(r)); }
private static RolesDto ConvertFromBllEntity(AccountsRoles accountRoles) { if (accountRoles == null) { return(null); } RolesDto accountDto = new RolesDto() { Id = accountRoles.Id, HotelID = accountRoles.HotelID, RoleID = accountRoles.RoleID, Description = accountRoles.Description, Title = accountRoles.Title }; return(accountDto); }
private static AccountsRoles ConvertFromDto(RolesDto rolesDto) { if (rolesDto == null) { return(null); } AccountsRoles user = new AccountsRoles() { Id = rolesDto.Id, HotelID = rolesDto.HotelID, RoleID = rolesDto.RoleID, Description = rolesDto.Description, Title = rolesDto.Title }; return(user); }
public ActionResult UpdateRole(RolesDto model) { var result = new StandardJsonResult <string>(); result.Try(() => { if (!ModelState.IsValid) { throw new KnownException(ModelState.GetFirstError()); } var service = Ioc.GetService <IRolesManagementService>(); model.OwnerID = ""; bool i = service.UpdateRole(model); result.Value = i + ""; }); return(result); }
public JsonResult Edit(RolesDto item) { OperationResult r = new OperationResult(); try { Roles.Update(item); r.ResultType = OperationResultType.Success; } catch { r.Message = "失败,请检查数据。"; r.ResultType = OperationResultType.Error; } return(Json(r)); }
public IActionResult GetPerson(int id) { var Person = Roles.SingleOrDefault(x => x.id == id); if (Person == null) { logger.LogInformation($"Person with {id} was not found"); return(NotFound()); } var result = new RolesDto { id = Person.id, name = Person.name, shortName = Person.shortName, }; return(Ok(result)); }
public async Task <IActionResult> AddRolesToUser([FromRoute] string userId, [FromBody] RolesDto addRoles, CancellationToken ct) { var user = await _userManager.FindByIdAsync(userId); if (user == null) { return(NotFound()); } var currentRoles = await _userManager.GetRolesAsync(user); await _userManager.RemoveFromRolesAsync(user, currentRoles.ToArray()); await _userManager.AddToRolesAsync(user, addRoles.Roles.ToArray()); var finalRoles = await _userManager.GetRolesAsync(user); return(Ok(finalRoles)); }
public IActionResult AddNewRole([FromBody] RolesDto newRole, [FromHeader(Name = "id_token")] string googleToken) { try { if (googleAuth.ProcessRequestAtGoogle(googleToken)) { var RoleAddStatus = empRepository.AddRole(newRole); return(Ok(Json(RoleAddStatus))); } else { return(BadRequest()); } } catch (Exception exp) { return(NotFound(@"Can't add the given Department")); } }