public async Task <OutResult> AddPermissionToGroup(int groupId, int permissionId) { var group = await GetById(groupId); if (!group.Any()) { return(OutResult.Failed("Group not found")); } var permission = _permissionManager.Roles.Where(x => x.Id == permissionId); if (!permission.Any()) { return(OutResult.Failed("Permission not found")); } var groupToAdd = group.First(); var permissionToAdd = permission.First(); var groupPermission = new GroupPermission() { Group = groupToAdd, Permission = permissionToAdd, GroupId = groupId, PermissionId = permissionId }; if (groupToAdd.GroupPermissions.Contains(groupPermission)) { return(OutResult.Failed("Group Already have Permission")); } var permissionResult = await _groupPermissionRepository.Insert(groupPermission); var groupUsers = groupToAdd.UsersInGroup.Select(x => x.User); foreach (var user in groupUsers) { if (!await _applicationUserManager.IsInRoleAsync(user, permissionToAdd.Name)) { await _applicationUserManager.AddToRoleAsync(user, permissionToAdd.Name); } } return(OutResult.Success_Updated()); }
public virtual async Task <OutResult> Update(T entity) { try { if (entity == null) { return(OutResult.Error_TryingToUpdateNull()); } AddUpdateEntityWithDateTime(entity); this.Entities.Update(entity); await this._context.SaveChangesAsync(); } catch (Exception dbEx) { var error = $"Failed while updating " + typeof(T).FullName + ":: " + GetFullErrorText(dbEx); return(new OutResult(error, dbEx.ToString(), false)); } return(OutResult.Success_Updated()); }