Skip to content

Commit 5af4b8f

Browse files
committed
refactored CQRS
1 parent f783b04 commit 5af4b8f

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

OnionArchitecture/OA.Service/Features/CustomerFeatures/Commands/CreateCustomerCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66

7-
namespace Application.Features.ProductFeatures.Commands
7+
namespace OA.Service.Features.CustomerFeatures.Commands
88
{
99
public class CreateCustomerCommand : IRequest<int>
1010
{
@@ -18,10 +18,10 @@ public class CreateCustomerCommand : IRequest<int>
1818
public string Country { get; set; }
1919
public string Phone { get; set; }
2020
public string Fax { get; set; }
21-
public class CreateProductCommandHandler : IRequestHandler<CreateCustomerCommand, int>
21+
public class CreateCustomerCommandHandler : IRequestHandler<CreateCustomerCommand, int>
2222
{
2323
private readonly IApplicationDbContext _context;
24-
public CreateProductCommandHandler(IApplicationDbContext context)
24+
public CreateCustomerCommandHandler(IApplicationDbContext context)
2525
{
2626
_context = context;
2727
}

OnionArchitecture/OA.Service/Features/CustomerFeatures/Commands/DeleteCustomerByIdCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77

8-
namespace Application.Features.ProductFeatures.Commands
8+
namespace OA.Service.Features.CustomerFeatures.Commands
99
{
1010
public class DeleteCustomerByIdCommand : IRequest<int>
1111
{
1212
public int Id { get; set; }
13-
public class DeleteProductByIdCommandHandler : IRequestHandler<DeleteCustomerByIdCommand, int>
13+
public class DeleteCustomerByIdCommandHandler : IRequestHandler<DeleteCustomerByIdCommand, int>
1414
{
1515
private readonly IApplicationDbContext _context;
16-
public DeleteProductByIdCommandHandler(IApplicationDbContext context)
16+
public DeleteCustomerByIdCommandHandler(IApplicationDbContext context)
1717
{
1818
_context = context;
1919
}

OnionArchitecture/OA.Service/Features/CustomerFeatures/Commands/UpdateCustomerCommand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77

8-
namespace Application.Features.ProductFeatures.Commands
8+
namespace OA.Service.Features.CustomerFeatures.Commands
99
{
1010
public class UpdateCustomerCommand : IRequest<int>
1111
{
@@ -20,18 +20,18 @@ public class UpdateCustomerCommand : IRequest<int>
2020
public string Country { get; set; }
2121
public string Phone { get; set; }
2222
public string Fax { get; set; }
23-
public class UpdateProductCommandHandler : IRequestHandler<UpdateCustomerCommand, int>
23+
public class UpdateCustomerCommandHandler : IRequestHandler<UpdateCustomerCommand, int>
2424
{
2525
private readonly IApplicationDbContext _context;
26-
public UpdateProductCommandHandler(IApplicationDbContext context)
26+
public UpdateCustomerCommandHandler(IApplicationDbContext context)
2727
{
2828
_context = context;
2929
}
3030
public async Task<int> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
3131
{
32-
var product = _context.Products.Where(a => a.Id == request.Id).FirstOrDefault();
32+
var cust = _context.Customers.Where(a => a.Id == request.Id).FirstOrDefault();
3333

34-
if (product == null)
34+
if (cust == null)
3535
{
3636
return default;
3737
}
@@ -41,7 +41,7 @@ public async Task<int> Handle(UpdateCustomerCommand request, CancellationToken c
4141
customer.CustomerName = request.CustomerName;
4242
customer.ContactName = request.ContactName;
4343
await _context.SaveChangesAsync();
44-
return product.Id;
44+
return cust.Id;
4545
}
4646
}
4747
}

OnionArchitecture/OA.Service/Features/CustomerFeatures/Queries/GetAllCustomerQuery.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88

9-
namespace Application.Features.ProductFeatures.Queries
9+
namespace OA.Service.Features.CustomerFeatures.Queries
1010
{
1111
public class GetAllCustomerQuery : IRequest<IEnumerable<Customer>>
1212
{
1313

14-
public class GetAllProductsQueryHandler : IRequestHandler<GetAllCustomerQuery, IEnumerable<Customer>>
14+
public class GetAllCustomerQueryHandler : IRequestHandler<GetAllCustomerQuery, IEnumerable<Customer>>
1515
{
1616
private readonly IApplicationDbContext _context;
17-
public GetAllProductsQueryHandler(IApplicationDbContext context)
17+
public GetAllCustomerQueryHandler(IApplicationDbContext context)
1818
{
1919
_context = context;
2020
}

OnionArchitecture/OA.Service/Features/CustomerFeatures/Queries/GetCustomerByIdQuery.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77

8-
namespace Application.Features.ProductFeatures.Queries
8+
namespace OA.Service.Features.CustomerFeatures.Queries
99
{
1010
public class GetCustomerByIdQuery : IRequest<Customer>
1111
{
1212
public int Id { get; set; }
13-
public class GetProductByIdQueryHandler : IRequestHandler<GetCustomerByIdQuery, Customer>
13+
public class GetCustomerByIdQueryHandler : IRequestHandler<GetCustomerByIdQuery, Customer>
1414
{
1515
private readonly IApplicationDbContext _context;
16-
public GetProductByIdQueryHandler(IApplicationDbContext context)
16+
public GetCustomerByIdQueryHandler(IApplicationDbContext context)
1717
{
1818
_context = context;
1919
}

OnionArchitecture/OA/Controllers/CustomerController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Application.Features.ProductFeatures.Commands;
2-
using Application.Features.ProductFeatures.Queries;
1+
using OA.Service.Features.CustomerFeatures.Commands;
2+
using OA.Service.Features.CustomerFeatures.Queries;
33
using MediatR;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.Extensions.DependencyInjection;

0 commit comments

Comments
 (0)