private static string GetTemplate(string controllerName, string commandName, CommandEndpointTypes commandEndpointType) { var code = @" using MediatR; using System.Threading; using System.Threading.Tasks; namespace Demo.Application.%CONTROLLERNAME%.Commands.%COMMANDNAME% { public class %COMMANDNAME%CommandHandler : IRequestHandler<%COMMANDNAME%Command, %RESPONSE%> { public %COMMANDNAME%CommandHandler() { } public async Task<%RESPONSE%> Handle(%COMMANDNAME%Command request, CancellationToken cancellationToken) { await Task.CompletedTask; return %RETURN%; } } } "; var hasResponse = commandEndpointType == CommandEndpointTypes.Create; code = code.Replace("%RESPONSE%", !hasResponse ? "Unit" : $"{commandName}Response"); code = code.Replace("%RETURN%", !hasResponse ? "Unit.Value" : $"new {commandName}Response()"); code = code.Replace("%CONTROLLERNAME%", controllerName); code = code.Replace("%COMMANDNAME%", commandName); return(code); }
private static string GetTemplate(string controllerName, string commandName, CommandEndpointTypes commandEndpointType) { var code = @" using AutoMapper; using Demo.Domain.%ENTITYNAME_GUESS%; namespace Demo.Application.%CONTROLLERNAME%.Commands.%COMMANDNAME% { public class %COMMANDNAME%MappingProfile : Profile { public %COMMANDNAME%MappingProfile() { CreateMap<%COMMANDNAME%Command, %ENTITYNAME_GUESS%>() .ForMember(x => x.Deleted, opt => opt.Ignore()) .ForMember(x => x.DeletedBy, opt => opt.Ignore()) .ForMember(x => x.DeletedOn, opt => opt.Ignore()) .ForMember(x => x.CreatedBy, opt => opt.Ignore()) .ForMember(x => x.CreatedOn, opt => opt.Ignore()) .ForMember(x => x.LastModifiedBy, opt => opt.Ignore()) .ForMember(x => x.LastModifiedOn, opt => opt.Ignore()) .ForMember(x => x.Id, opt => opt.Ignore()) .ForMember(x => x.Timestamp, opt => opt.Ignore()); } } } "; code = code.Replace("%CONTROLLERNAME%", controllerName); code = code.Replace("%COMMANDNAME%", commandName); code = code.Replace("%ENTITYNAME_GUESS%", commandName.Replace("Create", string.Empty).Replace("Update", string.Empty)); return(code); }