Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
packt-diwakar authored Jun 19, 2017
1 parent 924803b commit bf2dd0c
Show file tree
Hide file tree
Showing 19 changed files with 765 additions and 0 deletions.
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
6 changes: 6 additions & 0 deletions Chapter02/FlixOne.BookStore.ProductService/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003131"
}
}
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; }
}
}
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
}
}
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>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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");
}
}
}
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);
});
}
}
}
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; }
}
}
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; }
}
}
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; }
}
}
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);
}
}
Loading

0 comments on commit bf2dd0c

Please sign in to comment.