public async Task <IActionResult> SaveEntity(AppRoleViewModel roleVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (!roleVm.Id.HasValue) { var result = await _roleService.AddAsync(roleVm); if (result == false) { return(new OkObjectResult(new GenericResult(false, roleVm))); } } else { var result = await _roleService.UpdateAsync(roleVm); if (result == false) { return(new OkObjectResult(new GenericResult(false, roleVm))); } } return(new OkObjectResult(new GenericResult(true, roleVm))); }
public async Task <IActionResult> SaveEntity(AppRoleViewModel roleVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (!roleVm.Id.HasValue) { var notificationId = Guid.NewGuid().ToString(); var announcement = new AnnouncementViewModel() { Title = "Role created", DateCreated = DateTime.Now, Content = $"Role {roleVm.Name} has been created", Id = notificationId, UserId = User.GetUserId() }; var announcementUsers = new List <AnnouncementUserViewModel>() { new AnnouncementUserViewModel() { AnnouncementId = notificationId, HasRead = false, UserId = User.GetUserId() } }; await _roleService.AddAsync(announcement, announcementUsers, roleVm); await _hubContext.Clients.All.SendAsync("ReceiveMessage", announcement); } else { await _roleService.UpdateAsync(roleVm); } return(new OkObjectResult(roleVm)); }
public async Task <ActionResult> CreateAsync(RoleModel role) { try { if (!string.IsNullOrEmpty(role.Libelle)) { bool exists = await _roleService.ExistsRole(HttpContext.Session, role.Libelle); if (exists) { ModelState.AddModelError(nameof(role.Libelle), "role already exists, please choose another"); } } if (!ModelState.IsValid) { return(View()); } await _roleService.AddAsync(HttpContext.Session, role); return(RedirectToAction("Index")); } catch { return(View()); } }
public virtual async Task <JsonResult> Add(Role model) { if (!ModelState.IsValid) { return(Json(new { IsSuccessful = false, Message = ModelState.GetModelError() })); } return(Json(await _roleSrv.AddAsync(model))); }
public async Task <ActionResult> Create(RoleViewModel roleViewModel) { if (ModelState.IsValid) { await _roleService.AddAsync(roleViewModel); return(RedirectToAction(nameof(Index))); } return(View(roleViewModel)); }
private async Task SeedRolesAsync() { foreach (var role in RolesList) { if (!await _roleService.ExistAsync(role.Name)) { await _roleService.AddAsync(role); } } }
public async Task <IActionResult> Add(RoleDto roleDto) { using (var logger = _loggerManager.CreateLogger()) { await _roleService.AddAsync(roleDto); logger.LogInformation($"Role {roleDto.RoleName} is added successfully."); return(Ok()); } }
public async Task <JsonResult> Add(Role role) { if (await _role.IsExistsName(role.Name)) { return(AjaxHelper.Seed(Ajax.Bad, "角色名已存在!")); } var entity = await _role.AddAsync(role); return(AjaxHelper.Seed(Ajax.Ok, entity)); }
// [Permission("افزودن نقش کاربر", ActionType.Insert)] public async Task <GeneralResult> Post([FromBody] RoleVM model) { var xErrors = await _roleService.AddAsync(model); if (xErrors.Any()) { return(Ok(null, xErrors)); } return(Ok(true)); }
public async Task <IActionResult> Create([FromBody] AppRoleViewModel appRoleViewModel) { if (appRoleViewModel == null || !ModelState.IsValid) { return(new BadRequestResult()); } await _roleService.AddAsync(appRoleViewModel); return(new OkResult()); }
public async Task <ActionResult> Create(CreateViewModel model) { if (!ModelState.IsValid) { return(View("_Create", model)); } await _roleService.AddAsync(model.RoleName); return(Content("Refresh")); }
public async Task <ServiceResult> SubmitAsync([FromBody] RoleInput input) { if (!string.IsNullOrWhiteSpace(input.Id)) { return(await _roleService.UpdateAsync(input.Id, input)); } else { return(await _roleService.AddAsync(input)); } }
public async Task <IActionResult> Create([FromBody] AppRoleViewModel appRoleViewModel) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(string.Join("\r\n", allErrors.Select(x => x.ErrorMessage)))); } await _roleService.AddAsync(appRoleViewModel); return(new NoContentResult()); }
public async Task SeedAsync() { await _roleService.AddAsync(new RoleViewModel { Name = "مدیر" }); await _roleService.AddAsync(new RoleViewModel { Name = "نویسنده" }); await _userService.AddAsync(new UserViewModel { FullName = "محمد جواد ابراهیمی", Password = "******", UserName = "******", SelectedRoles = new List <int> { 1 } }); await _userService.AddAsync(new UserViewModel { FullName = "کاربر تست", Password = "******", UserName = "******", SelectedRoles = new List <int> { 2 } }); var allActionFullNames = PermissionHelper.Tabs .SelectMany(tab => tab.Controllers.SelectMany(controller => controller.Actions.SelectMany(action => action.FullNames))) .Distinct().ToList(); var permissions = allActionFullNames.Select(p => new Permission { ActionFullName = p, RoleId = 1 }).ToList(); await _permissionService.AddRangeAsync(permissions); }
public async Task <ActionResult> Add(RoleDto dto) { if (ModelState.IsValid) { var result = await _roleService.AddAsync(dto); if (result.IsNotBlank()) { return(RedirectToAction("Index")); } } return(View(dto)); }
public async Task <ActionResult> CreateItemAsync([FromBody] RoleDTO role, CancellationToken cancellationToken) { InitUserInfo(); var newItem = _mapper.Map <Role>(role); newItem = await _roleService.AddAsync(newItem, cancellationToken); if (newItem == null) { AssignToModelState(_roleService.Errors); return(ValidationProblem()); } return(CreatedAtAction(nameof(ItemByIdAsync), new { id = newItem.Id }, null)); }
public async Task <ActionResult> AddRole(RoleNewViewModel role) { // 除了平台的超级管理员,其他管理员只能管理所属 Client 的资源 bool isSuper = User.IsSuperAdmin(); IEnumerable <string> allowedClientIds = null; if (!isSuper) { allowedClientIds = User.FindAll(JwtClaimTypes.ClientId).Select(itm => itm.Value); } await _roleService.AddAsync(_mapper.Map <RoleNewDto>(role), allowedClientIds); return(Ok()); }
public async Task <IActionResult> CreateRoleAsync([FromBody] RoleResource roleResource) { if (roleResource == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed to create a new role.", Detail = "The specified role resource was null", Instance = "ABA3B997-1B80-47FC-A72B-69BC0D8DFA93" }; return(BadRequest(problem)); } Role role = mapper.Map <RoleResource, Role>(roleResource); foreach (RoleScope roleScope in role.Scopes) { if (!roleService.isValidScope(roleScope.Scope)) { ProblemDetails problem = new ProblemDetails { Title = "Failed to create a new role.", Detail = $"The specified scope: {roleScope.Scope} is not valid.", Instance = "1F40D851-8A4C-41F6-917C-D876970D825F" }; return(BadRequest(problem)); } } try { await roleService.AddAsync(role).ConfigureAwait(false); roleService.Save(); return(Created(nameof(CreateRoleAsync), mapper.Map <Role, RoleResourceResult>(role))); } catch (DbUpdateException e) { Log.Logger.Error(e, "Database exception"); ProblemDetails problem = new ProblemDetails { Title = "Failed to save the new role.", Detail = "There was a problem while saving the role to the database.", Instance = "D56DBE55-57A1-4655-99C5-4F4ECEEE3BE4" }; return(BadRequest(problem)); } }
public async Task <IActionResult> SaveEntity(AppRoleViewModel roleVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (string.IsNullOrWhiteSpace(roleVm.Id)) { await _roleService.AddAsync(roleVm); } else { await _roleService.UpdateAsync(roleVm); } return(new OkObjectResult(roleVm)); }
public async Task <IActionResult> AddRole(RoleDTO roleDTO) { var response = await _role.AddAsync(roleDTO); //HATEOAS AND HYPERMEDIA response.Links = new List <Link>() { new Link { Rel = "Get-roles", Method = "GET", Href = Url.Link(nameof(AddRole), new { }) } , new Link { Rel = "Update-role", Method = "PUT", Href = Url.Link(nameof(UpdateRole), new { Id = roleDTO.RoleId }) } }; return(Ok(response)); }
public async Task <IActionResult> SaveEntity(AppRoleViewModel appRole) { if (!ModelState.IsValid) { var allError = ModelState.Values.SelectMany(e => e.Errors); return(new BadRequestObjectResult(allError)); } if (appRole.Id.HasValue) { await _roleService.UpdateAsync(appRole); } await _roleService.AddAsync(appRole); return(new OkObjectResult(appRole)); }
public async Task <IActionResult> SaveEntity(AppRoleViewModel roleViewModel) { if (!ModelState.IsValid) { var allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (!roleViewModel.Id.HasValue) { await _roleService.AddAsync(roleViewModel); } else { await _roleService.UpdateAsync(roleViewModel); } return(new OkObjectResult(roleViewModel)); }
public async Task <IActionResult> SaveEntity(AppRoleViewModel roleVm) { try { //if (!ModelState.IsValid) //{ // IEnumerable<ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); // return new BadRequestObjectResult(allErrors); //} //if (string.IsNullOrWhiteSpace(roleVm.Id.ToString()) || roleVm.Id == Guid.Empty) //if(!roleVm.Id.HasValue) //if (roleVm.Id == null) if (roleVm.Id == Guid.Empty) { var notificationId = Guid.NewGuid(); var announcement = new AnnouncementViewModel() { Title = "Role created", DateCreated = DateTime.Now, //Content = result ? $"Quyền {roleVm.Name} đã được tạo" : $"Quyền {roleVm.Name} tạo không thành công", Id = notificationId, OwnerId = User.GetUserId() }; var announcementUsers = new List <AnnouncementUserViewModel>() { new AnnouncementUserViewModel() { AnnouncementId = notificationId, HasRead = false, UserId = User.GetUserId() } }; await _roleService.AddAsync(announcement, announcementUsers, roleVm); await _hubContext.Clients.All.SendAsync("ReceiveMessage", announcement); } else { await _roleService.UpdateAsync(roleVm); } return(new OkObjectResult(roleVm)); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> SaveEntity(AppRoleViewModel roleVm) { var data = await _IUserService.GetUserWithRole("Admin"); if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (roleVm.Id == null) { var avatar = User.GetSpecificClaim("Avatar"); var notificationId = Guid.NewGuid().ToString(); var userId = User.GetUserId(); var announcement = new AnnouncementViewModel() { Title = "Role created", DateCreated = DateTime.Now, Content = $"Role {roleVm.Name} has been created", Id = notificationId, UserId = userId, Avartar = string.IsNullOrEmpty(avatar) ? "/admin-side/images/user.png" : avatar }; await _announcementService.AnnounSendUser(userId, announcement, data); foreach (var item in data) { if (item.Id != userId) { var announcementUser = null as AnnouncementUserViewModel; if (item.Id != userId) { await _hubContext.Clients.User(item.Id.ToString()).SendAsync("ReceiveMessage", announcement); } } } await _roleService.AddAsync(roleVm); } else { await _roleService.UpdateAsync(roleVm); } return(new OkObjectResult(roleVm)); }
public async Task TestMutipleTrans(UserDto userDto) { User entity = Mapper.Map <User>(userDto); User entity1 = Mapper.Map <User>(userDto); if (entity.Id > 0) { await this.DeleteByIdAsync(entity.Id); } entity.LastModifyDate = DateTime.Now; await this.AddAsync(entity); await Daos["sfdb1"].AddAsync(entity1); await roleService.AddAsync(new RoleDto { Name = "role01", Code = "001", CreateDate = DateTime.Now }); throw new Exception("ss"); }
public async Task <IActionResult> SaveEntity(RoleViewModel roleVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } bool kt = false; if (!roleVm.Id.HasValue) { kt = await _roleService.AddAsync(roleVm); } else { kt = true; await _roleService.UpdateAsync(roleVm); } return(new OkObjectResult(kt)); }
public async Task <IActionResult> SaveEntity(AppRoleViewModel appRoleViewModel) { if (ModelState.IsValid) { if (appRoleViewModel.Id == null) { await _roleService.AddAsync(appRoleViewModel); } else { await _roleService.UpdateAsync(appRoleViewModel); } } else { IEnumerable <ModelError> modelErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(modelErrors)); } return(new OkObjectResult(appRoleViewModel)); }
public async Task <IActionResult> SaveEntity(AppRoleViewModel roleVm) { if (ModelState.IsValid) { if (!roleVm.Id.HasValue) { await _roleService.AddAsync(roleVm); } else { await _roleService.UpdateAsync(roleVm); } return(new OkObjectResult(new GenericResult(true))); } else { List <string> listErrors = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage).ToList(); string errorString = String.Join("\n", listErrors.ToArray()); return(new OkObjectResult(new GenericResult(false, errorString))); } }
public async Task <IActionResult> SaveEntity(AppRoleViewModel roleViewModel) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (!roleViewModel.Id.HasValue) { var announcementId = Guid.NewGuid().ToString(); var announcement = new AnnouncementViewModel() { Title = "Tạo mới role", DateCreated = DateTime.Now, Content = $"Role {roleViewModel.Name} đã được thêm mới !", Id = announcementId, UserId = User.GetUserId() }; var announcementUser = new List <AnnouncementUserViewModel>() { new AnnouncementUserViewModel() { AnnouncementId = announcementId, HasRead = false, UserId = User.GetUserId() } }; await _roleService.AddAsync( _mapper.Map <AnnouncementViewModel, Announcement>(announcement), _mapper.Map <List <AnnouncementUserViewModel>, List <AnnouncementUser> >(announcementUser), _mapper.Map <AppRoleViewModel, AppRole>(roleViewModel)); } else { await _roleService.UpdateAsync(_mapper.Map <AppRoleViewModel, AppRole>(roleViewModel)); } return(new OkObjectResult(roleViewModel)); }
private async void btnThem_Click(object sender, EventArgs e) { if (btnThem.Text.Equals("Save")) { if (!IsValid()) { MessageBox.Show("Bạn phải nhập thông tin đầy đủ !"); btnThem.Text = "Save"; return; } save_Roles(); var kq = await _roleService.AddAsync(_appRoleViewModel); if (kq) { FormHelper.showSuccessDialog("Thêm Roles Thành Công", "Thành Công"); } else { MessageBox.Show("Thêm User Không Thành Công", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } btnThem.Text = "Thêm nhóm quyền"; EnableFalseControl(); ResetControl(); gv_NhomQuyen.Enabled = true; setBtnBack_False(); await LoadGvRoles(); } else // Add { setBtnBack_True(); btnThem.Text = "Save"; btnSua.Enabled = false; btnXoa.Enabled = false; gv_NhomQuyen.Enabled = false; EnableTrueControl(); ResetControl(); } }