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