Spaces:
Runtime error
Runtime error
Download src/SCM.Domain/Qualidade/Agente.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Domain/Qualidade/Agente.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Domain/Qualidade/Agente.cs
-
curl -L -o Agente.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Domain/Qualidade/Agente.cs
2.07 kB
| using SCM.Shared.Exceptions; | |
| namespace SCM.Domain.Qualidade; | |
| /// <summary> | |
| /// Agente de qualidade (inspetor/fiscal CQ ou produção). Migrado de MCQ/AgenteController (cl_fiscalCQ). | |
| /// Invariantes: código e nome obrigatórios; CPF, quando informado, deve ser válido (armazenado só com dígitos). | |
| /// </summary> | |
| public sealed class Agente | |
| { | |
| public const int MaxCodigo = 50; | |
| public const int MaxNome = 200; | |
| public Guid Id { get; set; } | |
| public string Codigo { get; set; } = string.Empty; | |
| public string Nome { get; set; } = string.Empty; | |
| public AgenteTipo Tipo { get; set; } | |
| public string? Cpf { get; set; } | |
| public string? Email { get; set; } | |
| public static Agente Create(string codigo, string nome, AgenteTipo tipo, string? cpf, string? email) | |
| => new() | |
| { | |
| Id = Guid.NewGuid(), | |
| Codigo = NormalizeCodigo(codigo), | |
| Nome = NormalizeNome(nome), | |
| Tipo = tipo, | |
| Cpf = NormalizeCpf(cpf), | |
| Email = TrimOrNull(email) | |
| }; | |
| public void Atualizar(string codigo, string nome, AgenteTipo tipo, string? cpf, string? email) | |
| { | |
| Codigo = NormalizeCodigo(codigo); | |
| Nome = NormalizeNome(nome); | |
| Tipo = tipo; | |
| Cpf = NormalizeCpf(cpf); | |
| Email = TrimOrNull(email); | |
| } | |
| private static string NormalizeCodigo(string v) | |
| { | |
| if (string.IsNullOrWhiteSpace(v)) throw new DomainException("O código do agente é obrigatório."); | |
| return v.Trim(); | |
| } | |
| private static string NormalizeNome(string v) | |
| { | |
| if (string.IsNullOrWhiteSpace(v)) throw new DomainException("O nome do agente é obrigatório."); | |
| return v.Trim(); | |
| } | |
| private static string? NormalizeCpf(string? cpf) | |
| { | |
| if (string.IsNullOrWhiteSpace(cpf)) return null; | |
| if (!CpfValidator.IsValid(cpf)) throw new DomainException("CPF inválido."); | |
| return CpfValidator.OnlyDigits(cpf); | |
| } | |
| private static string? TrimOrNull(string? v) => string.IsNullOrWhiteSpace(v) ? null : v.Trim(); | |
| } | |