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 PostResponse | |
| { | |
| public Guid Id { get; set; } | |
| public string Name { get; set; } | |
| public string UserId { get; set; } | |
| public IEnumerable<TagResponse> Tags { 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
| public class TagResponse | |
| { | |
| public string Name { 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
| var response = new XResponse { | |
| Name = XDomain.Name; | |
| Id = XDomain.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 DomainToResponseProfile() | |
| { | |
| CreateMap<Post, PostResponse>() | |
| .ForMember(dest => dest.Tags, opt => | |
| opt.MapFrom(src => src.Tags.Select(x => new TagResponse{Name = x.TagName}))); | |
| CreateMap<Tag, TagResponse>(); | |
| } |
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
| if(string.IsNullOrEmpty(request.TagName) | |
| { | |
| return BadRequest(new {error = "Tag name should not be empty"}); | |
| } |
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 CreateTagRequestValidator() | |
| { | |
| RuleFor(x => x.TagName) | |
| .NotEmpty() | |
| .Matches("^[a-zA-Z0-9 ]*$"); // alphanumerics and space | |
| } |
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 ErrorModel | |
| { | |
| public string FieldName { get; set; } // actual name of the field | |
| public string Message { get; set; } // user friendly error message | |
| } |
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 async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) | |
| { | |
| if (!context.ModelState.IsValid) | |
| { | |
| var errorsInModelState = context.ModelState | |
| .Where(x => x.Value.Errors.Count > 0) | |
| .ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Errors.Select(x => x.ErrorMessage)).ToArray(); | |
| var errorResponse = new ErrorResponse(); |
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
| var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; | |
| var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); | |
| x.IncludeXmlComments(xmlPath); |
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
| <PropertyGroup> | |
| <GenerateDocumentationFile>true</GenerateDocumentationFile> | |
| <NoWarn>$(NoWarn);1591</NoWarn> | |
| </PropertyGroup> |