Exemplo n.º 1
0
 public static async Task CreateSeedDataAsync(this DapperCX <int, UserProfile> data)
 {
     using (var cn = data.GetConnection())
     {
         foreach (var row in Permission.SeedData)
         {
             await data.MergeAsync(row);
         }
         foreach (var row in RecurringTaskType.SeedData)
         {
             await data.MergeAsync(row);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// In a multi-tenant app, users would have processes for joining and leaving a tenant.
        /// For this sample app intended to run locally, we can generate a sample tenant and assume the user always belongs to it.
        /// In this app, a tenant is a "Workspace"
        /// </summary>
        public static async Task InitDefaultTenantAsync(this DapperCX <int, UserProfile> data)
        {
            if (data.HasUser && !data.User.WorkspaceId.HasValue)
            {
                // find or create default workspace
                var wsId = await data.MergeAsync(new Workspace()
                {
                    Name = "Default Workspace"
                });

                // add current user if not there already
                await data.MergeAsync(new WorkspaceUser()
                {
                    WorkspaceId = wsId,
                    UserId      = data.User.UserId
                });

                // set the current workspace on the user profile row
                data.User.WorkspaceId = wsId;
                await data.UpdateUserAsync(field => field.WorkspaceId);
            }
        }