예제 #1
0
 public static EditPlatformUserResponse ForEditing(this PlatformAdminUser admin)
 => new EditPlatformUserResponse
 {
     Id    = admin.Id,
     Name  = admin.Name,
     Email = admin.Email
 };
예제 #2
0
        //public async Task<PlatformAdminUser> GetUserAsync(PlatformAdminUserId userId, IAsyncDocumentSession session)
        //{
        //    return await session.LoadAsync<PlatformAdminUser>(userId.Value);
        //}

        public async Task <PlatformAdminUser> GetOrCreateUserAsync(string uniqueIdentifier, IAsyncDocumentSession session)
        {
            var existingUser = await session.Query <PlatformAdminUser>().SingleOrDefaultAsync(u => u.UniqueIdentifier == uniqueIdentifier);

            if (existingUser != null)
            {
                return(existingUser);
            }

            var newUser = new PlatformAdminUser
            {
                UniqueIdentifier = uniqueIdentifier
            };

            await session.StoreAsync(newUser);

            return(newUser);
        }
예제 #3
0
        public async Task <Platform> AddAdminAsync(Platform platform, PlatformAdminUser admin, IAsyncDocumentSession session)
        {
            var project = await session.Query <Project>().Where(p => p.Platforms.FirstOrDefault().Id == platform.Id).FirstOrDefaultAsync();

            if (project == null)
            {
                throw new ApiException($"The platform with id {platform.Id} was not found.");
            }
            admin = await session.LoadAsync <PlatformAdminUser>(admin.Id);

            if (!project.AdminIds.Contains(admin.Id) && project.OwnerAdminId != admin.Id)
            {
                var ids = project.AdminIds.ToList();
                ids.Add(admin.Id);
                project.AdminIds = ids;
            }

            // TODO: Save session changes once
            await session.SaveChangesAsync();

            return(platform);
        }