|  |  | 1 |  | using System.ComponentModel.DataAnnotations; | 
|  |  | 2 |  | using LGDXRobotCloud.Data.Models.Business.Automation; | 
|  |  | 3 |  |  | 
|  |  | 4 |  | namespace LGDXRobotCloud.Data.Models.DTOs.V1.Commands; | 
|  |  | 5 |  |  | 
|  |  | 6 |  | public record TriggerCreateDto | 
|  |  | 7 |  | { | 
|  |  | 8 |  |   [Required (ErrorMessage = "Please enter a name.")] | 
|  |  | 9 |  |   [MaxLength(50)] | 
|  |  | 10 |  |   public required string Name { get; set; } | 
|  |  | 11 |  |  | 
|  |  | 12 |  |   [Required (ErrorMessage = "Please enter an URL.")] | 
|  |  | 13 |  |   [MaxLength(200)] | 
|  |  | 14 |  |   public required string Url { get; set; } | 
|  |  | 15 |  |  | 
|  |  | 16 |  |   public required int HttpMethodId { get; set; } | 
|  |  | 17 |  |  | 
|  |  | 18 |  |   public string? Body { get; set; } | 
|  |  | 19 |  |  | 
|  |  | 20 |  |  | 
|  |  | 21 |  |   public int? ApiKeyInsertLocationId { get; set; } | 
|  |  | 22 |  |  | 
|  |  | 23 |  |   [MaxLength(50)] | 
|  |  | 24 |  |   public string? ApiKeyFieldName { get; set; } | 
|  |  | 25 |  |  | 
|  |  | 26 |  |   public int? ApiKeyId { get; set; } | 
|  |  | 27 |  |  | 
|  |  | 28 |  |   public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | 
|  |  | 29 |  |   { | 
|  |  | 30 |  |     if (!(ApiKeyInsertLocationId != null && ApiKeyFieldName != null && ApiKeyId != null)) | 
|  |  | 31 |  |     { | 
|  |  | 32 |  |       if (ApiKeyInsertLocationId == null) | 
|  |  | 33 |  |       { | 
|  |  | 34 |  |         yield return new ValidationResult("Please select an insert location.", [nameof(ApiKeyInsertLocationId)]); | 
|  |  | 35 |  |       } | 
|  |  | 36 |  |       if (ApiKeyFieldName == null) | 
|  |  | 37 |  |       { | 
|  |  | 38 |  |         yield return new ValidationResult("Please enter a field name.", [nameof(ApiKeyFieldName)]); | 
|  |  | 39 |  |       } | 
|  |  | 40 |  |       if (ApiKeyId == null) | 
|  |  | 41 |  |       { | 
|  |  | 42 |  |         yield return new ValidationResult("Please select an API Key.", [nameof(ApiKeyId)]); | 
|  |  | 43 |  |       } | 
|  |  | 44 |  |     } | 
|  |  | 45 |  |   } | 
|  |  | 46 |  | } | 
|  |  | 47 |  |  | 
|  |  | 48 |  | public static class TriggerCreateDtoExtensions | 
|  |  | 49 |  | { | 
|  |  | 50 |  |   public static TriggerCreateBusinessModel ToBusinessModel(this TriggerCreateDto triggerCreateDto) | 
|  | 0 | 51 |  |   { | 
|  | 0 | 52 |  |     return new TriggerCreateBusinessModel { | 
|  | 0 | 53 |  |       Name = triggerCreateDto.Name, | 
|  | 0 | 54 |  |       Url = triggerCreateDto.Url, | 
|  | 0 | 55 |  |       HttpMethodId = triggerCreateDto.HttpMethodId, | 
|  | 0 | 56 |  |       Body = triggerCreateDto.Body, | 
|  | 0 | 57 |  |       ApiKeyInsertLocationId = triggerCreateDto.ApiKeyInsertLocationId, | 
|  | 0 | 58 |  |       ApiKeyFieldName = triggerCreateDto.ApiKeyFieldName, | 
|  | 0 | 59 |  |       ApiKeyId = triggerCreateDto.ApiKeyId, | 
|  | 0 | 60 |  |     }; | 
|  | 0 | 61 |  |   } | 
|  |  | 62 |  | } |