diff --git a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html index 938caa3..bd01fdb 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html +++ b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html @@ -7,7 +7,7 @@
Nagrody:
{{competition.prize}}
-
diff --git a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts index 22c1eeb..9303aa6 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts +++ b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts @@ -3,8 +3,8 @@ import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/app-component-base'; import { Subscription } from 'rxjs/Rx'; import { ActivatedRoute } from '@angular/router'; -import { mergeMap } from 'rxjs/operators'; import { finalize } from 'rxjs/operators'; +import { forkJoin } from 'rxjs'; import { CompetitionServiceProxy, CompetitionDto, QuestionDto, @@ -18,11 +18,14 @@ import { CompetitionServiceProxy, export class CompetitionDetailComponent extends AppComponentBase implements OnInit, OnDestroy { private paramSubscription: Subscription; + private routeSubscription: Subscription; public competitionId: number; public competition: CompetitionDto = null; public competitionDetailAreaId: string = 'competition-detail-area'; + public canSolveCompetition: boolean = false; + public mode = 'detail'; public pager = { @@ -41,25 +44,31 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn public ngOnInit() { this.competition = new CompetitionDto(); - this.getCompetition(); + + this.routeSubscription = this.route.params + .subscribe(params => { + this.competitionId = +params['id']; + console.log('competitionId: ' + this.competitionId); + this.getCompetition(); + }) + } private getCompetition(): void { - this.paramSubscription = this.route.params - .pipe(mergeMap(params => { - this.competitionId = +params['id']; - console.log('competitionId: ' + this.competitionId); - this.setBusy(this.competitionDetailAreaId); - const competitionDetailStream = this._competitionService - .getCompetition(this.competitionId) - .pipe(finalize(() => { this.clearBusy(this.competitionDetailAreaId); })) - return competitionDetailStream - })).subscribe((result: CompetitionDto) => { - this.competition = result; - this.competition.questions.forEach((x) => this.shuffleOptions(x.questionOptions)); - this.pager.count = this.competition.questions.length; - console.log(this.competition); - }); + this.setBusy(this.competitionDetailAreaId); + + this.paramSubscription = forkJoin([this._competitionService.getCompetition(this.competitionId), + this._competitionService.canSolveCompetition(this.competitionId)]) + .pipe(finalize(() => { this.clearBusy(this.competitionDetailAreaId); })) + .subscribe((data: [CompetitionDto, boolean]) => { + this.competition = data[0]; + this.competition.questions.forEach((x) => this.shuffleOptions(x.questionOptions)); + this.pager.count = this.competition.questions.length; + console.log(this.competition); + + this.canSolveCompetition = data[1]; + console.log(this.canSolveCompetition); + }); } private shuffleOptions(array) { @@ -120,6 +129,10 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn if (this.paramSubscription) { this.paramSubscription.unsubscribe(); } + + if (this.routeSubscription) { + this.routeSubscription.unsubscribe(); + } } } \ No newline at end of file diff --git a/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts b/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts index c157cef..37bebd7 100644 --- a/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts +++ b/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts @@ -328,6 +328,61 @@ export class CompetitionServiceProxy { } return _observableOf(null); } + + /** + * @competitionId (optional) + * @return Success + */ + canSolveCompetition(competitionId: number | null | undefined): Observable { + let url_ = this.baseUrl + "/api/services/app/Competition/CanSolveCompetition?"; + if (competitionId !== undefined) + url_ += "competitionId=" + encodeURIComponent("" + competitionId) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_ : any = { + observe: "response", + responseType: "blob", + headers: new HttpHeaders({ + "Content-Type": "application/json", + "Accept": "application/json" + }) + }; + + return this.http.request("post", url_, options_).pipe(_observableMergeMap((response_ : any) => { + return this.processCanSolveCompetition(response_); + })).pipe(_observableCatch((response_: any) => { + if (response_ instanceof HttpResponseBase) { + try { + return this.processCanSolveCompetition(response_); + } catch (e) { + return >_observableThrow(e); + } + } else + return >_observableThrow(response_); + })); + } + + protected processCanSolveCompetition(response: HttpResponseBase): Observable { + const status = response.status; + const responseBlob = + response instanceof HttpResponse ? response.body : + (response).error instanceof Blob ? (response).error : undefined; + + let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); }}; + if (status === 200) { + return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => { + let result200: any = null; + let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); + result200 = resultData200 !== undefined ? resultData200 : null; + return _observableOf(result200); + })); + } else if (status !== 200 && status !== 204) { + return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + })); + } + return _observableOf(null); + } } @Injectable() diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs index 3108270..9c9e6a2 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using SystemKonkursow.Authorization.Users; using SystemKonkursow.Competition.CompetitionCategory.Dto; namespace SystemKonkursow.Competition.CompetitionCategory @@ -15,16 +16,22 @@ namespace SystemKonkursow.Competition.CompetitionCategory private readonly IRepository _competitionRepository; private readonly IRepository _questionRepository; private readonly IRepository _questionOptionRepository; + private readonly UserManager _userManager; + private readonly IRepository _participantRepository; public CompetitionAppService(IRepository competitionCategoryRepository, IRepository competitionRepository, IRepository questionRepository, - IRepository questionOptionRepository) + IRepository questionOptionRepository, + UserManager userManager, + IRepository participantRepository) { _competitionCategoryRepository = competitionCategoryRepository; _competitionRepository = competitionRepository; _questionRepository = questionRepository; _questionOptionRepository = questionOptionRepository; + _userManager = userManager; + _participantRepository = participantRepository; } [AbpAuthorize] @@ -116,5 +123,34 @@ namespace SystemKonkursow.Competition.CompetitionCategory return mappedObject; } + [AbpAuthorize] + public async Task CanSolveCompetition(int competitionId) + { + var user = await GetCurrentUserAsync(); + + var isParticipant = await _userManager.IsParticipantUserAsync(user); + + if (isParticipant) + { + var participant = await _participantRepository.GetAll() + .FirstOrDefaultAsync(t => t.UserId == user.Id); + + var competition = await _competitionRepository.GetAll() + .FirstOrDefaultAsync(t => t.Id == competitionId); + + if (participant.ParticipantClass < competition.MinClass || participant.ParticipantClass > competition.MaxClass) + { + return false; + } + + return true; + + } + else + { + return false; + } + } + } } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Authorization/Users/UserManager.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Authorization/Users/UserManager.cs index 9e514f0..20178b8 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Authorization/Users/UserManager.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Authorization/Users/UserManager.cs @@ -11,6 +11,7 @@ using Abp.Domain.Uow; using Abp.Organizations; using Abp.Runtime.Caching; using SystemKonkursow.Authorization.Roles; +using System.Threading.Tasks; namespace SystemKonkursow.Authorization.Users { @@ -54,5 +55,16 @@ namespace SystemKonkursow.Authorization.Users settingManager) { } + + public async Task CheckHasUserRole(User user, string roleName) + { + return await IsInRoleAsync(user, roleName); + } + + public async Task IsParticipantUserAsync(User user) + { + return await CheckHasUserRole(user, StaticRoleNames.Host.Participant); + } + } }