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
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Customer.Data.IRepositories; | |
using Customer.Domain.Commands; | |
using Customer.Domain.Dtos; | |
using Customer.Service.Dxos; | |
using MediatR; | |
namespace Customer.Service.Services |
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
using System; | |
using Newtonsoft.Json; | |
namespace Customer.Domain.Dtos | |
{ | |
public class CustomerDto | |
{ | |
[JsonProperty("id")] | |
public Guid Id { get; set; } | |
[JsonProperty("name")] |
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
using System.ComponentModel.DataAnnotations; | |
using Customer.Domain.Dtos; | |
using Newtonsoft.Json; | |
namespace Customer.Domain.Commands | |
{ | |
public class CreateCustomerCommand : CommandBase<CustomerDto> | |
{ | |
public CreateCustomerCommand() | |
{ |
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 UsersController : ControllerBase | |
{ | |
private readonly IMediator _mediator; | |
public UsersController(IMediator mediator) { | |
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); | |
} | |
[HttpGet("{id}")] | |
public async Task<Order> Get(int id) { |
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 GetUserDetailHandler : IRequestHandler<GetUserDetailQuery, UserDto> | |
{ | |
private readonly IUserRepository _userRepository; | |
private readonly IUserMapper _userMapper; | |
public GetUserDetailHandler(IUserRepository userRepository, IUserMapper userMapper) { | |
_userRepository = userRepository ?? throw new ArgumentNullException(nameof(userRepository)); | |
_userMapper = userMapper ?? throw new ArgumentNullException(nameof(userMapper)); | |
} | |
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 GetUserDetailQuery : IRequest<UserDto> | |
{ | |
public GetUserDetailQuery(int id) { | |
Id = id; | |
} | |
public int Id {get;} | |
} |
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
[AllowAnonymous] | |
[HttpPost] | |
public async Task<IHttpActionResult> Register ([FromBody] CreateUserCommand command) { | |
return Ok (await new CommandAsync (command)); | |
} |
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
[AllowAnonymous] | |
[HttpPost] | |
public async Task<IHttpActionResult> Register (RegisterBindingModel model) { | |
if (!ModelState.IsValid) return BadRequest (ModelState); | |
var user = new User { | |
UserName = model.Email, | |
Email = model.Email, | |
DateOfBirth = DateTime.Parse (model.DateOfBirth.ToString (CultureInfo.InvariantCulture)), | |
PhoneNumber = model.PhoneNumber, |
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
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
modelBuilder.ApplyAllConfigurations<MyDbContext>(); | |
} |
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
using System; | |
using System.Linq; | |
using System.Reflection; | |
using Microsoft.EntityFrameworkCore; | |
namespace Demo { | |
public static class Extensions | |
{ | |
/// <summary> | |
/// Auto find and apply all IEntityTypeConfiguration to modelBuilder |