-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
924803b
commit bf2dd0c
Showing
19 changed files
with
765 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
Chapter02/FlixOne.BookStore.ProductService/FlixOne.BookStore.ProductService.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F9ADCB4C-CCFA-4D90-9CE4-9DBCB1B799DB}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DF873B52-DC70-4CD7-A5A4-2691DA59DF50}" | ||
ProjectSection(SolutionItems) = preProject | ||
global.json = global.json | ||
EndProjectSection | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "FlixOne.BookStore.ProductService", "src\FlixOne.BookStore.ProductService\FlixOne.BookStore.ProductService.xproj", "{E0DEA7C7-D535-4D0E-B26A-E1020CF3EA92}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{E0DEA7C7-D535-4D0E-B26A-E1020CF3EA92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E0DEA7C7-D535-4D0E-B26A-E1020CF3EA92}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E0DEA7C7-D535-4D0E-B26A-E1020CF3EA92}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E0DEA7C7-D535-4D0E-B26A-E1020CF3EA92}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{E0DEA7C7-D535-4D0E-B26A-E1020CF3EA92} = {F9ADCB4C-CCFA-4D90-9CE4-9DBCB1B799DB} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"projects": [ "src", "test" ], | ||
"sdk": { | ||
"version": "1.0.0-preview2-003131" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
....BookStore.ProductService/src/FlixOne.BookStore.ProductService/Contexts/ProductContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using FlixOne.BookStore.ProductService.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace FlixOne.BookStore.ProductService.Contexts | ||
{ | ||
public class ProductContext : DbContext | ||
{ | ||
public ProductContext(DbContextOptions<ProductContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public ProductContext() | ||
{ | ||
} | ||
|
||
public DbSet<Product> Products { get; set; } | ||
public DbSet<Category> Categories { get; set; } | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...tore.ProductService/src/FlixOne.BookStore.ProductService/Controllers/ProductController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Linq; | ||
using FlixOne.BookStore.ProductService.Models; | ||
using FlixOne.BookStore.ProductService.Persistence; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace FlixOne.BookStore.ProductService.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class ProductController : Controller | ||
{ | ||
private readonly IProductRepository _productRepository; | ||
|
||
public ProductController(IProductRepository productRepository) | ||
{ | ||
_productRepository = productRepository; | ||
} | ||
|
||
public IActionResult Get() | ||
{ | ||
var productvm = _productRepository.GetAll().Select(product => new ProductViewModel | ||
{ | ||
CategoryId = product.CategoryId, | ||
CategoryDescription = product.Category.Description, | ||
CategoryName = product.Category.Name, | ||
ProductDescription = product.Description, | ||
ProductId = product.Id, | ||
ProductImage = product.Image, | ||
ProductName = product.Name, | ||
ProductPrice = product.Price | ||
}).ToList(); | ||
|
||
return new OkObjectResult(productvm); | ||
} | ||
|
||
//Rest of code has been removed | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...roductService/src/FlixOne.BookStore.ProductService/FlixOne.BookStore.ProductService.xproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>e0dea7c7-d535-4d0e-b26a-e1020cf3ea92</ProjectGuid> | ||
<RootNamespace>FlixOne.BookStore.ProductService</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
65 changes: 65 additions & 0 deletions
65
...FlixOne.BookStore.ProductService/Migrations/20170110204240_ProductdbMigration.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
...vice/src/FlixOne.BookStore.ProductService/Migrations/20170110204240_ProductdbMigration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
namespace FlixOne.BookStore.ProductService.Migrations | ||
{ | ||
public partial class ProductdbMigration : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Categories", | ||
columns: table => new | ||
{ | ||
Id = table.Column<Guid>(nullable: false), | ||
Description = table.Column<string>(nullable: true), | ||
Name = table.Column<string>(nullable: true) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Categories", x => x.Id); | ||
}); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "Products", | ||
columns: table => new | ||
{ | ||
Id = table.Column<Guid>(nullable: false), | ||
CategoryId = table.Column<Guid>(nullable: false), | ||
Description = table.Column<string>(nullable: true), | ||
Image = table.Column<string>(nullable: true), | ||
Name = table.Column<string>(nullable: true), | ||
Price = table.Column<decimal>(nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Products", x => x.Id); | ||
table.ForeignKey( | ||
name: "FK_Products_Categories_CategoryId", | ||
column: x => x.CategoryId, | ||
principalTable: "Categories", | ||
principalColumn: "Id", | ||
onDelete: ReferentialAction.Cascade); | ||
}); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Products_CategoryId", | ||
table: "Products", | ||
column: "CategoryId"); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Products"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "Categories"); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...uctService/src/FlixOne.BookStore.ProductService/Migrations/ProductContextModelSnapshot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using FlixOne.BookStore.ProductService.Contexts; | ||
|
||
namespace FlixOne.BookStore.ProductService.Migrations | ||
{ | ||
[DbContext(typeof(ProductContext))] | ||
partial class ProductContextModelSnapshot : ModelSnapshot | ||
{ | ||
protected override void BuildModel(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder | ||
.HasAnnotation("ProductVersion", "1.1.0-rtm-22752") | ||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); | ||
|
||
modelBuilder.Entity("FlixOne.BookStore.ProductService.Models.Category", b => | ||
{ | ||
b.Property<Guid>("Id") | ||
.ValueGeneratedOnAdd(); | ||
|
||
b.Property<string>("Description"); | ||
|
||
b.Property<string>("Name"); | ||
|
||
b.HasKey("Id"); | ||
|
||
b.ToTable("Categories"); | ||
}); | ||
|
||
modelBuilder.Entity("FlixOne.BookStore.ProductService.Models.Product", b => | ||
{ | ||
b.Property<Guid>("Id") | ||
.ValueGeneratedOnAdd(); | ||
|
||
b.Property<Guid>("CategoryId"); | ||
|
||
b.Property<string>("Description"); | ||
|
||
b.Property<string>("Image"); | ||
|
||
b.Property<string>("Name"); | ||
|
||
b.Property<decimal>("Price"); | ||
|
||
b.HasKey("Id"); | ||
|
||
b.HasIndex("CategoryId"); | ||
|
||
b.ToTable("Products"); | ||
}); | ||
|
||
modelBuilder.Entity("FlixOne.BookStore.ProductService.Models.Product", b => | ||
{ | ||
b.HasOne("FlixOne.BookStore.ProductService.Models.Category", "Category") | ||
.WithMany("Products") | ||
.HasForeignKey("CategoryId") | ||
.OnDelete(DeleteBehavior.Cascade); | ||
}); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../FlixOne.BookStore.ProductService/src/FlixOne.BookStore.ProductService/Models/Category.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace FlixOne.BookStore.ProductService.Models | ||
{ | ||
public class Category | ||
{ | ||
public Category() | ||
{ | ||
Products = new List<Product>(); | ||
} | ||
|
||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
public string Description { get; set; } | ||
public IEnumerable<Product> Products { get; set; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...2/FlixOne.BookStore.ProductService/src/FlixOne.BookStore.ProductService/Models/Product.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
|
||
namespace FlixOne.BookStore.ProductService.Models | ||
{ | ||
public class Product | ||
{ | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
public string Description { get; set; } | ||
public string Image { get; set; } | ||
public decimal Price { get; set; } | ||
public Guid CategoryId { get; set; } | ||
|
||
public virtual Category Category { get; set; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
....BookStore.ProductService/src/FlixOne.BookStore.ProductService/Models/ProductViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
|
||
namespace FlixOne.BookStore.ProductService.Models | ||
{ | ||
public class ProductViewModel | ||
{ | ||
public Guid ProductId { get; set; } | ||
public string ProductName { get; set; } | ||
public string ProductDescription { get; set; } | ||
public string ProductImage { get; set; } | ||
public decimal ProductPrice { get; set; } | ||
public Guid CategoryId { get; set; } | ||
public string CategoryName { get; set; } | ||
public string CategoryDescription { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ore.ProductService/src/FlixOne.BookStore.ProductService/Persistence/IProductRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using FlixOne.BookStore.ProductService.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace FlixOne.BookStore.ProductService.Persistence | ||
{ | ||
public interface IProductRepository | ||
{ | ||
void Add(Product product); | ||
IEnumerable<Product> GetAll(); | ||
Product GetBy(Guid id); | ||
void Remove(Guid id); | ||
void Update(Product product); | ||
} | ||
} |
Oops, something went wrong.