|  |  | 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 FlowCreateDto : IValidatableObject | 
|  |  | 7 |  | { | 
|  |  | 8 |  |   [Required (ErrorMessage = "Please enter a name.")] | 
|  | 0 | 9 |  |   public required string Name { get; set; } | 
|  |  | 10 |  |  | 
|  | 0 | 11 |  |   public required IList<FlowDetailCreateDto> FlowDetails { get; set; } = []; | 
|  |  | 12 |  |  | 
|  |  | 13 |  |   public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | 
|  | 0 | 14 |  |   { | 
|  | 0 | 15 |  |     foreach (var flow in FlowDetails) | 
|  | 0 | 16 |  |     { | 
|  | 0 | 17 |  |       List<ValidationResult> validationResults = []; | 
|  | 0 | 18 |  |       var vc = new ValidationContext(flow); | 
|  | 0 | 19 |  |       Validator.TryValidateObject(flow, vc, validationResults, true); | 
|  | 0 | 20 |  |       foreach (var validationResult in validationResults) | 
|  | 0 | 21 |  |       { | 
|  | 0 | 22 |  |         yield return validationResult; | 
|  | 0 | 23 |  |       } | 
|  | 0 | 24 |  |     } | 
|  | 0 | 25 |  |   } | 
|  |  | 26 |  | } | 
|  |  | 27 |  |  | 
|  |  | 28 |  | public static class FlowCreateDtoExtensions | 
|  |  | 29 |  | { | 
|  |  | 30 |  |   public static FlowCreateBusinessModel ToBusinessModel(this FlowCreateDto flowCreateDto) | 
|  |  | 31 |  |   { | 
|  |  | 32 |  |     return new FlowCreateBusinessModel { | 
|  |  | 33 |  |       Name = flowCreateDto.Name, | 
|  |  | 34 |  |       FlowDetails = flowCreateDto.FlowDetails.Select(fd => fd.ToBusinessModel()).ToList(), | 
|  |  | 35 |  |     }; | 
|  |  | 36 |  |   } | 
|  |  | 37 |  | } |