| | 1 | | using System.ComponentModel.DataAnnotations; |
| | 2 | | using LGDXRobotCloud.Data.Models.Business.Administration; |
| | 3 | |
|
| | 4 | | namespace LGDXRobotCloud.Data.Models.DTOs.V1.Commands; |
| | 5 | |
|
| | 6 | | public record LgdxRoleCreateDto : IValidatableObject |
| | 7 | | { |
| | 8 | | [Required (ErrorMessage = "Please enter a name.")] |
| | 9 | | public required string Name { get; set; } |
| | 10 | |
|
| | 11 | | public string? Description { get; set; } |
| | 12 | |
|
| | 13 | | public IEnumerable<string> Scopes { get; set; } = []; // Empty scope is allowed |
| | 14 | |
|
| | 15 | | public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) |
| | 16 | | { |
| | 17 | | int i = 0; |
| | 18 | | foreach (var scope in Scopes) |
| | 19 | | { |
| | 20 | | if (string.IsNullOrWhiteSpace(scope)) |
| | 21 | | { |
| | 22 | | yield return new ValidationResult($"Scope is required.", [nameof(Scopes), $"{nameof(Scopes)}-{i}"]); |
| | 23 | | } |
| | 24 | | i++; |
| | 25 | | } |
| | 26 | | } |
| | 27 | | } |
| | 28 | |
|
| | 29 | | public static class LgdxRoleCreateDtoExtensions |
| | 30 | | { |
| | 31 | | public static LgdxRoleCreateBusinessModel ToBusinessModel(this LgdxRoleCreateDto model) |
| 0 | 32 | | { |
| 0 | 33 | | return new LgdxRoleCreateBusinessModel |
| 0 | 34 | | { |
| 0 | 35 | | Name = model.Name, |
| 0 | 36 | | Description = model.Description, |
| 0 | 37 | | Scopes = model.Scopes, |
| 0 | 38 | | }; |
| 0 | 39 | | } |
| | 40 | | } |