Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

Bloco de código
languagec#
firstline1
titleCountry.cs
linenumberstrue
[AutoMap(typeof(CountryDto))]
[Table("Countries")]
public class Country : Entity
{
	public const int MaxNameLength = 256;
    [Required]
    [MaxLength(MaxNameLength)]
    public string Name { get; set; }
    public Country()
    {
    }
    public Country(int id, string name)
    {
    	Id = id;
        Name = name;
    }
}
 
public class CountryDto : IDto
{
    public IList<string> _expandables { get; set; }
	public string Name { get; set; }
}

...

Bloco de código
languagec#
firstline1
titlePresidentEntity.cs
linenumberstrue
[JsonObject("president")]
public class PresidentEntity : CarolEntity
{
	public string Name { get; set; }
    public string ZipCode { get; set; }
    public override object GetStagingMapping()
    {
    	return new
        {
        	name = "string",
            zipCode = "string"
        };
	}
}
 
public class PresidentDto : IDto
{
    public IList<string> _expandables { get; set; }
	public PresidentDto()
    {
    }
    public PresidentDto(string id, string name, string zipCode)
    {
    	Id = id;
        Name = name;
        ZipCode = new ZipCode(zipCode);
	}
    public string Id { get; set; }
    public string Name { get; set; }
    public ZipCode ZipCode { get; set; }
}

...

Bloco de código
languagec#
firstline1
titleWhiteHouseService.cs
linenumberstrue
// Domain service interface
public interface IWhiteHouseService : IDomainService
{
    Task<DtoResponseBase<PresidentDto>>Task<PresidentDto> InsertPresidentAsync(PresidentDto request);
}
 
// Domain service
public class WhiteHouseService : DomainService<IWhiteHouseRepository>AppDomainService<IWhiteHouseRepository>, IWhiteHouseService
{
    private readonly IEventBus _eventBus;
 
    public WhiteHouseService(IWhiteHouseRepository repository, IEventBus eventBus)
        : base(repository)
    {
        _eventBus = eventBus;
    }
 
    public Task<DtoResponseBase<PresidentDto>>Task<PresidentDto> InsertPresidentAsync(PresidentDto request)
    {
        var response = new DtoResponseBase<PresidentDto>();
        var builder = new PresidentBuilder()
            .WithId(item.Id)
            .WithName(item.Name);
    
        
		var buildpresident = builder.Build();

        if (!buildNotification.SuccessHasNotification())
        {
            response.AddNotifications(build.Notifications);
            return responsevar ids = await Repository.InsertPresidentsAsync(new List<President>() { president }, sync);
        }
 
        var presidentCreateddto.Id = await Repository.InsertPresidentAsync(request)ids[0];


        response.Data = presidentCreated;
 
 // Trigger president created event
   // Trigger event
        _eventBus.Trigger(new PresidentCreatedEvent(presidentCreatedpresident));
        }

        return response;
    }
}

Além da validação da entidade nosso caso de testes faz uso de Domain Events e dispara um evento após inserir a entidade de presidente.

Bloco de código
languagec#
firstline1
titlePresidentBuilder.cs
linenumberstrue
internal class PresidentBuilder : Builder<President>
{
    public PresidentBuilder(INotificationHandler notification)
        : base(notification)
    {
    }
    
    public PresidentBuilder(President instance, INotificationHandler notification)
        : base(instance, notification)
    {
    }

    public PresidentBuilder WithId(string id)
    {
        Instance.Id = id;
        return this;
    }
    public PresidentBuilder WithName(string name)
    {
        Instance.Name = name;
        return this;
    }
        public
	protected override BuilderResponse<President>void BuildSpecifications()
    {
        // Entity specifications
        var shouldHaveName = AddSpecification(new PresidentShouldHaveNameSpecification());
 
        if (!shouldHaveName.IsSatisfiedBy(Instance))}
        {
	public override           var notificationMessage = LocalizationHelper.GetString(President Build()
                AppConsts.LocalizationSourceName,{
                President.Error.PresidentNameMustHaveValue);
            Response.AddNotification(President.Error.PresidentNameMustHaveValue, notificationMessage	base.Validate();
        }
 
        return base.Build();
    }
}

Camada de aplicação

...

Bloco de código
languagec#
firstline1
titleIWhiteHouseAppService.cs
linenumberstrue
public interface IWhiteHouseAppService : IApplicationService
{
	Task<PagingDtoResponse<PresidentDto>>Task<ListDto<PresidentDto>> GetAllPresidents(GellAllPresidentsRequestDtoGetAllPresidentsDto request);
    Task<PresidentDto> GetPresidentById(stringRequestDto<string> id);
    Task<DtoResponseBase<List<PresidentDto>>>Task<PresidentDto> InsertPresidentAsync(List<PresidentDto>PresidentDto dtospresident, bool sync = true);
    Task<DtoResponseBase>Task<PresidentDto> UpdatePresidentAsync(string id, PresidentDto dtopresident);
    Task<DtoResponseBase>Task DeletePresidentAsync(string id);
}

...