From f93499ea6796392ded133c8f9404f18bce5bd9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Stawujak?= Date: Tue, 11 Dec 2018 22:58:11 +0100 Subject: [PATCH] SKE-37 getCompetitionsForCategory method --- .../categories-list.component.html | 2 +- .../categories-list.component.ts | 12 +- .../shared/service-proxies/service-proxies.ts | 184 ++++++++++++++++-- .../service-proxies/service-proxy.module.ts | 1 + .../Category/CategoryAppService.cs | 29 +++ .../Competition/Category/Dto/CategoryDto.cs | 9 + .../Category/Dto/CategoryMapProfile.cs | 12 ++ .../CompetitionCategoryAppService.cs | 16 +- .../Dto/CompetitionCategoryDto.cs | 9 - .../Dto/CompetitionCategoryMapProfile.cs | 11 +- .../CompetitionCategory/Dto/CompetitionDto.cs | 26 +++ .../SystemKonkursow.Core/Domain/Category.cs | 11 ++ .../Domain/Competition.cs | 7 +- .../Domain/CompetitionCategory.cs | 12 +- .../Seed/CompetitionBuilder.cs | 34 ++-- .../SystemKonkursowDbContext.cs | 2 + .../SystemKonkursowDbContextModelSnapshot.cs | 47 ++++- 17 files changed, 357 insertions(+), 67 deletions(-) create mode 100644 SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/CategoryAppService.cs create mode 100644 SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/Dto/CategoryDto.cs create mode 100644 SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/Dto/CategoryMapProfile.cs delete mode 100644 SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryDto.cs create mode 100644 SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionDto.cs create mode 100644 SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Category.cs diff --git a/SystemKonkursow/4.2.1/angular/src/app/categories-list/categories-list.component.html b/SystemKonkursow/4.2.1/angular/src/app/categories-list/categories-list.component.html index fcef52e..1284ae4 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/categories-list/categories-list.component.html +++ b/SystemKonkursow/4.2.1/angular/src/app/categories-list/categories-list.component.html @@ -1,5 +1,5 @@
-
+
{{ category.name }}
\ No newline at end of file diff --git a/SystemKonkursow/4.2.1/angular/src/app/categories-list/categories-list.component.ts b/SystemKonkursow/4.2.1/angular/src/app/categories-list/categories-list.component.ts index f2fddd2..4386db9 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/categories-list/categories-list.component.ts +++ b/SystemKonkursow/4.2.1/angular/src/app/categories-list/categories-list.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit, Injector, OnDestroy } from '@angular/core'; import { appModuleAnimation } from '@shared/animations/routerTransition'; -import { CompetitionCategoryServiceProxy, CompetitionCategoryDto } from '@shared/service-proxies/service-proxies'; +import { CategoryServiceProxy, CategoryDto } from '@shared/service-proxies/service-proxies'; import { List } from 'lodash'; import { AppComponentBase } from '@shared/app-component-base'; import { Subscription } from 'rxjs/Rx'; @@ -13,14 +13,14 @@ import { finalize } from 'rxjs/operators'; }) export class CategoriesListComponent extends AppComponentBase implements OnInit, OnDestroy { - public competitionCategoriesList: List = []; + public categoriesList: List = []; public categoriesListAreaId: string = 'categories-list-area'; private categoryListSubscription: Subscription; constructor( injector: Injector, - private _competitionCategoryService: CompetitionCategoryServiceProxy + private _categoryService: CategoryServiceProxy ) { super(injector); } @@ -38,10 +38,10 @@ export class CategoriesListComponent extends AppComponentBase implements OnInit, private getCompetitionCategories(): void { this.setBusy(this.categoriesListAreaId); - this.categoryListSubscription = this._competitionCategoryService.getAllCompetitionCategories() + this.categoryListSubscription = this._categoryService.getAllCategories() .pipe(finalize(() => { this.clearBusy(this.categoriesListAreaId); })) - .subscribe((result: List) => { - this.competitionCategoriesList = result; + .subscribe((result: List) => { + this.categoriesList = result; }); } } \ 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 f54d471..a2c9dba 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 @@ -140,7 +140,7 @@ export class AccountServiceProxy { } @Injectable() -export class CompetitionCategoryServiceProxy { +export class CategoryServiceProxy { private http: HttpClient; private baseUrl: string; protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined; @@ -153,8 +153,8 @@ export class CompetitionCategoryServiceProxy { /** * @return Success */ - getAllCompetitionCategories(): Observable { - let url_ = this.baseUrl + "/api/services/app/CompetitionCategory/GetAllCompetitionCategories"; + getAllCategories(): Observable { + let url_ = this.baseUrl + "/api/services/app/Category/GetAllCategories"; url_ = url_.replace(/[?&]$/, ""); let options_ : any = { @@ -167,20 +167,20 @@ export class CompetitionCategoryServiceProxy { }; return this.http.request("get", url_, options_).pipe(_observableMergeMap((response_ : any) => { - return this.processGetAllCompetitionCategories(response_); + return this.processGetAllCategories(response_); })).pipe(_observableCatch((response_: any) => { if (response_ instanceof HttpResponseBase) { try { - return this.processGetAllCompetitionCategories(response_); + return this.processGetAllCategories(response_); } catch (e) { - return >_observableThrow(e); + return >_observableThrow(e); } } else - return >_observableThrow(response_); + return >_observableThrow(response_); })); } - protected processGetAllCompetitionCategories(response: HttpResponseBase): Observable { + protected processGetAllCategories(response: HttpResponseBase): Observable { const status = response.status; const responseBlob = response instanceof HttpResponse ? response.body : @@ -194,7 +194,7 @@ export class CompetitionCategoryServiceProxy { if (resultData200 && resultData200.constructor === Array) { result200 = []; for (let item of resultData200) - result200.push(CompetitionCategoryDto.fromJS(item)); + result200.push(CategoryDto.fromJS(item)); } return _observableOf(result200); })); @@ -203,7 +203,78 @@ export class CompetitionCategoryServiceProxy { return throwException("An unexpected server error occurred.", status, _responseText, _headers); })); } - return _observableOf(null); + return _observableOf(null); + } +} + +@Injectable() +export class CompetitionCategoryServiceProxy { + private http: HttpClient; + private baseUrl: string; + protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined; + + constructor(@Inject(HttpClient) http: HttpClient, @Optional() @Inject(API_BASE_URL) baseUrl?: string) { + this.http = http; + this.baseUrl = baseUrl ? baseUrl : ""; + } + + /** + * @categoryId (optional) + * @return Success + */ + getAllCompetitionsForCategory(categoryId: number | null | undefined): Observable { + let url_ = this.baseUrl + "/api/services/app/CompetitionCategory/GetAllCompetitionsForCategory?"; + if (categoryId !== undefined) + url_ += "categoryId=" + encodeURIComponent("" + categoryId) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_ : any = { + observe: "response", + responseType: "blob", + headers: new HttpHeaders({ + "Content-Type": "application/json", + "Accept": "application/json" + }) + }; + + return this.http.request("get", url_, options_).pipe(_observableMergeMap((response_ : any) => { + return this.processGetAllCompetitionsForCategory(response_); + })).pipe(_observableCatch((response_: any) => { + if (response_ instanceof HttpResponseBase) { + try { + return this.processGetAllCompetitionsForCategory(response_); + } catch (e) { + return >_observableThrow(e); + } + } else + return >_observableThrow(response_); + })); + } + + protected processGetAllCompetitionsForCategory(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); + if (resultData200 && resultData200.constructor === Array) { + result200 = []; + for (let item of resultData200) + result200.push(CompetitionDto.fromJS(item)); + } + 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); } } @@ -1841,11 +1912,11 @@ export interface IRegisterOutput { canLogin: boolean | undefined; } -export class CompetitionCategoryDto implements ICompetitionCategoryDto { +export class CategoryDto implements ICategoryDto { name: string | undefined; id: number | undefined; - constructor(data?: ICompetitionCategoryDto) { + constructor(data?: ICategoryDto) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -1861,9 +1932,9 @@ export class CompetitionCategoryDto implements ICompetitionCategoryDto { } } - static fromJS(data: any): CompetitionCategoryDto { + static fromJS(data: any): CategoryDto { data = typeof data === 'object' ? data : {}; - let result = new CompetitionCategoryDto(); + let result = new CategoryDto(); result.init(data); return result; } @@ -1875,19 +1946,98 @@ export class CompetitionCategoryDto implements ICompetitionCategoryDto { return data; } - clone(): CompetitionCategoryDto { + clone(): CategoryDto { const json = this.toJSON(); - let result = new CompetitionCategoryDto(); + let result = new CategoryDto(); result.init(json); return result; } } -export interface ICompetitionCategoryDto { +export interface ICategoryDto { name: string | undefined; id: number | undefined; } +export class CompetitionDto implements ICompetitionDto { + name: string | undefined; + startDate: moment.Moment | undefined; + endDate: moment.Moment | undefined; + description: string | undefined; + prize: string | undefined; + minClass: number | undefined; + maxClass: number | undefined; + creationTime: moment.Moment | undefined; + creatorName: string | undefined; + id: number | undefined; + + constructor(data?: ICompetitionDto) { + if (data) { + for (var property in data) { + if (data.hasOwnProperty(property)) + (this)[property] = (data)[property]; + } + } + } + + init(data?: any) { + if (data) { + this.name = data["name"]; + this.startDate = data["startDate"] ? moment(data["startDate"].toString()) : undefined; + this.endDate = data["endDate"] ? moment(data["endDate"].toString()) : undefined; + this.description = data["description"]; + this.prize = data["prize"]; + this.minClass = data["minClass"]; + this.maxClass = data["maxClass"]; + this.creationTime = data["creationTime"] ? moment(data["creationTime"].toString()) : undefined; + this.creatorName = data["creatorName"]; + this.id = data["id"]; + } + } + + static fromJS(data: any): CompetitionDto { + data = typeof data === 'object' ? data : {}; + let result = new CompetitionDto(); + result.init(data); + return result; + } + + toJSON(data?: any) { + data = typeof data === 'object' ? data : {}; + data["name"] = this.name; + data["startDate"] = this.startDate ? this.startDate.toISOString() : undefined; + data["endDate"] = this.endDate ? this.endDate.toISOString() : undefined; + data["description"] = this.description; + data["prize"] = this.prize; + data["minClass"] = this.minClass; + data["maxClass"] = this.maxClass; + data["creationTime"] = this.creationTime ? this.creationTime.toISOString() : undefined; + data["creatorName"] = this.creatorName; + data["id"] = this.id; + return data; + } + + clone(): CompetitionDto { + const json = this.toJSON(); + let result = new CompetitionDto(); + result.init(json); + return result; + } +} + +export interface ICompetitionDto { + name: string | undefined; + startDate: moment.Moment | undefined; + endDate: moment.Moment | undefined; + description: string | undefined; + prize: string | undefined; + minClass: number | undefined; + maxClass: number | undefined; + creationTime: moment.Moment | undefined; + creatorName: string | undefined; + id: number | undefined; +} + export class ChangeUiThemeInput implements IChangeUiThemeInput { theme: string; diff --git a/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxy.module.ts b/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxy.module.ts index 954dc3c..22a58d9 100644 --- a/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxy.module.ts +++ b/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxy.module.ts @@ -13,6 +13,7 @@ import * as ApiServiceProxies from './service-proxies'; ApiServiceProxies.TokenAuthServiceProxy, ApiServiceProxies.AccountServiceProxy, ApiServiceProxies.ConfigurationServiceProxy, + ApiServiceProxies.CategoryServiceProxy, ApiServiceProxies.CompetitionCategoryServiceProxy, { provide: HTTP_INTERCEPTORS, useClass: AbpHttpInterceptor, multi: true } ] diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/CategoryAppService.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/CategoryAppService.cs new file mode 100644 index 0000000..0ed76dc --- /dev/null +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/CategoryAppService.cs @@ -0,0 +1,29 @@ +using Abp.Authorization; +using Abp.Domain.Repositories; +using System.Collections.Generic; +using System.Linq; +using SystemKonkursow.Competition.Category.Dto; + +namespace SystemKonkursow.Competition.Category +{ + public class CategoryAppService : SystemKonkursowAppServiceBase + { + private readonly IRepository _categoryRepository; + + public CategoryAppService(IRepository categoryRepository) + { + _categoryRepository = categoryRepository; + } + + [AbpAuthorize] + public List GetAllCategories() + { + var categories = _categoryRepository.GetAll().ToList(); + + var mappedObjects = ObjectMapper.Map>(categories + .OrderBy(t => t.Name)); + + return mappedObjects; + } + } +} diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/Dto/CategoryDto.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/Dto/CategoryDto.cs new file mode 100644 index 0000000..399e8c3 --- /dev/null +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/Dto/CategoryDto.cs @@ -0,0 +1,9 @@ +using Abp.Application.Services.Dto; + +namespace SystemKonkursow.Competition.Category.Dto +{ + public class CategoryDto : EntityDto + { + public string Name { get; set; } + } +} diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/Dto/CategoryMapProfile.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/Dto/CategoryMapProfile.cs new file mode 100644 index 0000000..0de4e2a --- /dev/null +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/Category/Dto/CategoryMapProfile.cs @@ -0,0 +1,12 @@ +using AutoMapper; + +namespace SystemKonkursow.Competition.Category.Dto +{ + public class CategoryMapProfile : Profile + { + public CategoryMapProfile() + { + CreateMap(); + } + } +} diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionCategoryAppService.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionCategoryAppService.cs index ba5a141..35650a1 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionCategoryAppService.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionCategoryAppService.cs @@ -1,5 +1,6 @@ using Abp.Authorization; using Abp.Domain.Repositories; +using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; using SystemKonkursow.Competition.CompetitionCategory.Dto; @@ -9,19 +10,24 @@ namespace SystemKonkursow.Competition.CompetitionCategory public class CompetitionCategoryAppService : SystemKonkursowAppServiceBase { private readonly IRepository _competitionCategoryRepository; + private readonly IRepository _competitionRepository; - public CompetitionCategoryAppService(IRepository competitionCategoryRepository) + public CompetitionCategoryAppService(IRepository competitionCategoryRepository, + IRepository competitionRepository) { _competitionCategoryRepository = competitionCategoryRepository; + _competitionRepository = competitionRepository; } [AbpAuthorize] - public List GetAllCompetitionCategories() + public List GetAllCompetitionsForCategory(int categoryId) { - var competitionCategories = _competitionCategoryRepository.GetAll().ToList(); + var competitions = _competitionCategoryRepository.GetAll() + .Include(t => t.Competition).ThenInclude(x => x.Creator) + .Where(t => t.CategoryId == categoryId).ToList(); - var mappedObjects = ObjectMapper.Map>(competitionCategories - .OrderBy(t => t.Name)); + var mappedObjects = ObjectMapper.Map>(competitions + .OrderBy(t => t.Competition.Name)); return mappedObjects; } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryDto.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryDto.cs deleted file mode 100644 index 48dd8fa..0000000 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryDto.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Abp.Application.Services.Dto; - -namespace SystemKonkursow.Competition.CompetitionCategory.Dto -{ - public class CompetitionCategoryDto : EntityDto - { - public string Name { get; set; } - } -} diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryMapProfile.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryMapProfile.cs index 1604ae5..ec2de8a 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryMapProfile.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryMapProfile.cs @@ -6,7 +6,16 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto { public CompetitionCategoryMapProfile() { - CreateMap(); + CreateMap() + .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Competition.Name)) + .ForMember(dest => dest.StartDate, opt => opt.MapFrom(src => src.Competition.StartDate)) + .ForMember(dest => dest.EndDate, opt => opt.MapFrom(src => src.Competition.EndDate)) + .ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Competition.Description)) + .ForMember(dest => dest.Prize, opt => opt.MapFrom(src => src.Competition.Prize)) + .ForMember(dest => dest.MinClass, opt => opt.MapFrom(src => src.Competition.MinClass)) + .ForMember(dest => dest.MaxClass, opt => opt.MapFrom(src => src.Competition.MaxClass)) + .ForMember(dest => dest.CreationTime, opt => opt.MapFrom(src => src.Competition.CreationTime)) + .ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Competition.Creator.UserName)); } } } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionDto.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionDto.cs new file mode 100644 index 0000000..98f8290 --- /dev/null +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionDto.cs @@ -0,0 +1,26 @@ +using Abp.Application.Services.Dto; +using System; + +namespace SystemKonkursow.Competition.CompetitionCategory.Dto +{ + public class CompetitionDto : EntityDto + { + public string Name { get; set; } + + public DateTime StartDate { get; set; } + + public DateTime EndDate { get; set; } + + public string Description { get; set; } + + public string Prize { get; set; } + + public int MinClass { get; set; } + + public int MaxClass { get; set; } + + public DateTime CreationTime { get; set; } + + public string CreatorName { get; set; } + } +} diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Category.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Category.cs new file mode 100644 index 0000000..94739e3 --- /dev/null +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Category.cs @@ -0,0 +1,11 @@ +using Abp.Domain.Entities; +using System.ComponentModel.DataAnnotations.Schema; + +namespace SystemKonkursow.Domain +{ + [Table("Categories")] + public class Category : Entity + { + public string Name { get; set; } + } +} diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Competition.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Competition.cs index 672dbf0..9ef2d52 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Competition.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Competition.cs @@ -15,8 +15,6 @@ namespace SystemKonkursow.Domain public string Name { get; set; } - public int CompetitionCategoryId { get; set; } - public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } @@ -25,8 +23,9 @@ namespace SystemKonkursow.Domain public string Prize { get; set; } - [ForeignKey(nameof(CompetitionCategoryId))] - public virtual CompetitionCategory CompetitionCategory { get; set; } + public int MinClass { get; set; } + + public int MaxClass { get; set; } [ForeignKey(nameof(CreatorUserId))] public virtual User Creator { get; set; } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/CompetitionCategory.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/CompetitionCategory.cs index c06aa9d..8091396 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/CompetitionCategory.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/CompetitionCategory.cs @@ -1,5 +1,4 @@ using Abp.Domain.Entities; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; namespace SystemKonkursow.Domain @@ -7,8 +6,15 @@ namespace SystemKonkursow.Domain [Table("CompetitionCategories")] public class CompetitionCategory : Entity { - public string Name { get; set; } + public int CategoryId { get; set; } + + public long CompetitionId { get; set; } + + [ForeignKey(nameof(CategoryId))] + public virtual Category Category { get; set; } + + [ForeignKey(nameof(CompetitionId))] + public virtual Competition Competition { get; set; } - public virtual ICollection Competitions { get; set; } } } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/EntityFrameworkCore/Seed/CompetitionBuilder.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/EntityFrameworkCore/Seed/CompetitionBuilder.cs index 418f36c..4e724c5 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/EntityFrameworkCore/Seed/CompetitionBuilder.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/EntityFrameworkCore/Seed/CompetitionBuilder.cs @@ -29,6 +29,9 @@ namespace SystemKonkursow.EntityFrameworkCore.Seed CreateOneCategory("Język niemiecki"); CreateOneCategory("Historia"); CreateOneCategory("Informatyka"); + CreateOneCategory("Muzyka"); + CreateOneCategory("Plastyka"); + CreateOneCategory("Religia"); } @@ -36,29 +39,38 @@ namespace SystemKonkursow.EntityFrameworkCore.Seed { Random rnd = new Random(); + var exampleCategory = new Domain.Category() + { + Name = name + }; + var competitions = new List { }; for (int competitionId = 1; competitionId < CompetitionsNumber; competitionId++) { - competitions.Add(new Domain.Competition + var exampleCompetition = new Domain.Competition { CreatorUserId = 3, Name = name + " : konkurs nr " + competitionId, StartDate = new DateTime(2019, rnd.Next(1, 4), rnd.Next(1, 29)), EndDate = new DateTime(2019, rnd.Next(4, 7), rnd.Next(1, 31)), Description = "Opis konkursu nr " + competitionId + " z kategorii: " + name, - Prize = "Opis nagród dla konkursu nr " + competitionId + " z kategorii: " + name - }); + Prize = "Opis nagród dla konkursu nr " + competitionId + " z kategorii: " + name, + MinClass = rnd.Next(1, 5), + MaxClass = rnd.Next(5, 9) + }; + + var exampleCompetitionCategory = new Domain.CompetitionCategory() + { + Category = exampleCategory, + Competition = exampleCompetition + }; + + _context.CompetitionCategories.Add(exampleCompetitionCategory); } - - var exampleCategory = new Domain.CompetitionCategory() - { - Name = name, - Competitions = competitions - }; - - _context.CompetitionCategories.Add(exampleCategory); + _context.SaveChanges(); + } } } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/EntityFrameworkCore/SystemKonkursowDbContext.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/EntityFrameworkCore/SystemKonkursowDbContext.cs index 8a6674b..5de643e 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/EntityFrameworkCore/SystemKonkursowDbContext.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/EntityFrameworkCore/SystemKonkursowDbContext.cs @@ -18,6 +18,8 @@ namespace SystemKonkursow.EntityFrameworkCore public DbSet CompetitionCategories { get; set; } + public DbSet Categories { get; set; } + public DbSet Competitions { get; set; } } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/Migrations/SystemKonkursowDbContextModelSnapshot.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/Migrations/SystemKonkursowDbContextModelSnapshot.cs index 0512071..20accc7 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/Migrations/SystemKonkursowDbContextModelSnapshot.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.EntityFrameworkCore/Migrations/SystemKonkursowDbContextModelSnapshot.cs @@ -1008,14 +1008,25 @@ namespace SystemKonkursow.Migrations b.ToTable("AbpUsers"); }); + modelBuilder.Entity("SystemKonkursow.Domain.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + modelBuilder.Entity("SystemKonkursow.Domain.Competition", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("CompetitionCategoryId"); - b.Property("CreationTime"); b.Property("CreatorUserId"); @@ -1034,6 +1045,10 @@ namespace SystemKonkursow.Migrations b.Property("LastModifierUserId"); + b.Property("MaxClass"); + + b.Property("MinClass"); + b.Property("Name"); b.Property("Prize"); @@ -1042,8 +1057,6 @@ namespace SystemKonkursow.Migrations b.HasKey("Id"); - b.HasIndex("CompetitionCategoryId"); - b.HasIndex("CreatorUserId"); b.ToTable("Competitions"); @@ -1055,10 +1068,16 @@ namespace SystemKonkursow.Migrations .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("Name"); + b.Property("CategoryId"); + + b.Property("CompetitionId"); b.HasKey("Id"); + b.HasIndex("CategoryId"); + + b.HasIndex("CompetitionId"); + b.ToTable("CompetitionCategories"); }); @@ -1265,16 +1284,24 @@ namespace SystemKonkursow.Migrations modelBuilder.Entity("SystemKonkursow.Domain.Competition", b => { - b.HasOne("SystemKonkursow.Domain.CompetitionCategory", "CompetitionCategory") - .WithMany("Competitions") - .HasForeignKey("CompetitionCategoryId") - .OnDelete(DeleteBehavior.Cascade); - b.HasOne("SystemKonkursow.Authorization.Users.User", "Creator") .WithMany() .HasForeignKey("CreatorUserId"); }); + modelBuilder.Entity("SystemKonkursow.Domain.CompetitionCategory", b => + { + b.HasOne("SystemKonkursow.Domain.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("SystemKonkursow.Domain.Competition", "Competition") + .WithMany() + .HasForeignKey("CompetitionId") + .OnDelete(DeleteBehavior.Cascade); + }); + modelBuilder.Entity("SystemKonkursow.MultiTenancy.Tenant", b => { b.HasOne("SystemKonkursow.Authorization.Users.User", "CreatorUser")