public async Task <IActionResult> Profile() { // Initialize the GraphServiceClient. Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.ScopeUserRead }); var me = await graphClient.Me.Request().GetAsync(); ViewData["Me"] = me; try { // Get user photo using (var photoStream = await graphClient.Me.Photo.Content.Request().GetAsync()) { byte[] photoByte = ((MemoryStream)photoStream).ToArray(); ViewData["Photo"] = Convert.ToBase64String(photoByte); } } catch (System.Exception) { ViewData["Photo"] = null; } return(View()); }
public async Task <IActionResult> RiskyUsers() { // Initialize the GraphServiceClient. Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.ScopeUserRead }); var riskyUsers = await graphClient.RiskyUsers.Request().GetAsync(); ViewData["riskyUsers"] = riskyUsers; RiskyUsersViewModel.RiskyUsers = (ViewData["riskyUsers"] as IList <Graph.RiskyUser>); return(View()); }
public async Task <IActionResult> Users() { // Initialize the GraphServiceClient. Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { GraphScopes.UserReadBasicAll }); var users = await graphClient.Users.Request().GetAsync(); ViewData["Users"] = users.CurrentPage; return(View()); }
public async Task <IActionResult> SignIns() { // Initialize the GraphServiceClient. Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.ScopeUserRead }); var signIns = await graphClient.AuditLogs.SignIns.Request().GetAsync(); ViewData["signIns"] = signIns; SignInsViewModel.SignIns = (ViewData["signIns"] as IList <Graph.SignIn>); return(View()); }
private async Task <Room> GetRoomData(Room room, DateTime dt, string tenantId) { var identifier = User.FindFirst(Startup.ObjectIdentifierType)?.Value; var azureOptions = new AzureAdOptions(); _configuration.Bind("AzureAd", azureOptions); if (room.HasMailBox) { Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { "Calendars.Read.Shared" }, tenantId); room = await GraphService.GetRoomAvailability(graphClient, room, HttpContext, dt); } if (_tenantConfig.bGridConfig.bGridUser != "") { var roomOccupancies = await GetbGridOccupancies(); var roomTemperatures = await GetbGridTemperatures(); if (room.Nodes != null) { var roomNodes = roomOccupancies.Where(r => room.Nodes.Where(ro => ro.Id == r.location_id.ToString()).Count() > 0); if (roomNodes != null) { var occupiedNodes = roomNodes.Where(nodes => nodes.value == 2); room.Occupied = occupiedNodes == null ? -1 : occupiedNodes.Count() > 0 ? 2 : 0; //Get Associated Island //var islands = _bGridIslands.Where(i => i.locations.Any(l => room.Nodes.Any(n => Convert.ToInt32(n.Id).Equals(l)))); //if(islands != null) //{ // room.Island = islands.First(); //} } var roomNodesTemp = roomTemperatures.Where(r => room.Nodes.Where(ro => ro.Id == r.location_id.ToString()).Count() > 0); if (roomNodesTemp != null) { var roomNodesTempLatest = roomNodesTemp.GroupBy(r => r.location_id).Select(ro => ro.OrderByDescending(x => x.timestamp).FirstOrDefault()); if (roomNodesTemp.Count() > 0) { var avgTemp = roomNodesTemp.Average(r => Convert.ToDecimal(r.value)); room.Temperature = avgTemp; } } } } return(room); }
public async Task <List <Group> > GetGroups() { if (CurrentGroupsFromGraph.Count == 0) { Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { Infrastructure.Constants.ScopeUserRead }); var myGroups = await graphClient.Me.GetMemberGroups(false).Request().PostAsync(); foreach (var group in myGroups.CurrentPage) { var results = await graphClient.Groups.Request().Filter($"Id eq '{group}'").GetAsync(); CurrentGroupsFromGraph.AddRange(results.CurrentPage); } } return(CurrentGroupsFromGraph); }
public async Task <IViewComponentResult> InvokeAsync() { Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.ScopeUserRead }); try { // Get user photo var photoStream = await graphClient.Me.Photo.Content.Request().GetAsync(); byte[] photoByte = ((MemoryStream)photoStream).ToArray(); ViewData["Photo"] = Convert.ToBase64String(photoByte); } catch (System.Exception ex) { } return(View()); }
private async Task <Usr> GetProfileProperties() { Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.ScopeUserRead }); try { // Get users properties var me = await graphClient.Me.Request().Select(e => new { e.DisplayName, e.Mail }) .GetAsync(); return(new Usr { Email = me.Mail, Name = me.DisplayName }); } catch (System.Exception ex) { return(null); } }
public async Task <List <Group> > GetGroups() { try { if (CurrentGroupsFromGraph.Count == 0) { Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { Infrastructure.Constants.ScopeUserRead }); var myGroups = await graphClient.Me.GetMemberGroups(false).Request().PostAsync(); foreach (var group in myGroups.CurrentPage) { var results = await graphClient.Groups.Request().Filter($"Id eq '{group}'").GetAsync(); CurrentGroupsFromGraph.AddRange(results.CurrentPage); } } } catch (Exception e) { Console.WriteLine("Could not get groups from GRAPH" + e.ToString()); } return(CurrentGroupsFromGraph); }
public async Task <IActionResult> Index() { var ADemail = User.Identity.Name; //Console.WriteLine(ADemail); var LocalUserEmail = _context.LocalUser .FromSqlRaw("SELECT * FROM dbo.LocalUser where LocalUserID={0}", ADemail) .ToList(); var c = LocalUserEmail.Count; if (c == 0) { //Console.WriteLine("Creating Local User"); Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.ScopeUserRead }); var me = await graphClient.Me.Request().GetAsync() as Microsoft.Graph.User; var properties = me.GetType().GetProperties(); IDictionary <string, string> LocalUserAttributes = new Dictionary <string, string>(); foreach (var child in properties) { object value = child.GetValue(me); string stringRepresentation; if (value is string) { stringRepresentation = value?.ToString(); } else { stringRepresentation = ""; } if (child.Name == "OnPremisesSamAccountName") { LocalUserAttributes.Add("NetID", stringRepresentation); } else if (child.Name == "GivenName") { LocalUserAttributes.Add("FirstName", stringRepresentation); } else if (child.Name == "Surname") { LocalUserAttributes.Add("LastName", stringRepresentation); } else if (child.Name == "Mail") { LocalUserAttributes.Add("EmailID", stringRepresentation); } } //ViewData["Me"] = me; var CreateUser = new LocalUser { LocalUserID = LocalUserAttributes["EmailID"], FirstName = LocalUserAttributes["FirstName"], LastName = LocalUserAttributes["LastName"], EmailID = LocalUserAttributes["NetID"] }; _context.Add(CreateUser); EmailPreference e_pref = new EmailPreference { LocalUserID = CreateUser.LocalUserID, CaseCreation = true, CaseAssignment = true, GroupAssignment = true, CommentCreation = true, AttachmentCreation = true, CaseProcessed = true, CasesCreatedByUser = true, CasesAssignedToUser = false, CasesAssignedToUsersGroups = false }; _context.Add(e_pref); await _context.SaveChangesAsync(); /* * Console.WriteLine("Created"); * Console.WriteLine(LocalUserAttributes["NetID"]); * Console.WriteLine(LocalUserAttributes["FirstName"]); * Console.WriteLine(LocalUserAttributes["LastName"]); * Console.WriteLine(LocalUserAttributes["EmailID"]); */ } else { //Console.WriteLine("User Already Exists!"); } // Populate or Check validity of User's group membership var UsersLGroups = _context.UserGroup .Where(m => m.LocalUserID == ADemail) .ToList(); HashSet <string> UsersLocalGroups = new HashSet <string>(); foreach (var g in UsersLGroups) { UsersLocalGroups.Add(g.LocalGroupID); } HashSet <string> UsersRetrievedGroups = new HashSet <string>(); foreach (var claim in User.Claims) { if (claim.Type == "groups") { UsersRetrievedGroups.Add(claim.Value); } } HashSet <string> AllLocalGroups = new HashSet <string>(); var AllGroups = _context.LocalGroup.ToList(); foreach (var g in AllGroups) { AllLocalGroups.Add(g.LocalGroupID); } HashSet <string> GroupsToBeAdded = new HashSet <string>(); HashSet <string> GroupsToBeRemoved = new HashSet <string>(); // Check for every groups that is associated with our application (Resolve) foreach (var group in AllLocalGroups) { if (UsersRetrievedGroups.Contains(group)) { if (UsersLocalGroups.Contains(group)) { } else { GroupsToBeAdded.Add(group); } } else { if (UsersLocalGroups.Contains(group)) { GroupsToBeRemoved.Add(group); } else { } } } foreach (var g in GroupsToBeAdded) { var test = new UserGroup { LocalGroupID = g, LocalUserID = ADemail }; _context.Add(test); } foreach (var g in GroupsToBeRemoved) { var test = _context.UserGroup.Single(b => b.LocalUserID == ADemail && b.LocalGroupID == g); _context.Remove(test); } await _context.SaveChangesAsync(); // Cases created by the User(or on behalf of user), assigned to the User, and assigned to the groups to which the User belongs to var UCases = await _context.LocalUser // Created by the User .Include(s => s.Cases.Where(p => p.Processed == 0)) .ThenInclude(w => w.CaseType) // Including Approvers .Include(s => s.Cases.Where(p => p.Processed == 0)) .ThenInclude(w => w.Approvers) .ThenInclude(w => w.LocalUser) // Created on behalf of the User .Include(s => s.OnBehalves.Where(p => p.Case.Processed == 0)) .ThenInclude(s => s.Case) .ThenInclude(s => s.CaseType) // Including Approvers .Include(s => s.OnBehalves.Where(p => p.Case.Processed == 0)) .ThenInclude(s => s.Case) .ThenInclude(s => s.Approvers) .ThenInclude(w => w.LocalUser) // Assigned to the User .Include(q => q.CasesforApproval.Where(p => p.Case.Processed == 0 && p.Approved == 0)) .ThenInclude(q => q.Case) .ThenInclude(q => q.CaseType) // Including Case Creator .Include(q => q.CasesforApproval.Where(p => p.Case.Processed == 0 && p.Approved == 0)) .ThenInclude(q => q.Case) .ThenInclude(q => q.LocalUser) // Including Approvers .Include(q => q.CasesforApproval.Where(p => p.Case.Processed == 0 && p.Approved == 0)) .ThenInclude(q => q.Case) .ThenInclude(q => q.Approvers) .ThenInclude(w => w.LocalUser) // Assigned to the Groups to which the user belongs to .Include(e => e.UserGroups) .ThenInclude(e => e.LocalGroup) .ThenInclude(e => e.GroupCases.Where(p => p.Case.Processed == 0)) .ThenInclude(e => e.Case) .ThenInclude(e => e.CaseType) // Including Case Creator .Include(e => e.UserGroups) .ThenInclude(e => e.LocalGroup) .ThenInclude(e => e.GroupCases.Where(p => p.Case.Processed == 0)) .ThenInclude(e => e.Case) .ThenInclude(e => e.LocalUser) // Including Approvers .Include(e => e.UserGroups) .ThenInclude(e => e.LocalGroup) .ThenInclude(e => e.GroupCases.Where(p => p.Case.Processed == 0)) .ThenInclude(e => e.Case) .ThenInclude(e => e.Approvers) .ThenInclude(w => w.LocalUser) .Include(e => e.EmailPreference) .FirstOrDefaultAsync(m => m.LocalUserID == ADemail); int group_case_count = 0; foreach (var item in UCases.UserGroups) { foreach (var item2 in item.LocalGroup.GroupCases) { group_case_count += 1; } } ViewData["group_case_count"] = group_case_count; return(View(UCases)); }