예제 #1
0
        public async Task <IActionResult> UpdateAsync([FromRoute] int applicationId, [FromBody] ApplicationRequestDto dto)
        {
            Application application;

            if (this.UserHasScope(ApplicationScopes.Admin))
            {
                application = await _updateApplicationService.UpdateAsync(dto.ToApplication(applicationId), dto.user_id ?? this.GetUserId());
            }
            else
            {
                application = await _updateApplicationService.UpdateAsync(dto.ToApplication(applicationId), this.GetUserId());
            }

            var updated = ApplicationResponseDto.FromApplication(application);

            return(Ok(updated));
        }
예제 #2
0
        public async Task <IActionResult> FindAsync([FromRoute] int applicationId)
        {
            Application application;

            if (this.UserHasScope(ApplicationScopes.Admin))
            {
                application = await _findApplicationService.FindAsync(applicationId);
            }
            else
            {
                application = await _findApplicationService.FindAsync(applicationId, this.GetUserId());
            }

            var found = ApplicationResponseDto.FromApplication(application);

            return(Ok(found));
        }
예제 #3
0
        public async Task <IActionResult> CreateAsync([FromBody] ApplicationRequestDto dto)
        {
            Application application;

            if (this.UserHasScope(ApplicationScopes.Admin))
            {
                application = await _addApplicationService.AddAsync(dto.ToApplication(), dto.user_id ?? this.GetUserId());
            }
            else
            {
                application = await _addApplicationService.AddAsync(dto.ToApplication(), this.GetUserId());
            }

            var created = ApplicationResponseDto.FromApplication(application);

            return(Created($"{_siteSettings.ListenUri}/applications/{application.ApplicationId}", created));
        }
예제 #4
0
        public static ApplicationResponseDto FromApplication(Application application, bool includeChildren)
        {
            var dto = new ApplicationResponseDto
            {
                application_id = application.ApplicationId,
                name           = application.Name,
                description    = application.Description,
                type           = application.Type,
                homepage_uri   = application.HomepageUri,
                redirect_uri   = application.RedirectUri,
                client_id      = application.ClientId,
                user_id        = application.UserId,
                created_date   = application.CreatedDateTime,
                modified_date  = application.ModifiedDateTime
            };

            if (includeChildren)
            {
                dto.roles = application.Roles?.Select(r =>
                                                      RoleResponseDto.FromRole(r, true)).ToList();
            }

            return(dto);
        }