示例#1
0
        /// <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)));
        }
示例#2
0
        /// <inheritdoc />
        public async Task <Hub> Create(Guid userId, Hub entity, bool modelState)
        {
            // find lead
            var lead = await _graphUserService.GetGraphUserById(entity.Lead);

            // create aad group
            var hubGroup = await _graphGroupService.CreateGroup(entity.Name, userId, "Hub Group");

            // add lead to group
            await _graphGroupService.AddUserToGroup(lead, hubGroup.Id);

            var newHub = new Infrastructure.Entities.Db.Hub(entity.Name, entity.Lead, hubGroup.Id, userId);

            // make sure lead has permissions and title
            await _graphUserService.DefineHubLead(entity.Lead, new Guid[] { }, newHub.AadGroupId);


            return(Hub.FromDb(await _hubDbService.Create(newHub, modelState)));
        }