Skip to content

Instantly share code, notes, and snippets.

View ducmeit1's full-sized avatar
:octocat:
Simple is best! Always do every simple!

David Ho ducmeit1

:octocat:
Simple is best! Always do every simple!
View GitHub Profile
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
using System;
using Newtonsoft.Json;
namespace Customer.Domain.Dtos
{
public class CustomerDto
{
[JsonProperty("id")]
public Guid Id { get; set; }
[JsonProperty("name")]
using System.ComponentModel.DataAnnotations;
using Customer.Domain.Dtos;
using Newtonsoft.Json;
namespace Customer.Domain.Commands
{
public class CreateCustomerCommand : CommandBase<CustomerDto>
{
public CreateCustomerCommand()
{
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) {
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));
}
public class GetUserDetailQuery : IRequest<UserDto>
{
public GetUserDetailQuery(int id) {
Id = id;
}
public int Id {get;}
}
[AllowAnonymous]
[HttpPost]
public async Task<IHttpActionResult> Register ([FromBody] CreateUserCommand command) {
return Ok (await new CommandAsync (command));
}
@ducmeit1
ducmeit1 / Controller.cs
Created July 15, 2019 07:57
ThinController
[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,
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyAllConfigurations<MyDbContext>();
}
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