public void RemoveUserFromGroup(int groupId, string userId) { GroupUsers dbEntry = context.GroupUsers .FirstOrDefault(g => g.AppUserId == userId && g.GroupId == groupId); if (dbEntry != null) { context.GroupUsers.Remove(dbEntry); context.SaveChanges(); } Group group = context.Groups.FirstOrDefault(g => g.GroupId == groupId); group.UpdatedAt = DateTime.Now; context.SaveChanges(); }
public void AddUserToGroup(string userId, int groupId) { AppUser user = userManager.Users.FirstOrDefault(u => u.Id == userId); if (user != null) { Group group = context.Groups .FirstOrDefault(g => g.GroupId == groupId); if (group != null) { GroupUsers dbEntry = new GroupUsers { GroupId = group.GroupId, AppUserId = user.Id }; dbEntry.CreatedAt = DateTime.Now; dbEntry.UpdatedAt = DateTime.Now; context.GroupUsers.Add(dbEntry); context.SaveChanges(); group.UpdatedAt = DateTime.Now; context.SaveChanges(); } } }