public async Task ExecuteAsync(CreateApplication command)
        {
            var app = new Application(command.UserId, command.Name)
            {
                AppKey          = command.ApplicationKey,
                ApplicationType =
                    (TypeOfApplication)Enum.Parse(typeof(TypeOfApplication), command.TypeOfApplication.ToString())
            };
            var creator = await _userRepository.GetUserAsync(command.UserId);

            await _repository.CreateAsync(app);

            await _repository.CreateAsync(new ApplicationTeamMember(app.Id, creator.AccountId)
            {
                UserName    = creator.UserName,
                Roles       = new[] { ApplicationRole.Admin, ApplicationRole.Member },
                AddedByName = creator.UserName
            });

            var identity = ClaimsPrincipal.Current.Identities.First();
            var claim    = new Claim(OneTrueClaims.Application, app.Id.ToString(), ClaimValueTypes.Integer32);

            identity.AddClaim(claim);
            claim = new Claim(OneTrueClaims.ApplicationAdmin, app.Id.ToString(), ClaimValueTypes.Integer32);
            identity.AddClaim(claim);
            claim = new Claim(OneTrueClaims.ApplicationName, app.Name, ClaimValueTypes.String);
            identity.AddClaim(claim);
            identity.AddClaim(OneTrueClaims.UpdateIdentity);

            var evt = new ApplicationCreated(app.Id, app.Name, command.UserId, command.ApplicationKey, app.SharedSecret);
            await _eventBus.PublishAsync(evt);
        }
Exemplo n.º 2
0
        public async Task HandleAsync(IMessageContext context, CreateApplication command)
        {
            var app = new Application(command.UserId, command.Name)
            {
                ApplicationType =
                    (TypeOfApplication)Enum.Parse(typeof(TypeOfApplication), command.TypeOfApplication.ToString())
            };

            if (command.ApplicationKey != null)
            {
                app.AppKey = command.ApplicationKey;
            }


            if (command.NumberOfDevelopers > 0)
            {
                app.AddStatsBase(command.NumberOfDevelopers, command.NumberOfErrors);
            }

            var creator = await _userRepository.GetUserAsync(command.UserId);

            await _repository.CreateAsync(app);

            await _repository.CreateAsync(new ApplicationTeamMember(app.Id, creator.AccountId, creator.UserName)
            {
                UserName = creator.UserName,
                Roles    = new[] { ApplicationRole.Admin, ApplicationRole.Member },
            });

            var evt = new ApplicationCreated(app.Id, app.Name, command.UserId, app.AppKey, app.SharedSecret);
            await context.SendAsync(evt);
        }
Exemplo n.º 3
0
        public async Task ExecuteAsync(CreateApplication command)
        {
            var app = new Application(command.UserId, command.Name)
            {
                AppKey          = command.ApplicationKey,
                ApplicationType =
                    (TypeOfApplication)Enum.Parse(typeof(TypeOfApplication), command.TypeOfApplication.ToString())
            };
            var creator = await _userRepository.GetUserAsync(command.UserId);

            await _repository.CreateAsync(app);

            await _repository.CreateAsync(new ApplicationTeamMember(app.Id, creator.EmailAddress)
            {
                AccountId   = creator.AccountId,
                UserName    = creator.UserName,
                Roles       = new[] { ApplicationRole.Admin, ApplicationRole.Member },
                AddedByName = creator.UserName
            });

            var evt = new ApplicationCreated(app.Id, app.Name, command.UserId, command.ApplicationKey, app.SharedSecret);
            await _eventBus.PublishAsync(evt);
        }
 //Apply State Changes
 private void Apply(ApplicationCreated @event)
 {
     Id             = @event.ApplicationId;
     _clientPrefix  = @event.Name;
     OneRolePerUser = @event.OneRolePerUser;
 }
Exemplo n.º 5
0
 private static void RaiseApplicationCreated(XamlApplication application)
 {
     ApplicationCreated?.Invoke(application, new EventArgs());
 }