This file contains hidden or 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
| [HttpGet] | |
| [Route("get-all")] | |
| public async Task<List<AllCustomerQueryResponseModel>> GetAllCustomerAsync(AllCustomerQueryRequestModel requestModel) | |
| { | |
| try | |
| { | |
| return await mediator.Send(requestModel); | |
| } | |
| catch | |
| { |
This file contains hidden or 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
| public class AllCustomerQueryHandler : IRequestHandler<AllCustomerQueryRequestModel, List<AllCustomerQueryResponseModel>> | |
| { | |
| private readonly CustomerDbContext context; | |
| public AllCustomerQueryHandler(CustomerDbContext context) | |
| { | |
| this.context = context; | |
| } | |
| public async Task<List<AllCustomerQueryResponseModel>> Handle(AllCustomerQueryRequestModel request, |
This file contains hidden or 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
| public class AllCustomerQueryResponseModel | |
| { | |
| public int CustomerId { get; set; } | |
| public string Name { get; set; } | |
| public string City { get; set; } | |
| public int LoyaltyPoints { get; set; } | |
| } |
This file contains hidden or 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
| [Route("api/[controller]")] | |
| [ApiController] | |
| public class CustomerController : ControllerBase | |
| { | |
| private readonly IMediator mediator; | |
| public CustomerController(IMediator mediator) | |
| { | |
| this.mediator = mediator; | |
| } |
This file contains hidden or 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
| public class SaveCustomerCommandHandler : IRequestHandler<SaveCustomerRequestModel, Unit> | |
| { | |
| private readonly CustomerDbContext context; | |
| public SaveCustomerCommandHandler(CustomerDbContext context) | |
| { | |
| this.context = context; | |
| } | |
| public async Task<Unit> Handle(SaveCustomerRequestModel saveCustomerRequestModel, | |
| CancellationToken cancellationToken) |
This file contains hidden or 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
| namespace CQRSwithMediatR.RequestModels.CommandRequests | |
| { | |
| public class SaveCustomerRequestModel : IRequest | |
| { | |
| public string Title { get; set; } | |
| public string Name { get; set; } | |
| public string City { get; set; } | |
| public int LoyaltyPoints { get; set; } | |
| } | |
| } |
This file contains hidden or 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
| [HttpGet] | |
| [Route("customer-id")] | |
| [ProducesResponseType(typeof(CustomerIdQueryResponseModel),StatusCodes.Status200OK)] | |
| public async Task<IActionResult> GetCustomerAsync([FromQuery] CustomerIdQueryRequestModel model) | |
| { | |
| try | |
| { | |
| var result = await this.customerIdQueryHandler.GetCustomerAsync(model); | |
| if (result != null) |
This file contains hidden or 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
| namespace CustomerManagement.Handlers.QueryHandler | |
| { | |
| public class CustomerIdQueryHandler : ICustomerIdQueryHandler | |
| { | |
| private readonly CustomerDbContext context; | |
| public CustomerIdQueryHandler(CustomerDbContext context) | |
| { | |
| this.context = context; | |
| } | |
| public async Task<CustomerIdQueryResponseModel> GetCustomerAsync(CustomerIdQueryRequestModel requestModel) |
This file contains hidden or 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
| namespace CustomerManagement.Contracts.QueryHandlers | |
| { | |
| public interface ICustomerIdQueryHandler | |
| { | |
| Task<CustomerIdQueryResponseModel> GetCustomerAsync(CustomerIdQueryRequestModel requestModel); | |
| } | |
| } |
This file contains hidden or 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
| namespace CustomerManagement.RequestModels.QueryRequests | |
| { | |
| public class CustomerIdQueryRequestModel | |
| { | |
| public int CustomerId { get; set; } | |
| } | |
| } |
NewerOlder