-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from neozhu/dev
clean code add global using in application project
- Loading branch information
Showing
95 changed files
with
351 additions
and
613 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
2 changes: 0 additions & 2 deletions
2
src/Application/Common/Behaviours/CacheInvalidationBehaviour.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
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
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
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
1 change: 0 additions & 1 deletion
1
src/Application/Common/Behaviours/UnhandledExceptionBehaviour.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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
77 changes: 34 additions & 43 deletions
77
src/Application/Customers/Commands/AddEdit/AddEditCustomerCommand.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 |
---|---|---|
@@ -1,60 +1,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using AutoMapper; | ||
using CleanArchitecture.Razor.Application.Common.Interfaces; | ||
using CleanArchitecture.Razor.Application.Common.Interfaces.Caching; | ||
using CleanArchitecture.Razor.Application.Common.Mappings; | ||
using CleanArchitecture.Razor.Application.Common.Models; | ||
using CleanArchitecture.Razor.Application.Customers.Caching; | ||
using CleanArchitecture.Razor.Application.Customers.DTOs; | ||
using CleanArchitecture.Razor.Domain.Entities; | ||
using CleanArchitecture.Razor.Domain.Events; | ||
using MediatR; | ||
|
||
namespace CleanArchitecture.Razor.Application.Customers.Commands.AddEdit | ||
namespace CleanArchitecture.Razor.Application.Customers.Commands.AddEdit; | ||
|
||
public class AddEditCustomerCommand : CustomerDto, IRequest<Result<int>>, IMapFrom<Customer>, ICacheInvalidator | ||
{ | ||
public class AddEditCustomerCommand : CustomerDto, IRequest<Result<int>>, IMapFrom<Customer>, ICacheInvalidator | ||
{ | ||
public string CacheKey => CustomerCacheKey.GetAllCacheKey; | ||
public string CacheKey => CustomerCacheKey.GetAllCacheKey; | ||
|
||
public CancellationTokenSource ResetCacheToken => CustomerCacheTokenSource.ResetCacheToken; | ||
} | ||
public CancellationTokenSource ResetCacheToken => CustomerCacheTokenSource.ResetCacheToken; | ||
} | ||
|
||
public class AddEditCustomerCommandHandler : IRequestHandler<AddEditCustomerCommand, Result<int>> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
private readonly IMapper _mapper; | ||
|
||
public class AddEditCustomerCommandHandler : IRequestHandler<AddEditCustomerCommand, Result<int>> | ||
public AddEditCustomerCommandHandler( | ||
IApplicationDbContext context, | ||
IMapper mapper | ||
) | ||
{ | ||
_context = context; | ||
_mapper = mapper; | ||
} | ||
public async Task<Result<int>> Handle(AddEditCustomerCommand request, CancellationToken cancellationToken) | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
private readonly IMapper _mapper; | ||
|
||
public AddEditCustomerCommandHandler( | ||
IApplicationDbContext context, | ||
IMapper mapper | ||
) | ||
if (request.Id > 0) | ||
{ | ||
_context = context; | ||
_mapper = mapper; | ||
var customer = await _context.Customers.FindAsync(new object[] { request.Id }, cancellationToken); | ||
customer = _mapper.Map(request, customer); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return Result<int>.Success(customer.Id); | ||
} | ||
public async Task<Result<int>> Handle(AddEditCustomerCommand request, CancellationToken cancellationToken) | ||
else | ||
{ | ||
|
||
if (request.Id > 0) | ||
{ | ||
var customer = await _context.Customers.FindAsync(new object[] { request.Id }, cancellationToken); | ||
customer=_mapper.Map(request, customer); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return Result<int>.Success(customer.Id); | ||
} | ||
else | ||
{ | ||
var customer = _mapper.Map<Customer>(request); | ||
var createevent = new CustomerCreatedEvent(customer); | ||
customer.DomainEvents.Add(createevent); | ||
_context.Customers.Add(customer); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return Result<int>.Success(customer.Id); | ||
} | ||
|
||
|
||
var customer = _mapper.Map<Customer>(request); | ||
var createevent = new CustomerCreatedEvent(customer); | ||
customer.DomainEvents.Add(createevent); | ||
_context.Customers.Add(customer); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return Result<int>.Success(customer.Id); | ||
} | ||
|
||
|
||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
src/Application/Customers/Commands/AddEdit/AddEditCustomerCommandValidator.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
5 changes: 0 additions & 5 deletions
5
src/Application/Customers/Commands/Delete/DeleteCustomerCommand.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
2 changes: 0 additions & 2 deletions
2
src/Application/Customers/Commands/Delete/DeleteCustomerCommandValidator.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
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
2 changes: 0 additions & 2 deletions
2
src/Application/Customers/Commands/Import/ImportCustomersCommandValidator.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
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
3 changes: 0 additions & 3 deletions
3
src/Application/Customers/EventHandlers/CustomerCreatedEventHandler.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
11 changes: 0 additions & 11 deletions
11
src/Application/Customers/Queries/ByMeQuery/CustomersByMeQueryQuery.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
Oops, something went wrong.