-
Notifications
You must be signed in to change notification settings - Fork 0
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
cfbb963
commit b2c51f6
Showing
158 changed files
with
79,688 additions
and
0 deletions.
There are no files selected for viewing
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,43 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.1.32228.430 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleShop.Web", "src\SimpleShop.Web\SimpleShop.Web.csproj", "{75B755DF-E0D4-46DB-A774-C00E51729C0A}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleShop.Infrastructure", "src\SimpleShop.Infrastructure\SimpleShop.Infrastructure.csproj", "{FA471625-6F0A-45C6-B5D5-00DF22E72F5A}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleShop.Domain", "src\SimpleShop.Domain\SimpleShop.Domain.csproj", "{EB6581E2-FCC5-43B9-A724-F68EC5DB0D6A}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleShop.Application", "src\SimpleShop.Application\SimpleShop.Application.csproj", "{6456067B-79E8-4FBF-865D-1FC68DC1D8FF}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{75B755DF-E0D4-46DB-A774-C00E51729C0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{75B755DF-E0D4-46DB-A774-C00E51729C0A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{75B755DF-E0D4-46DB-A774-C00E51729C0A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{75B755DF-E0D4-46DB-A774-C00E51729C0A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{FA471625-6F0A-45C6-B5D5-00DF22E72F5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FA471625-6F0A-45C6-B5D5-00DF22E72F5A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FA471625-6F0A-45C6-B5D5-00DF22E72F5A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FA471625-6F0A-45C6-B5D5-00DF22E72F5A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{EB6581E2-FCC5-43B9-A724-F68EC5DB0D6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EB6581E2-FCC5-43B9-A724-F68EC5DB0D6A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EB6581E2-FCC5-43B9-A724-F68EC5DB0D6A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EB6581E2-FCC5-43B9-A724-F68EC5DB0D6A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{6456067B-79E8-4FBF-865D-1FC68DC1D8FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6456067B-79E8-4FBF-865D-1FC68DC1D8FF}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6456067B-79E8-4FBF-865D-1FC68DC1D8FF}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6456067B-79E8-4FBF-865D-1FC68DC1D8FF}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {91035B60-F07D-4B6F-A504-8EBF235F6EF3} | ||
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,44 @@ | ||
using Ardalis.GuardClauses; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using SimpleShop.Infrastructure.Database; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SimpleShop.Application.Commands.Carts | ||
{ | ||
public static class ClearCart | ||
{ | ||
public record Command(string cartId) : IRequest<Unit>; | ||
|
||
public class Handler : IRequestHandler<Command, Unit> | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public Handler(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
var cart = await _context.Carts | ||
.Include(c => c.Items) | ||
.SingleOrDefaultAsync(c => c.Id.Equals(request.cartId)); | ||
|
||
Guard.Against.Null(cart, nameof(cart)); | ||
|
||
if(!cart.IsEmpty) | ||
{ | ||
_context.RemoveRange(cart.Items); | ||
await _context.SaveChangesAsync(); | ||
} | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} | ||
} |
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,47 @@ | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using SimpleShop.Domain.Entities; | ||
using SimpleShop.Infrastructure.Database; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SimpleShop.Application.Commands.Carts | ||
{ | ||
public static class CreateCart | ||
{ | ||
public record Command(string userId) : IRequest<Unit>; | ||
|
||
public class Handler : IRequestHandler<Command, Unit> | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public Handler(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
var cart = await _context.Carts | ||
.SingleOrDefaultAsync(c => c.UserId.Equals(request.userId)); | ||
|
||
if (cart is null) | ||
{ | ||
cart = new Cart | ||
{ | ||
Id = Guid.NewGuid().ToString(), | ||
UserId = request.userId | ||
}; | ||
|
||
_context.Carts.Add(cart); | ||
await _context.SaveChangesAsync(); | ||
} | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/SimpleShop.Application/Commands/CartItem/AddCartItem.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,32 @@ | ||
using Ardalis.GuardClauses; | ||
using MediatR; | ||
using SimpleShop.Domain.Entities; | ||
using SimpleShop.Infrastructure.Database; | ||
|
||
namespace SimpleShop.Application.Commands.CartItems | ||
{ | ||
public static class AddCartItem | ||
{ | ||
public record Command(CartItem item) : IRequest<Unit>; | ||
|
||
public class Handler : IRequestHandler<Command, Unit> | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public Handler(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
Guard.Against.Null(request.item, nameof(request.item)); | ||
|
||
_context.CartItems.Add(request.item); | ||
await _context.SaveChangesAsync(); | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/SimpleShop.Application/Commands/CartItem/DeleteCartItem.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,35 @@ | ||
using Ardalis.GuardClauses; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using SimpleShop.Infrastructure.Database; | ||
|
||
namespace SimpleShop.Application.Commands.CartItems | ||
{ | ||
public static class DeleteCartItem | ||
{ | ||
public record Command(string itemId) : IRequest<Unit>; | ||
|
||
public class Handler : IRequestHandler<Command, Unit> | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public Handler(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
var item = await _context.CartItems | ||
.SingleOrDefaultAsync(i => i.Id.Equals(request.itemId)); | ||
|
||
Guard.Against.Null(item, nameof(item)); | ||
|
||
_context.CartItems.Remove(item); | ||
await _context.SaveChangesAsync(); | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/SimpleShop.Application/Commands/CartItem/UpdateCartItem.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,44 @@ | ||
using Ardalis.GuardClauses; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using SimpleShop.Domain.Entities; | ||
using SimpleShop.Infrastructure.Database; | ||
|
||
namespace SimpleShop.Application.Commands.CartItems | ||
{ | ||
public static class UpdateCartItem | ||
{ | ||
public record Command(string itemId, int quantity) : IRequest<Unit>; | ||
|
||
public class Handler : IRequestHandler<Command, Unit> | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public Handler(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
var item = await _context.CartItems | ||
.SingleOrDefaultAsync(i => i.Id.Equals(request.itemId)); | ||
|
||
Guard.Against.Null(item, nameof(item)); | ||
|
||
if(item.Quantity + request.quantity <= 0) | ||
{ | ||
_context.Remove(item); | ||
} | ||
else | ||
{ | ||
item.Quantity += request.quantity; | ||
_context.CartItems.Update(item); | ||
} | ||
await _context.SaveChangesAsync(); | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/SimpleShop.Application/Commands/Order/AddOrderDetails.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,32 @@ | ||
using Ardalis.GuardClauses; | ||
using MediatR; | ||
using SimpleShop.Domain.Entities; | ||
using SimpleShop.Infrastructure.Database; | ||
|
||
namespace SimpleShop.Application.Commands.Orders | ||
{ | ||
public static class AddOrderDetails | ||
{ | ||
public record Command(OrderDetails orderDetails) : IRequest<Unit>; | ||
|
||
public class Handler : IRequestHandler<Command, Unit> | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public Handler(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
Guard.Against.Null(request.orderDetails, nameof(request.orderDetails)); | ||
|
||
_context.OrderDetails.Add(request.orderDetails); | ||
await _context.SaveChangesAsync(); | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/SimpleShop.Application/Commands/Order/AddOrderItems.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,32 @@ | ||
using Ardalis.GuardClauses; | ||
using MediatR; | ||
using SimpleShop.Domain.Entities; | ||
using SimpleShop.Infrastructure.Database; | ||
|
||
namespace SimpleShop.Application.Commands.Orders | ||
{ | ||
public static class AddOrderItems | ||
{ | ||
public record Command(List<OrderItem> orderItems) : IRequest<Unit>; | ||
|
||
public class Handler : IRequestHandler<Command, Unit> | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public Handler(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
Guard.Against.NullOrEmpty(request.orderItems, nameof(request.orderItems)); | ||
|
||
await _context.OrderItems.AddRangeAsync(request.orderItems); | ||
await _context.SaveChangesAsync(); | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
using Ardalis.GuardClauses; | ||
using MediatR; | ||
using SimpleShop.Domain.Entities; | ||
using SimpleShop.Infrastructure.Database; | ||
|
||
namespace SimpleShop.Application.Commands.Orders | ||
{ | ||
public static class CreateOrder | ||
{ | ||
public record Command(Order order) : IRequest<bool>; | ||
|
||
public class Handler : IRequestHandler<Command, bool> | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public Handler(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<bool> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
Guard.Against.Null(request.order, nameof(request.order)); | ||
|
||
_context.Orders.Add(request.order); | ||
var success = await _context.SaveChangesAsync(); | ||
|
||
return success > 0; | ||
} | ||
} | ||
} | ||
} |
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,33 @@ | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using SimpleShop.Domain.Entities; | ||
using SimpleShop.Infrastructure.Database; | ||
|
||
namespace SimpleShop.Application.Queries.Carts | ||
{ | ||
public static class GetCart | ||
{ | ||
public record Query(string userId) : IRequest<Cart>; | ||
|
||
public class Handler : IRequestHandler<Query, Cart> | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public Handler(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Cart> Handle(Query request, CancellationToken cancellationToken) | ||
{ | ||
var cart = await _context.Carts | ||
.AsNoTracking() | ||
.Include(c => c.Items) | ||
.ThenInclude(p => p.Product) | ||
.SingleOrDefaultAsync(c => c.UserId.Equals(request.userId)); | ||
|
||
return cart; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.