public async Task <Boolean> AddRoleOfGroupMember(string userName, string groupId, string roleName) { var groups = context.groups.Where(x => x.GroupId.ToString() == groupId).FirstOrDefault(); if (groups == null) { return(false); /// groups not create } var users = await userManager.FindByNameAsync(userName); var role = await roleManager.FindByNameAsync(roleName); if (users == null || role == null) { return(false); /// username is not exist } UsersGroups usersGroups = new UsersGroups { Groups = groups, IdentityUser = users, IdentityRole = role }; await context.usersGroups.AddAsync(usersGroups); // add user and group in usergroup table await save(); return(true); }
public async Task <IActionResult> Edit(int id, [Bind("UserId,GroupId")] UsersGroups usersGroups) { if (id != usersGroups.UserId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(usersGroups); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsersGroupsExists(usersGroups.UserId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["GroupId"] = new SelectList(_context.Group, "Id", "Id", usersGroups.GroupId); ViewData["UserId"] = new SelectList(_context.User, "Id", "Id", usersGroups.UserId); return(View(usersGroups)); }
public override int GetHashCode() { unchecked { return(((UsersGroups != null ? UsersGroups.GetHashCode() : 0) * 397) ^ IncludeCurrentUser.GetHashCode()); } }
public async Task <IActionResult> CreateGroup([FromBody] CreateGroupModel groupModel) { try { var user = await _context.Users .FirstOrDefaultAsync(x => x.UserName.Equals(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value)); var group = new Group(); group.Name = groupModel.GroupName; _context.Groups.Add(group); await _context.SaveChangesAsync(); var userGroups = new UsersGroups(); userGroups.UserId = user.Id; userGroups.GroupId = group.Id; _context.UsersGroups.Add(userGroups); await _context.SaveChangesAsync(); group.Users = new List <UsersGroups>() { userGroups }; return(new OkObjectResult(group.MapGroupToModel(_context, User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value))); } catch (Exception ex) { throw ex; } }
private async void LoadUsersGroups() { List <UserGroup> userGroups = await UsersGroups.GetList(); txtGrupo.ItemsSource = userGroups; txtGrupo.DisplayMemberPath = "Name"; txtGrupo.SelectedValuePath = "Id"; txtGrupo.SelectedValue = "user"; }
protected void DeletePermission(UsersGroups userGroup, IList functionsList) { foreach (Functions function in functionsList) { if (userGroup.FunctionsList.Contains(function)) { userGroup.FunctionsList.Remove(function); } } (crudForm as UsersGroupsCRUD).RefreshPermissionsList(); }
public bool AddUserGroup(UsersGroups UG, string InsertUser) { bool rpta = false; try { SqlCon.Open(); var SqlCmd = new SqlCommand("[adm].[uspAddUserGroup]", SqlCon) { CommandType = CommandType.StoredProcedure }; //Insert Parameters SqlParameter pUserID = new SqlParameter { ParameterName = "@UserID", SqlDbType = SqlDbType.Int, Value = UG.UserID }; SqlCmd.Parameters.Add(pUserID); SqlParameter pGroupID = new SqlParameter { ParameterName = "@GroupID", SqlDbType = SqlDbType.Int, Value = UG.GroupID }; SqlCmd.Parameters.Add(pGroupID); SqlParameter ParInsertUser = new SqlParameter { ParameterName = "@InsertUser", SqlDbType = SqlDbType.VarChar, Size = 50, Value = InsertUser }; SqlCmd.Parameters.Add(ParInsertUser); //Exec Command SqlCmd.ExecuteNonQuery(); rpta = true; } catch (Exception ex) { throw ex; } if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } return(rpta); }
public async Task <IActionResult> Create([Bind("UserId,GroupId")] UsersGroups usersGroups) { if (ModelState.IsValid) { _context.Add(usersGroups); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["GroupId"] = new SelectList(_context.Group, "Id", "Id", usersGroups.GroupId); ViewData["UserId"] = new SelectList(_context.User, "Id", "Id", usersGroups.UserId); return(View(usersGroups)); }
public async Task AddUserToGroup(string userId, string groupId) { var user = await this.userManager.FindByIdAsync(userId); var group = this.groupRepo.AllAsNoTracking().Where(x => x.Id == groupId).FirstOrDefault(); var userGroup = new UsersGroups { User = user, Group = group }; await this.usersGroupsRepo.AddAsync(userGroup); await this.usersGroupsRepo.SaveChangesAsync(); }
public async Task <IActionResult> AddUserToGroup(string id, string userId) { try { var permissionExists = await _context.UsersGroups .Include(x => x.User) .FirstOrDefaultAsync(x => x.GroupId.ToString().Equals(id) && x.User.UserName.Equals(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value)); if (permissionExists == null) { return(new BadRequestObjectResult(new List <ErrorViewModel>() { new ErrorViewModel() { Code = "NotAllowed", Description = "Action is not allowed." } })); } var userExists = await _context.UsersGroups .FirstOrDefaultAsync(x => x.GroupId.ToString().Equals(id) && x.UserId.Equals(userId)); if (userExists != null) { return(new BadRequestObjectResult(new List <ErrorViewModel>() { new ErrorViewModel() { Code = "UserExists", Description = "User is already group member." } })); } var userGroups = new UsersGroups(); userGroups.UserId = userId; userGroups.GroupId = new Guid(id); _context.UsersGroups.Add(userGroups); await _context.SaveChangesAsync(); return(NoContent()); } catch (Exception ex) { throw ex; } }
public List <UsersGroups> UserList(int GroupID) { List <UsersGroups> List = new List <UsersGroups>(); try { SqlCon.Open(); var SqlCmd = new SqlCommand("[config].[uspReadUsersGroups]", SqlCon) { CommandType = CommandType.StoredProcedure }; SqlParameter pID = new SqlParameter { ParameterName = "@GroupID", SqlDbType = SqlDbType.Int, Value = GroupID }; SqlCmd.Parameters.Add(pID); using (var dr = SqlCmd.ExecuteReader()) { while (dr.Read()) { var detail = new UsersGroups { UserGroupID = Convert.ToInt32(dr["UserGroupID"]), GroupID = Convert.ToInt32(dr["GroupID"]), UserID = Convert.ToInt32(dr["UserID"]), FullName = dr["FullName"].ToString() }; List.Add(detail); } } } catch (Exception ex) { throw ex; } if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } return(List); }
static void Main(string[] args) { //Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ApplicationDBContext>()); Database.SetInitializer(new MigrateDatabaseToLatestVersion <ApplicationDBContext, Configuration>()); using (ApplicationDBContext dbContext = new ApplicationDBContext()) { var userOne = new User() { Name = "Alisher" }; var groupOne = new Group() { Name = "SHAG IN VK" }; dbContext.Users.Add(userOne); dbContext.Groups.Add(groupOne); dbContext.SaveChanges(); var recordOfEntry = new UsersGroups() { UserId = userOne.Id, GroupId = groupOne.Id, IsActiveMember = true, EnteredDate = DateTime.Now, RoleHistory = new List <UserInGroupHistory> { new UserInGroupHistory() { RoleName = "Student" } } }; dbContext.UsersInGroups.Add(recordOfEntry); dbContext.SaveChanges(); } Console.ReadLine(); }
public bool RemoveUG(UsersGroups UG, string InsertUser) { return(GDAL.RemoveUG(UG, InsertUser)); }
public bool AddUserGroup(UsersGroups UG, string InsertUser) { return(GDAL.AddUserGroup(UG, InsertUser)); }