Skip to content

Commit 02df9d1

Browse files
committed
sql server ef.core adapted
1 parent ff9a370 commit 02df9d1

File tree

13 files changed

+223
-143
lines changed

13 files changed

+223
-143
lines changed

src/Ordering/Ordering.API/EventHandlers/BasketCheckoutEventHandler.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/Ordering/Ordering.API/Ordering.API.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
99
<PackageReference Include="MediatR" Version="8.0.1" />
1010
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
1115
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.3.1" />
1216
</ItemGroup>
1317

src/Ordering/Ordering.API/RabbitMQ/EventBusRabbitMQConsumer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ private void ReceivedEvent(object sender, BasicDeliverEventArgs e)
4545
var message = Encoding.UTF8.GetString(e.Body);
4646
var basketCheckoutEvent = JsonConvert.DeserializeObject<BasketCheckoutEvent>(message);
4747

48-
// TODO : stuff
49-
var command = _mapper.Map<CheckoutOrderCommand>(basketCheckoutEvent);
50-
var result = _mediator.Send(command);
48+
// Internal Checkout Operation Call
49+
var command = _mapper.Map<CheckoutOrderCommand>(basketCheckoutEvent);
50+
var result = _mediator.Send(command);
5151
}
5252
}
5353

src/Ordering/Ordering.API/Startup.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
using Microsoft.Extensions.DependencyInjection;
99
using Microsoft.Extensions.Hosting;
1010
using Microsoft.OpenApi.Models;
11-
using Ordering.API.Extentions;
1211
using Ordering.API.RabbitMQ;
12+
using Ordering.Application.Handlers;
1313
using Ordering.Core.Repositories;
1414
using Ordering.Core.Repositories.Base;
1515
using Ordering.Infrastructure.Data;
1616
using Ordering.Infrastructure.Repository;
1717
using Ordering.Infrastructure.Repository.Base;
1818
using RabbitMQ.Client;
19+
using System.Reflection;
1920

2021
namespace Ordering.API
2122
{
@@ -35,30 +36,29 @@ public void ConfigureServices(IServiceCollection services)
3536

3637
#region SqlServer Dependencies
3738

38-
// use in-memory database
39-
services.AddDbContext<OrderContext>(c =>
40-
c.UseInMemoryDatabase("OrderConnection"));
41-
42-
//// use real database
43-
//services.AddDbContext<AspnetRunContext>(c =>
44-
// c.UseSqlServer(Configuration.GetConnectionString("OrderConnection")));
39+
//// use in-memory database
40+
//services.AddDbContext<OrderContext>(c =>
41+
// c.UseInMemoryDatabase("OrderConnection"));
4542

46-
//TODO : burdasin -- connection string ekle
43+
// use real database
44+
services.AddDbContext<OrderContext>(c =>
45+
c.UseSqlServer(Configuration.GetConnectionString("OrderConnection")));
4746

4847
#endregion
4948

5049
#region Project Dependencies
5150

5251
// Add Infrastructure Layer
5352
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
53+
services.AddScoped(typeof(IOrderRepository), typeof(OrderRepository));
5454
services.AddScoped<IOrderRepository, OrderRepository>();
5555

56-
// Add MediatR
57-
services.AddMediatR(this.GetType().Assembly);
58-
5956
// Add AutoMapper
6057
services.AddAutoMapper(typeof(Startup));
6158

59+
// Add MediatR
60+
services.AddMediatR(typeof(CheckoutOrderHandler).GetTypeInfo().Assembly);
61+
6262
#endregion
6363

6464
#region RabbitMQ Dependencies
@@ -114,8 +114,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
114114
endpoints.MapControllers();
115115
});
116116

117-
//Initilize Rabbit Listener in ApplicationBuilderExtentions
118-
app.UseRabbitListener();
117+
////Initilize Rabbit Listener in ApplicationBuilderExtentions
118+
//app.UseRabbitListener();
119119

120120
app.UseSwagger();
121121
app.UseSwaggerUI(c =>

src/Ordering/Ordering.API/appsettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"ConnectionStrings": {
3+
"OrderConnection": "Server=(localdb)\\mssqllocaldb;Integrated Security=true;Initial Catalog=OrderDb;"
4+
},
25
"Logging": {
36
"LogLevel": {
47
"Default": "Information",

src/Ordering/Ordering.Application/Interfaces/IOrderService.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Ordering/Ordering.Application/Models/Base/BaseModel.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Ordering/Ordering.Application/Models/OrderModel.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Ordering/Ordering.Application/Services/OrderService.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/Ordering/Ordering.Infrastructure/Data/OrderContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Ordering.Infrastructure.Data
55
{
66
public class OrderContext : DbContext
77
{
8-
public OrderContext(DbContextOptions options) : base(options)
8+
public OrderContext(DbContextOptions<OrderContext> options) : base(options)
99
{
1010
}
1111

src/Ordering/Ordering.Infrastructure/Migrations/20200414154554_Initial.Designer.cs

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
namespace Ordering.Infrastructure.Migrations
4+
{
5+
public partial class Initial : Migration
6+
{
7+
protected override void Up(MigrationBuilder migrationBuilder)
8+
{
9+
migrationBuilder.CreateTable(
10+
name: "Orders",
11+
columns: table => new
12+
{
13+
Id = table.Column<int>(nullable: false)
14+
.Annotation("SqlServer:Identity", "1, 1"),
15+
UserName = table.Column<string>(nullable: true),
16+
TotalPrice = table.Column<decimal>(nullable: false),
17+
FirstName = table.Column<string>(nullable: true),
18+
LastName = table.Column<string>(nullable: true),
19+
EmailAddress = table.Column<string>(nullable: true),
20+
AddressLine = table.Column<string>(nullable: true),
21+
Country = table.Column<string>(nullable: true),
22+
State = table.Column<string>(nullable: true),
23+
ZipCode = table.Column<string>(nullable: true),
24+
CardName = table.Column<string>(nullable: true),
25+
CardNumber = table.Column<string>(nullable: true),
26+
Expiration = table.Column<string>(nullable: true),
27+
CVV = table.Column<string>(nullable: true),
28+
PaymentMethod = table.Column<int>(nullable: false)
29+
},
30+
constraints: table =>
31+
{
32+
table.PrimaryKey("PK_Orders", x => x.Id);
33+
});
34+
}
35+
36+
protected override void Down(MigrationBuilder migrationBuilder)
37+
{
38+
migrationBuilder.DropTable(
39+
name: "Orders");
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)