// GET: Users
        public ActionResult Index()
        {
            InitializeState();

            var svc   = WebServiceFactory.ApplicationTenantUser();
            var users = svc.ReadMultiple(
                new []
            {
                new ApplicationTenantUser.ApplicationTenantUser_Filter
                {
                    Field    = ApplicationTenantUser.ApplicationTenantUser_Fields.Application_Tenant_ID,
                    Criteria = State.Get <TenantModel>().Id
                }
            }, null, 0);

            return(View(new UserListModel
            {
                Users = users.Select(u => new UserModel
                {
                    UserName = u.User_Name,
                    FullName = u.Full_Name,
                    ContactEmail = u.Contact_Email,
                    Administrator = u.Administrator
                }).ToArray(),
                Tenant = State.Get <TenantModel>()
            }));
        }
Beispiel #2
0
        protected override void RequestTasks()
        {
            var service = WebServiceFactory.ApplicationTenantUser();

            RegisterTask(
                new AsyncWorkflowTask("Creating the administrative user account", (state, action) =>
            {
                state.Get <UserModel>().TenantId = state.Get <TenantModel>().Id;
                service.CreateCompleted         += (sender, args) =>
                {
                    action.CompleteAsyncOperation(args, () => state.Set(args.ApplicationTenantUser));
                };
                service.CreateAsync(state.Get <UserModel>().ToApplicationTenantUser());
            })
                .Then(
                    new AsyncWorkflowTask("Enabling the user account to access the tenant", (state, action) =>
            {
                service.NewCompleted += (sender, args) =>
                {
                    action.CompleteAsyncOperation(args,
                                                  () =>
                    {
                        state.Get <UserModel>().Password = args.Result;
                        state["UserCreated"]             = true;
                    });
                };
                service.NewAsync(state.Get <ApplicationTenantUser.ApplicationTenantUser>().Key, true);
            }).Then(
                        new AsyncWorkflowTask("Activating security system for the tenant", (state, action) =>
            {
                Task.Factory.StartNew(() =>
                {
                    while (!state["CompanyRenamed"])
                    {
                        Thread.Sleep(1000);
                    }

                    var svcUser = WebServiceFactory.Tenant.User(state);
                    var user    = svcUser.ReadMultiple(null, null, 1)?[0];
                    if (user != null)
                    {
                        user.Permissions = new[] { new User_Line {
                                                       Permission_Set = "SUPER"
                                                   } };
                        svcUser.UpdateCompleted += (sender, args) =>
                        {
                            action.CompleteAsyncOperation(args, null);
                        };
                        svcUser.UpdateAsync(user);
                    }
                });
            }))));
        }
        protected override void RequestTasks()
        {
            var service = WebServiceFactory.ApplicationTenantUser();

            RegisterTask(
                new AsyncWorkflowTask("Creating the user account", (state, action) =>
            {
                state.Get <NewUserModel>().User.TenantId = state.Get <TenantModel>().Id;
                service.CreateCompleted += (sender, args) =>
                {
                    action.CompleteAsyncOperation(args, () => state.Set(args.ApplicationTenantUser));
                };
                service.CreateAsync(state.Get <NewUserModel>().User.ToApplicationTenantUser());
            })
                .Then(
                    new AsyncWorkflowTask("Enabling the user account to access the tenant", (state, action) =>
            {
                service.NewCompleted += (sender, args) =>
                {
                    action.CompleteAsyncOperation(args, null);
                };
                service.NewAsync(state.Get <ApplicationTenantUser.ApplicationTenantUser>().Key, true);
            }).Then(
                        new AsyncWorkflowTask("Setting user permission sets", (state, action) =>
            {
                var userSvc = WebServiceFactory.Tenant.User(state);
                var newUser = state.Get <NewUserModel>();
                var user    = userSvc.ReadMultiple(
                    new[]
                {
                    new User_Filter
                    {
                        Field    = User_Fields.User_Name,
                        Criteria = state.Get <NewUserModel>().User.UserName
                    }
                }, null, 1)[0];
                user.Permissions =
                    JsonConvert.DeserializeObject <string[]>(
                        newUser.SelectedPermissionSets).Select(p => new User_Line
                {
                    Company        = newUser.User.Company,
                    Permission_Set = p
                }).ToArray();
                userSvc.Update(ref user);
                action.Complete();
            }))));
        }