/// <inheritdoc /> public async Task <Campus> CreateCampus(ClaimsPrincipal user, Guid hubId, Campus campus, bool modelState) { var userId = AuthenticationHelper.GetUserIdFromToken(user); // find hub var hub = await _hubDbService.GetById(hubId); // find lead var lead = await _graphUserService.GetGraphUserById(campus.Lead); var campusGroup = await _graphGroupService.CreateGroup(campus.Name, userId, hub.AadGroupId.ToString()); // add lead to group await _graphGroupService.AddUserToGroup(lead, campusGroup.Id); // make sure lead has permissions and title await _graphUserService.DefineCampusLead(campus.Lead, campusGroup.Id); // assign manager await _graphUserService.AssignManager(lead, hub.Lead.ToString()); var newCampus = new Infrastructure.Entities.Db.Campus(campus.Name, campus.Lead, campusGroup.Id, campus.University, userId) { Hub = hub }; return(Campus.FromDb(await _campusDbService.Create(newCampus, modelState))); }
/// <inheritdoc /> public async Task <Campus> GetById(Guid campusId, ClaimsPrincipal user) { var campus = await _campusDbService.GetById(campusId); AuthorizeHubLeadForCampus(campus, user); return(Campus.FromDb(campus)); }
/// <inheritdoc /> public async Task <Campus> GetMyCampus(Guid userId) { var campusId = await _graphUserService.GetCampusIdForUser(userId); if (campusId == Guid.Empty) { throw new MccNotFoundException($"Could not find campus for user with id {userId}"); } var campus = await _campusDbService.GetById(campusId); return(Campus.FromDb(campus)); }