Finished first iteration over ordering.data
This commit is contained in:
parent
1ae4d01f82
commit
d25f1c64a9
@ -4,6 +4,7 @@
|
||||
using Application.Queries;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Models;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -13,7 +14,7 @@
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IOrderQueries _orderQueries;
|
||||
|
||||
public OrdersController(IMediator mediator,IOrderQueries orderQueries)
|
||||
public OrdersController(IMediator mediator, IOrderQueries orderQueries)
|
||||
{
|
||||
if (mediator == null)
|
||||
{
|
||||
@ -31,9 +32,21 @@
|
||||
|
||||
[Route("new")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AddOrder()
|
||||
public async Task<IActionResult> AddOrder([FromBody]NewOrderViewModel order)
|
||||
{
|
||||
var newOrderRequest = new NewOrderRequest();
|
||||
var newOrderRequest = new NewOrderRequest()
|
||||
{
|
||||
Buyer =GetUserName(), //TODO
|
||||
CardTypeId = 1, //TODO
|
||||
CardHolderName = order.CardHolderName,
|
||||
CardNumber = order.CardNumber,
|
||||
CardExpiration = order.CardExpiration,
|
||||
CardSecurityNumber = order.CardSecurityNumber,
|
||||
State = order.ShippingState,
|
||||
City = order.ShippingCity,
|
||||
Country = order.ShippingCountry,
|
||||
Street = order.ShippingStreet
|
||||
};
|
||||
|
||||
var added = await _mediator.SendAsync(newOrderRequest);
|
||||
|
||||
@ -45,50 +58,38 @@
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
|
||||
[Route("cancel/{orderId:int}")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CancelOrder(int orderId)
|
||||
{
|
||||
var cancelOrderRequest = new CancelOrderRequest(orderId);
|
||||
|
||||
var cancelled = await _mediator.SendAsync(cancelOrderRequest);
|
||||
|
||||
if (cancelled)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
|
||||
[Route("{orderId:int}")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetOrder(int orderId)
|
||||
{
|
||||
var order = await _orderQueries.GetOrder(orderId);
|
||||
|
||||
if ( order != null)
|
||||
{
|
||||
Ok(order);
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
|
||||
return Ok(order);
|
||||
}
|
||||
|
||||
[Route("pending")]
|
||||
[Route("")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetPendingOrders(int orderId)
|
||||
public async Task<IActionResult> GetOrders()
|
||||
{
|
||||
var orders = await _orderQueries.GetPendingOrders();
|
||||
var orders = await _orderQueries.GetOrders();
|
||||
|
||||
if (orders.Any())
|
||||
{
|
||||
Ok(orders);
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
return Ok(orders);
|
||||
}
|
||||
|
||||
[Route("cardtypes")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetCardTypes()
|
||||
{
|
||||
var cardTypes = await _orderQueries.GetCardTypes();
|
||||
|
||||
return Ok(cardTypes);
|
||||
}
|
||||
|
||||
string GetUserName()
|
||||
{
|
||||
return "MOCK";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.ActionResults
|
||||
{
|
||||
using AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
public class InternalServerErrorObjectResult : ObjectResult
|
||||
{
|
||||
public InternalServerErrorObjectResult(object error)
|
||||
: base(error)
|
||||
{
|
||||
StatusCode = StatusCodes.Status500InternalServerError;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.AutofacModules
|
||||
{
|
||||
using Application.Queries;
|
||||
using Autofac;
|
||||
using Domain.Repositories;
|
||||
using Ordering.Infrastructure.Repositories;
|
||||
|
||||
public class ApplicationModule
|
||||
:Autofac.Module
|
||||
{
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterType<OrderQueries>()
|
||||
.As<IOrderQueries>()
|
||||
.InstancePerLifetimeScope();
|
||||
|
||||
builder.RegisterType<BuyerRepository>()
|
||||
.As<IBuyerRepository>()
|
||||
.InstancePerLifetimeScope();
|
||||
|
||||
builder.RegisterType<OrderRepository>()
|
||||
.As<IOrderRepository>()
|
||||
.InstancePerLifetimeScope();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.AutofacModules
|
||||
{
|
||||
using Application.Commands;
|
||||
using Application.Decorators;
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
using MediatR;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
public class MediatorModule : Autofac.Module
|
||||
{
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly)
|
||||
.AsImplementedInterfaces();
|
||||
|
||||
builder.RegisterAssemblyTypes(typeof(NewOrderRequest).GetTypeInfo().Assembly)
|
||||
.As(o => o.GetInterfaces()
|
||||
.Where(i => i.IsClosedTypeOf(typeof(IAsyncRequestHandler<,>)))
|
||||
.Select(i => new KeyedService("IAsyncRequestHandler", i)));
|
||||
|
||||
builder.Register<SingleInstanceFactory>(context =>
|
||||
{
|
||||
var componentContext = context.Resolve<IComponentContext>();
|
||||
|
||||
return t => componentContext.Resolve(t);
|
||||
});
|
||||
|
||||
builder.Register<MultiInstanceFactory>(context =>
|
||||
{
|
||||
var componentContext = context.Resolve<IComponentContext>();
|
||||
|
||||
return t => (IEnumerable<object>)componentContext.Resolve(typeof(IEnumerable<>).MakeGenericType(t));
|
||||
});
|
||||
|
||||
builder.RegisterGenericDecorator(typeof(LogDecorator<,>),
|
||||
typeof(IAsyncRequestHandler<,>),
|
||||
"IAsyncRequestHandler");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Filters
|
||||
{
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.ActionResults;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public class HttpGlobalExceptionFilter : IExceptionFilter
|
||||
{
|
||||
private readonly IHostingEnvironment env;
|
||||
private readonly ILogger<HttpGlobalExceptionFilter> logger;
|
||||
|
||||
public HttpGlobalExceptionFilter(IHostingEnvironment env, ILogger<HttpGlobalExceptionFilter> logger)
|
||||
{
|
||||
this.env = env;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void OnException(ExceptionContext context)
|
||||
{
|
||||
logger.LogError(new EventId(context.Exception.HResult),
|
||||
context.Exception,
|
||||
context.Exception.Message);
|
||||
|
||||
var json = new JsonErrorResponse
|
||||
{
|
||||
Messages = new[] { "An error ocurr.Try it again." }
|
||||
};
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
json.DeveloperMeesage = context.Exception;
|
||||
}
|
||||
|
||||
context.Result = new InternalServerErrorObjectResult(json);
|
||||
}
|
||||
|
||||
private class JsonErrorResponse
|
||||
{
|
||||
public string[] Messages { get; set; }
|
||||
|
||||
public object DeveloperMeesage { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -8,8 +8,8 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
||||
namespace Ordering.API.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(OrderingContext))]
|
||||
[Migration("20161122162602_initial")]
|
||||
partial class initial
|
||||
[Migration("20161124133626_InitialModel")]
|
||||
partial class InitialModel
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
@ -29,16 +29,8 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.Property<string>("Country");
|
||||
|
||||
b.Property<string>("CountryCode");
|
||||
|
||||
b.Property<double>("Latitude");
|
||||
|
||||
b.Property<double>("Longitude");
|
||||
|
||||
b.Property<string>("State");
|
||||
|
||||
b.Property<string>("StateCode");
|
||||
|
||||
b.Property<string>("Street");
|
||||
|
||||
b.Property<string>("ZipCode");
|
||||
@ -62,15 +54,21 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FullName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("buyers","ordering");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValue(1);
|
||||
|
||||
b.Property<string>("Name");
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasAnnotation("MaxLength", 200);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -85,8 +83,6 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
||||
|
||||
b.Property<int?>("BillingAddressId");
|
||||
|
||||
b.Property<int>("BuyerId");
|
||||
|
||||
b.Property<DateTime>("OrderDate");
|
||||
@ -99,8 +95,6 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BillingAddressId");
|
||||
|
||||
b.HasIndex("BuyerId");
|
||||
|
||||
b.HasIndex("PaymentId");
|
||||
@ -142,9 +136,12 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValue(1);
|
||||
|
||||
b.Property<string>("Name");
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasAnnotation("MaxLength", 200);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -159,6 +156,8 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
||||
|
||||
b.Property<int>("BuyerId");
|
||||
|
||||
b.Property<string>("CardHolderName")
|
||||
.IsRequired()
|
||||
.HasAnnotation("MaxLength", 200);
|
||||
@ -175,6 +174,8 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuyerId");
|
||||
|
||||
b.HasIndex("CardTypeId");
|
||||
|
||||
b.ToTable("payments","ordering");
|
||||
@ -182,11 +183,6 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "BillingAddress")
|
||||
.WithMany()
|
||||
.HasForeignKey("BillingAddressId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", "Buyer")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuyerId")
|
||||
@ -194,8 +190,7 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", "Payment")
|
||||
.WithMany()
|
||||
.HasForeignKey("PaymentId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
.HasForeignKey("PaymentId");
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "ShippingAddress")
|
||||
.WithMany()
|
||||
@ -217,6 +212,11 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer")
|
||||
.WithMany("Payments")
|
||||
.HasForeignKey("BuyerId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", "CardType")
|
||||
.WithMany()
|
||||
.HasForeignKey("CardTypeId")
|
@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
|
||||
namespace Ordering.API.Infrastructure.Migrations
|
||||
{
|
||||
public partial class initial : Migration
|
||||
public partial class InitialModel : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
@ -36,11 +36,7 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
||||
City = table.Column<string>(nullable: true),
|
||||
Country = table.Column<string>(nullable: true),
|
||||
CountryCode = table.Column<string>(nullable: true),
|
||||
Latitude = table.Column<double>(nullable: false),
|
||||
Longitude = table.Column<double>(nullable: false),
|
||||
State = table.Column<string>(nullable: true),
|
||||
StateCode = table.Column<string>(nullable: true),
|
||||
Street = table.Column<string>(nullable: true),
|
||||
ZipCode = table.Column<string>(nullable: true)
|
||||
},
|
||||
@ -67,9 +63,8 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
schema: "ordering",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(nullable: true)
|
||||
Id = table.Column<int>(nullable: false, defaultValue: 1),
|
||||
Name = table.Column<string>(maxLength: 200, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -81,9 +76,8 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
schema: "ordering",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(nullable: true)
|
||||
Id = table.Column<int>(nullable: false, defaultValue: 1),
|
||||
Name = table.Column<string>(maxLength: 200, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -96,6 +90,7 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false),
|
||||
BuyerId = table.Column<int>(nullable: false),
|
||||
CardHolderName = table.Column<string>(maxLength: 200, nullable: false),
|
||||
CardNumber = table.Column<string>(maxLength: 25, nullable: false),
|
||||
CardTypeId = table.Column<int>(nullable: false),
|
||||
@ -105,6 +100,13 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_payments", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_payments_buyers_BuyerId",
|
||||
column: x => x.BuyerId,
|
||||
principalSchema: "ordering",
|
||||
principalTable: "buyers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_payments_cardtypes_CardTypeId",
|
||||
column: x => x.CardTypeId,
|
||||
@ -120,7 +122,6 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false),
|
||||
BillingAddressId = table.Column<int>(nullable: true),
|
||||
BuyerId = table.Column<int>(nullable: false),
|
||||
OrderDate = table.Column<DateTime>(nullable: false),
|
||||
PaymentId = table.Column<int>(nullable: false),
|
||||
@ -130,13 +131,6 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_orders_address_BillingAddressId",
|
||||
column: x => x.BillingAddressId,
|
||||
principalSchema: "ordering",
|
||||
principalTable: "address",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "FK_orders_buyers_BuyerId",
|
||||
column: x => x.BuyerId,
|
||||
@ -150,7 +144,7 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
principalSchema: "ordering",
|
||||
principalTable: "payments",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_orders_address_ShippingAddressId",
|
||||
column: x => x.ShippingAddressId,
|
||||
@ -194,10 +188,11 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_orders_BillingAddressId",
|
||||
name: "IX_buyers_FullName",
|
||||
schema: "ordering",
|
||||
table: "orders",
|
||||
column: "BillingAddressId");
|
||||
table: "buyers",
|
||||
column: "FullName",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_orders_BuyerId",
|
||||
@ -229,6 +224,12 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
table: "orderItems",
|
||||
column: "OrderId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_payments_BuyerId",
|
||||
schema: "ordering",
|
||||
table: "payments",
|
||||
column: "BuyerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_payments_CardTypeId",
|
||||
schema: "ordering",
|
||||
@ -258,22 +259,22 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
name: "orders",
|
||||
schema: "ordering");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "address",
|
||||
schema: "ordering");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "buyers",
|
||||
schema: "ordering");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "payments",
|
||||
schema: "ordering");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "address",
|
||||
schema: "ordering");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "orderstatus",
|
||||
schema: "ordering");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "buyers",
|
||||
schema: "ordering");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "cardtypes",
|
||||
schema: "ordering");
|
@ -28,16 +28,8 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.Property<string>("Country");
|
||||
|
||||
b.Property<string>("CountryCode");
|
||||
|
||||
b.Property<double>("Latitude");
|
||||
|
||||
b.Property<double>("Longitude");
|
||||
|
||||
b.Property<string>("State");
|
||||
|
||||
b.Property<string>("StateCode");
|
||||
|
||||
b.Property<string>("Street");
|
||||
|
||||
b.Property<string>("ZipCode");
|
||||
@ -61,15 +53,21 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FullName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("buyers","ordering");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValue(1);
|
||||
|
||||
b.Property<string>("Name");
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasAnnotation("MaxLength", 200);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -84,8 +82,6 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
||||
|
||||
b.Property<int?>("BillingAddressId");
|
||||
|
||||
b.Property<int>("BuyerId");
|
||||
|
||||
b.Property<DateTime>("OrderDate");
|
||||
@ -98,8 +94,6 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BillingAddressId");
|
||||
|
||||
b.HasIndex("BuyerId");
|
||||
|
||||
b.HasIndex("PaymentId");
|
||||
@ -141,9 +135,12 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValue(1);
|
||||
|
||||
b.Property<string>("Name");
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasAnnotation("MaxLength", 200);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -158,6 +155,8 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
||||
|
||||
b.Property<int>("BuyerId");
|
||||
|
||||
b.Property<string>("CardHolderName")
|
||||
.IsRequired()
|
||||
.HasAnnotation("MaxLength", 200);
|
||||
@ -174,6 +173,8 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuyerId");
|
||||
|
||||
b.HasIndex("CardTypeId");
|
||||
|
||||
b.ToTable("payments","ordering");
|
||||
@ -181,11 +182,6 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "BillingAddress")
|
||||
.WithMany()
|
||||
.HasForeignKey("BillingAddressId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", "Buyer")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuyerId")
|
||||
@ -193,8 +189,7 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", "Payment")
|
||||
.WithMany()
|
||||
.HasForeignKey("PaymentId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
.HasForeignKey("PaymentId");
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "ShippingAddress")
|
||||
.WithMany()
|
||||
@ -216,6 +211,11 @@ namespace Ordering.API.Infrastructure.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer")
|
||||
.WithMany("Payments")
|
||||
.HasForeignKey("BuyerId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", "CardType")
|
||||
.WithMany()
|
||||
.HasForeignKey("CardTypeId")
|
||||
|
@ -1,12 +1,12 @@
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure
|
||||
{
|
||||
using AspNetCore.Builder;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain;
|
||||
using Ordering.Infrastructure;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
public class OrderingContextSeed
|
||||
{
|
||||
public static async Task SeedAsync(IApplicationBuilder applicationBuilder)
|
||||
@ -18,6 +18,22 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure
|
||||
{
|
||||
context.Database.Migrate();
|
||||
|
||||
if (!context.CardTypes.Any())
|
||||
{
|
||||
context.CardTypes.Add(CardType.Amex);
|
||||
context.CardTypes.Add(CardType.Visa);
|
||||
context.CardTypes.Add(CardType.MasterCard);
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
if (!context.OrderStatus.Any())
|
||||
{
|
||||
context.OrderStatus.Add(OrderStatus.Canceled);
|
||||
context.OrderStatus.Add(OrderStatus.InProcess);
|
||||
context.OrderStatus.Add(OrderStatus.Shipped);
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Models
|
||||
{
|
||||
public class NewOrderViewModel
|
||||
{
|
||||
public string ShippingCity { get; set; }
|
||||
|
||||
public string ShippingStreet { get; set; }
|
||||
|
||||
public string ShippingState { get; set; }
|
||||
|
||||
public string ShippingCountry { get; set; }
|
||||
|
||||
public string CardType { get; set; }
|
||||
|
||||
public string CardNumber { get; set; }
|
||||
|
||||
public string CardHolderName { get; set; }
|
||||
|
||||
public DateTime CardExpiration { get; set; }
|
||||
|
||||
public string CardSecurityNumber { get; set; }
|
||||
}
|
||||
}
|
@ -1,187 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Welcome to ASP.NET Core</title>
|
||||
<style>
|
||||
html {
|
||||
background: #f1f1f1;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background: #fff;
|
||||
color: #505050;
|
||||
font: 14px 'Segoe UI', tahoma, arial, helvetica, sans-serif;
|
||||
margin: 1%;
|
||||
min-height: 95.5%;
|
||||
border: 1px solid silver;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#header {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#header h1 {
|
||||
font-size: 44px;
|
||||
font-weight: normal;
|
||||
margin: 0;
|
||||
padding: 10px 30px 10px 30px;
|
||||
}
|
||||
|
||||
#header span {
|
||||
margin: 0;
|
||||
padding: 0 30px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#header p {
|
||||
font-size: 20px;
|
||||
color: #fff;
|
||||
background: #007acc;
|
||||
padding: 0 30px;
|
||||
line-height: 50px;
|
||||
margin-top: 25px;
|
||||
|
||||
}
|
||||
|
||||
#header p a {
|
||||
color: #fff;
|
||||
text-decoration: underline;
|
||||
font-weight: bold;
|
||||
padding-right: 35px;
|
||||
background: no-repeat right bottom url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAWCAMAAAAcqPc3AAAANlBMVEUAAAAAeswfitI9mthXp91us+KCvuaTx+mjz+2x1u+83PLH4vTR5/ba7Pjj8Pns9fv1+v3////wy3dWAAAAAXRSTlMAQObYZgAAAHxJREFUeNp9kVcSwCAIRMHUYoH7XzaxOxJ9P8oyQ1uIqNPwh3s2aLmIM2YtqrLcQIeQEylhuCeUOlhgve5yoBCfWmlnlgkN4H8ykbpaE7gR03AbUHiwoOxUH9Xp+ubd41p1HF3mBPrfC87BHeTdaB3ceeKL9HGpcvX9zu6+DdMWT9KQPvYAAAAASUVORK5CYII=);
|
||||
}
|
||||
|
||||
#main {
|
||||
padding: 5px 30px;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.section {
|
||||
width: 21.7%;
|
||||
float: left;
|
||||
margin: 0 0 0 4%;
|
||||
}
|
||||
|
||||
.section h2 {
|
||||
font-size: 13px;
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
border-bottom: 1px solid silver;
|
||||
padding-bottom: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.section.first {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.section.first h2 {
|
||||
font-size: 24px;
|
||||
text-transform: none;
|
||||
margin-bottom: 25px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.section.first li {
|
||||
border-top: 1px solid silver;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.section.last {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
li {
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #267cb2;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#footer {
|
||||
clear: both;
|
||||
padding-top: 50px;
|
||||
}
|
||||
|
||||
#footer p {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="header">
|
||||
<h1>Welcome to ASP.NET Core</h1>
|
||||
<span>
|
||||
We've made some big updates in this release, so it’s <b>important</b> that you spend
|
||||
a few minutes to learn what’s new.
|
||||
</span>
|
||||
<p>You've created a new ASP.NET Core project. <a href="http://go.microsoft.com/fwlink/?LinkId=518016">Learn what's new</a></p>
|
||||
</div>
|
||||
|
||||
<div id="main">
|
||||
<div class="section first">
|
||||
<h2>This application consists of:</h2>
|
||||
<ul>
|
||||
<li>Sample pages using ASP.NET Core MVC</li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=518004">Bower</a> for managing client-side libraries</li>
|
||||
<li>Theming using <a href="http://go.microsoft.com/fwlink/?LinkID=398939">Bootstrap</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2>How to</h2>
|
||||
<ul>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkID=398600">Add a Controller and View</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkID=699562">Add an appsetting in config and access it in app.</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=699315">Manage User Secrets using Secret Manager.</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=699316">Use logging to log a message.</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=699317">Add packages using NuGet.</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=699318">Add client packages using Bower.</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=699319">Target development, staging or production environment.</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2>Overview</h2>
|
||||
<ul>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=518008">Conceptual overview of what is ASP.NET Core</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=699320">Fundamentals of ASP.NET Core such as Startup and middleware.</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=398602">Working with Data</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkId=398603">Security</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkID=699321">Client side development</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkID=699322">Develop on different platforms</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkID=699323">Read more on the documentation site</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section last">
|
||||
<h2>Run & Deploy</h2>
|
||||
<ul>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkID=517851">Run your app</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkID=517853">Run tools such as EF migrations and more</a></li>
|
||||
<li><a href="http://go.microsoft.com/fwlink/?LinkID=398609">Publish to Microsoft Azure Web Apps</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
<p>We would love to hear your <a href="http://go.microsoft.com/fwlink/?LinkId=518015">feedback</a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -11,7 +11,7 @@
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/environmentInfo/machinename",
|
||||
"launchUrl": "/swagger/ui",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
||||
{
|
||||
using Autofac;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using Infrastructure;
|
||||
using Infrastructure.AutofacModules;
|
||||
using Infrastructure.Filters;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@ -8,6 +13,7 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ordering.Infrastructure;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
public class Startup
|
||||
@ -31,10 +37,16 @@
|
||||
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Add framework services.
|
||||
services.AddMvc();
|
||||
|
||||
services.AddMvc(options=>
|
||||
{
|
||||
|
||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||
|
||||
}).AddControllersAsServices();
|
||||
|
||||
services.AddEntityFrameworkSqlServer()
|
||||
.AddDbContext<OrderingContext>(options =>
|
||||
@ -56,8 +68,22 @@
|
||||
});
|
||||
});
|
||||
|
||||
services.AddMediatR(typeof(Startup)); //TODO:pending
|
||||
|
||||
services.AddSingleton<IConfiguration>(this.Configuration);
|
||||
|
||||
services.AddOptions();
|
||||
|
||||
|
||||
|
||||
//configure autofac
|
||||
|
||||
var container = new ContainerBuilder();
|
||||
container.Populate(services);
|
||||
|
||||
container.RegisterModule(new MediatorModule());
|
||||
container.RegisterModule(new ApplicationModule());
|
||||
|
||||
|
||||
return new AutofacServiceProvider(container.Build());
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
@ -69,7 +95,9 @@
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
|
||||
OrderingContextSeed.SeedAsync(app).Wait();
|
||||
|
||||
app.UseMvc();
|
||||
|
||||
app.UseSwagger()
|
||||
|
@ -10,16 +10,13 @@ services:
|
||||
- ConnectionString=Server=ordering.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
|
||||
ports:
|
||||
- "81:80"
|
||||
# (Go to Production): For secured/final deployment, remove Ports mapping and
|
||||
# leave just the internal expose section
|
||||
# expose:
|
||||
# - "80"
|
||||
extra_hosts:
|
||||
- "CESARDLBOOKVHD:10.0.75.1"
|
||||
depends_on:
|
||||
- ordering.data
|
||||
|
||||
ordering.data:
|
||||
image: eshop/ordering.data.sqlserver.linux
|
||||
image: microsoft/mssql-server-linux
|
||||
environment:
|
||||
- ACCEPT_EULA=Y
|
||||
- SA_PASSWORD=Pass@word
|
||||
ports:
|
||||
- "1433:1433"
|
@ -5,6 +5,7 @@
|
||||
"type": "platform"
|
||||
},
|
||||
"MediatR.Extensions.Microsoft.DependencyInjection": "1.0.1",
|
||||
"Autofac.Extensions.DependencyInjection": "4.0.0",
|
||||
"Microsoft.AspNetCore.Mvc": "1.0.0",
|
||||
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
|
||||
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
|
||||
@ -12,6 +13,7 @@
|
||||
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
|
||||
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
|
||||
"Microsoft.Extensions.Configuration.Json": "1.0.0",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "1.0.0",
|
||||
"Microsoft.Extensions.Logging.Console": "1.0.0",
|
||||
"Microsoft.Extensions.Logging.Debug": "1.0.0",
|
||||
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user