-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add partial class for PermissionSet
- Loading branch information
Showing
33 changed files
with
806 additions
and
799 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
92 changes: 46 additions & 46 deletions
92
src/Application/Features/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,70 +1,70 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using CleanArchitecture.Blazor.Application.Features.Customers.Caching; | ||
using CleanArchitecture.Blazor.Application.Features.Customers.DTOs; | ||
|
||
using CleanArchitecture.Blazor.Application.Features.Customers.Caching; | ||
namespace CleanArchitecture.Blazor.Application.Features.Customers.Commands.AddEdit; | ||
|
||
public class AddEditCustomerCommand : ICacheInvalidatorRequest<Result<int>> | ||
public class AddEditCustomerCommand: ICacheInvalidatorRequest<Result<int>> | ||
{ | ||
[Description("Id")] public int Id { get; set; } | ||
[Description("Id")] | ||
public int Id { get; set; } | ||
[Description("Name")] | ||
public string Name {get;set;} = String.Empty; | ||
[Description("Description")] | ||
public string? Description {get;set;} | ||
|
||
[Description("Name")] public string Name { get; set; } = string.Empty; | ||
|
||
[Description("Description")] public string? Description { get; set; } | ||
|
||
|
||
public string CacheKey => CustomerCacheKey.GetAllCacheKey; | ||
public CancellationTokenSource? SharedExpiryTokenSource => CustomerCacheKey.SharedExpiryTokenSource(); | ||
public string CacheKey => CustomerCacheKey.GetAllCacheKey; | ||
public CancellationTokenSource? SharedExpiryTokenSource => CustomerCacheKey.SharedExpiryTokenSource(); | ||
|
||
private class Mapping : Profile | ||
{ | ||
public Mapping() | ||
{ | ||
CreateMap<CustomerDto, AddEditCustomerCommand>(MemberList.None); | ||
CreateMap<AddEditCustomerCommand, Customer>(MemberList.None); | ||
CreateMap<CustomerDto,AddEditCustomerCommand>(MemberList.None); | ||
CreateMap<AddEditCustomerCommand,Customer>(MemberList.None); | ||
|
||
} | ||
} | ||
} | ||
|
||
public class AddEditCustomerCommandHandler : IRequestHandler<AddEditCustomerCommand, Result<int>> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
private readonly IStringLocalizer<AddEditCustomerCommandHandler> _localizer; | ||
private readonly IMapper _mapper; | ||
|
||
public AddEditCustomerCommandHandler( | ||
IApplicationDbContext context, | ||
IStringLocalizer<AddEditCustomerCommandHandler> localizer, | ||
IMapper mapper | ||
) | ||
public class AddEditCustomerCommandHandler : IRequestHandler<AddEditCustomerCommand, Result<int>> | ||
{ | ||
_context = context; | ||
_localizer = localizer; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<Result<int>> Handle(AddEditCustomerCommand request, CancellationToken cancellationToken) | ||
{ | ||
if (request.Id > 0) | ||
private readonly IApplicationDbContext _context; | ||
private readonly IMapper _mapper; | ||
private readonly IStringLocalizer<AddEditCustomerCommandHandler> _localizer; | ||
public AddEditCustomerCommandHandler( | ||
IApplicationDbContext context, | ||
IStringLocalizer<AddEditCustomerCommandHandler> localizer, | ||
IMapper mapper | ||
) | ||
{ | ||
var item = await _context.Customers.FindAsync(new object[] { request.Id }, cancellationToken) ?? | ||
throw new NotFoundException($"Customer with id: [{request.Id}] not found."); | ||
item = _mapper.Map(request, item); | ||
// raise a update domain event | ||
item.AddDomainEvent(new CustomerUpdatedEvent(item)); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return await Result<int>.SuccessAsync(item.Id); | ||
_context = context; | ||
_localizer = localizer; | ||
_mapper = mapper; | ||
} | ||
else | ||
public async Task<Result<int>> Handle(AddEditCustomerCommand request, CancellationToken cancellationToken) | ||
{ | ||
var item = _mapper.Map<Customer>(request); | ||
// raise a create domain event | ||
item.AddDomainEvent(new CustomerCreatedEvent(item)); | ||
_context.Customers.Add(item); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return await Result<int>.SuccessAsync(item.Id); | ||
if (request.Id > 0) | ||
{ | ||
var item = await _context.Customers.FindAsync(new object[] { request.Id }, cancellationToken) ?? throw new NotFoundException($"Customer with id: [{request.Id}] not found."); | ||
item = _mapper.Map(request, item); | ||
// raise a update domain event | ||
item.AddDomainEvent(new CustomerUpdatedEvent(item)); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return await Result<int>.SuccessAsync(item.Id); | ||
} | ||
else | ||
{ | ||
var item = _mapper.Map<Customer>(request); | ||
// raise a create domain event | ||
item.AddDomainEvent(new CustomerCreatedEvent(item)); | ||
_context.Customers.Add(item); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return await Result<int>.SuccessAsync(item.Id); | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
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: 38 additions & 39 deletions
77
src/Application/Features/Customers/Commands/Create/CreateCustomerCommand.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,56 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using CleanArchitecture.Blazor.Application.Features.Customers.Caching; | ||
using System.ComponentModel; | ||
using CleanArchitecture.Blazor.Application.Features.Customers.DTOs; | ||
using CleanArchitecture.Blazor.Application.Features.Customers.Caching; | ||
|
||
namespace CleanArchitecture.Blazor.Application.Features.Customers.Commands.Create; | ||
|
||
public class CreateCustomerCommand : ICacheInvalidatorRequest<Result<int>> | ||
public class CreateCustomerCommand: ICacheInvalidatorRequest<Result<int>> | ||
{ | ||
[Description("Id")] public int Id { get; set; } | ||
|
||
[Description("Name")] public string Name { get; set; } = string.Empty; | ||
|
||
[Description("Description")] public string? Description { get; set; } | ||
|
||
public string CacheKey => CustomerCacheKey.GetAllCacheKey; | ||
public CancellationTokenSource? SharedExpiryTokenSource => CustomerCacheKey.SharedExpiryTokenSource(); | ||
|
||
[Description("Id")] | ||
public int Id { get; set; } | ||
[Description("Name")] | ||
public string Name {get;set;} = String.Empty; | ||
[Description("Description")] | ||
public string? Description {get;set;} | ||
|
||
public string CacheKey => CustomerCacheKey.GetAllCacheKey; | ||
public CancellationTokenSource? SharedExpiryTokenSource => CustomerCacheKey.SharedExpiryTokenSource(); | ||
private class Mapping : Profile | ||
{ | ||
public Mapping() | ||
{ | ||
CreateMap<CustomerDto, CreateCustomerCommand>(MemberList.None); | ||
CreateMap<CreateCustomerCommand, Customer>(MemberList.None); | ||
CreateMap<CustomerDto,CreateCustomerCommand>(MemberList.None); | ||
CreateMap<CreateCustomerCommand,Customer>(MemberList.None); | ||
} | ||
} | ||
} | ||
|
||
public class CreateCustomerCommandHandler : IRequestHandler<CreateCustomerCommand, Result<int>> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
private readonly IStringLocalizer<CreateCustomerCommand> _localizer; | ||
private readonly IMapper _mapper; | ||
|
||
public CreateCustomerCommandHandler( | ||
IApplicationDbContext context, | ||
IStringLocalizer<CreateCustomerCommand> localizer, | ||
IMapper mapper | ||
) | ||
|
||
public class CreateCustomerCommandHandler : IRequestHandler<CreateCustomerCommand, Result<int>> | ||
{ | ||
_context = context; | ||
_localizer = localizer; | ||
_mapper = mapper; | ||
private readonly IApplicationDbContext _context; | ||
private readonly IMapper _mapper; | ||
private readonly IStringLocalizer<CreateCustomerCommand> _localizer; | ||
public CreateCustomerCommandHandler( | ||
IApplicationDbContext context, | ||
IStringLocalizer<CreateCustomerCommand> localizer, | ||
IMapper mapper | ||
) | ||
{ | ||
_context = context; | ||
_localizer = localizer; | ||
_mapper = mapper; | ||
} | ||
public async Task<Result<int>> Handle(CreateCustomerCommand request, CancellationToken cancellationToken) | ||
{ | ||
var item = _mapper.Map<Customer>(request); | ||
// raise a create domain event | ||
item.AddDomainEvent(new CustomerCreatedEvent(item)); | ||
_context.Customers.Add(item); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return await Result<int>.SuccessAsync(item.Id); | ||
} | ||
} | ||
|
||
public async Task<Result<int>> Handle(CreateCustomerCommand request, CancellationToken cancellationToken) | ||
{ | ||
var item = _mapper.Map<Customer>(request); | ||
// raise a create domain event | ||
item.AddDomainEvent(new CustomerCreatedEvent(item)); | ||
_context.Customers.Add(item); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return await Result<int>.SuccessAsync(item.Id); | ||
} | ||
} |
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
Oops, something went wrong.