Ejemplo n.º 1
0
        public async Task <BasicUser> CreateUser(NewUser user, Guid campusId)
        {
            // get campus and lead for user
            var campus = await _graphGroupService.GetGroupById(campusId);

            var graphUser    = CreateGraphUser(user, Campus.FromMccGroup(campus));
            var userPassword = graphUser.PasswordProfile.Password.ToSecureString();

            graphUser = await _graphService.Client.Users.Request().AddAsync(graphUser);

            // add user to the corresponding groups
            await _graphGroupService.AddUserToGroup(graphUser, _authorizationConfiguration.CommunityGroupId);

            await _graphGroupService.AddUserToGroup(graphUser, campusId);

            // add licence
            await AssignLicense(graphUser);

            // add new user as additional direct to lead
            var lead = await GetLeadForCampus(campus.Id);

            await AssignManager(graphUser, lead.Id);

            // Send welcome mail
            await SendNewUserWelcomeMail(graphUser, user, lead, userPassword);

            return(BasicUser.FromGraphUser(graphUser));
        }
Ejemplo n.º 2
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)));
        }
Ejemplo n.º 3
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)));
        }