Skip to content

Commit d9ce98d

Browse files
committed
Added Category entity (for testing).
1 parent c9ee399 commit d9ce98d

File tree

10 files changed

+189
-6
lines changed

10 files changed

+189
-6
lines changed

src/AbpCompanyName.AbpProjectName.Application/Products/Dtos/ProductDto.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using Abp.Application.Services.Dto;
1+
using System;
2+
using Abp.Application.Services.Dto;
23
using Abp.AutoMapper;
34

45
namespace AbpCompanyName.AbpProjectName.Products.Dtos
56
{
67
[AutoMapFrom(typeof(Product))]
78
public class ProductDto : EntityDto
89
{
10+
public Guid CategoryId { get; set; }
11+
912
public string Name { get; set; }
1013

1114
public float? Price { get; set; }

src/AbpCompanyName.AbpProjectName.Application/Products/ProductAppService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Abp.Application.Services.Dto;
44
using Abp.Domain.Repositories;
55
using AbpCompanyName.AbpProjectName.Products.Dtos;
6+
using Microsoft.EntityFrameworkCore;
67

78
namespace AbpCompanyName.AbpProjectName.Products
89
{
@@ -17,7 +18,11 @@ public ProductAppService(IRepository<Product> productRepository)
1718

1819
public async Task<ListResultOutput<ProductDto>> GetAllProducts()
1920
{
20-
var products = await _productRepository.GetAllListAsync();
21+
var products = await _productRepository
22+
.GetAll()
23+
.Include(product => product.Category)
24+
.ToListAsync();
25+
2126
return new ListResultOutput<ProductDto>(
2227
ObjectMapper.Map<List<ProductDto>>(products)
2328
);

src/AbpCompanyName.AbpProjectName.Application/project.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"version": "1.0.0.0-*",
33

44
"dependencies": {
5-
"Abp.AutoMapper": "0.10.1",
6-
"AbpCompanyName.AbpProjectName.Core": "1.0.0.0-*"
5+
"AbpCompanyName.AbpProjectName.Core": "1.0.0.0-*",
6+
"Abp.EntityFrameworkCore": "0.10.1",
7+
"Abp.AutoMapper": "0.10.1"
78
},
89

910
"frameworks": {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations.Schema;
3+
using Abp.Domain.Entities;
4+
5+
namespace AbpCompanyName.AbpProjectName.Products
6+
{
7+
public class Category : Entity<Guid>
8+
{
9+
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
10+
public override Guid Id { get; set; }
11+
12+
public string Name { get; set; }
13+
}
14+
}

src/AbpCompanyName.AbpProjectName.Core/Products/Product.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public class Product : AuditedEntity
99
{
1010
public const int MaxNameLength = 128;
1111

12+
[Required]
13+
public virtual Category Category { get; set; }
14+
1215
[Required]
1316
[StringLength(MaxNameLength)]
1417
public string Name { get; set; }

src/AbpCompanyName.AbpProjectName.EntityFrameworkCore/Migrations/20160722072351_Added_Category.Designer.cs

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.EntityFrameworkCore.Migrations;
4+
5+
namespace AbpCompanyName.AbpProjectName.EntityFrameworkCore.Migrations
6+
{
7+
public partial class Added_Category : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.CreateTable(
12+
name: "Category",
13+
columns: table => new
14+
{
15+
Id = table.Column<Guid>(nullable: false),
16+
Name = table.Column<string>(nullable: true)
17+
},
18+
constraints: table =>
19+
{
20+
table.PrimaryKey("PK_Category", x => x.Id);
21+
});
22+
23+
migrationBuilder.AddColumn<Guid>(
24+
name: "CategoryId",
25+
table: "Products",
26+
nullable: false,
27+
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
28+
29+
migrationBuilder.CreateIndex(
30+
name: "IX_Products_CategoryId",
31+
table: "Products",
32+
column: "CategoryId");
33+
34+
migrationBuilder.AddForeignKey(
35+
name: "FK_Products_Category_CategoryId",
36+
table: "Products",
37+
column: "CategoryId",
38+
principalTable: "Category",
39+
principalColumn: "Id",
40+
onDelete: ReferentialAction.Cascade);
41+
}
42+
43+
protected override void Down(MigrationBuilder migrationBuilder)
44+
{
45+
migrationBuilder.DropForeignKey(
46+
name: "FK_Products_Category_CategoryId",
47+
table: "Products");
48+
49+
migrationBuilder.DropIndex(
50+
name: "IX_Products_CategoryId",
51+
table: "Products");
52+
53+
migrationBuilder.DropColumn(
54+
name: "CategoryId",
55+
table: "Products");
56+
57+
migrationBuilder.DropTable(
58+
name: "Category");
59+
}
60+
}
61+
}

src/AbpCompanyName.AbpProjectName.EntityFrameworkCore/Migrations/AbpProjectNameDbContextModelSnapshot.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,29 @@ partial class AbpProjectNameDbContextModelSnapshot : ModelSnapshot
1313
protected override void BuildModel(ModelBuilder modelBuilder)
1414
{
1515
modelBuilder
16-
.HasAnnotation("ProductVersion", "1.0.0-rc2-20901")
16+
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431")
1717
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
1818

19+
modelBuilder.Entity("AbpCompanyName.AbpProjectName.Products.Category", b =>
20+
{
21+
b.Property<Guid>("Id")
22+
.ValueGeneratedOnAdd();
23+
24+
b.Property<string>("Name");
25+
26+
b.HasKey("Id");
27+
28+
b.ToTable("Category");
29+
});
30+
1931
modelBuilder.Entity("AbpCompanyName.AbpProjectName.Products.Product", b =>
2032
{
2133
b.Property<int>("Id")
2234
.ValueGeneratedOnAdd();
2335

36+
b.Property<Guid?>("CategoryId")
37+
.IsRequired();
38+
2439
b.Property<DateTime>("CreationTime");
2540

2641
b.Property<long?>("CreatorUserId");
@@ -37,8 +52,18 @@ protected override void BuildModel(ModelBuilder modelBuilder)
3752

3853
b.HasKey("Id");
3954

55+
b.HasIndex("CategoryId");
56+
4057
b.ToTable("Products");
4158
});
59+
60+
modelBuilder.Entity("AbpCompanyName.AbpProjectName.Products.Product", b =>
61+
{
62+
b.HasOne("AbpCompanyName.AbpProjectName.Products.Category", "Category")
63+
.WithMany()
64+
.HasForeignKey("CategoryId")
65+
.OnDelete(DeleteBehavior.Cascade);
66+
});
4267
}
4368
}
4469
}

src/AbpCompanyName.AbpProjectName.Web/wwwroot/js/views/home/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
$('<li>')
1616
.attr('data-id', product.id)
17+
.attr('data-category-id', product.categoryId)
1718
.html(product.name + " - " + product.price)
1819
.appendTo(_$productList);
1920
}

src/AbpCompanyName.AbpProjectName.Web/wwwroot/js/views/home/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)