Spaces:
Runtime error
Runtime error
File size: 2,151 Bytes
3dd5c9a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TaskTrackingSystem.Shared.Models.User
{
public class CreateUserDto : IValidatableObject
{
[Required, MaxLength(50)]
[MinLength(3, ErrorMessage = ResultMessages.UsernameMinLength)]
[RegularExpression(@"^[a-zA-Z0-9._]+$", ErrorMessage = ResultMessages.UsernameInvalidCharacters)]
public string Username { get; set; } = string.Empty;
[MaxLength(50)]
public string FirstName { get; set; } = string.Empty;
[MaxLength(50)]
public string LastName { get; set; } = string.Empty;
[MaxLength(50)]
public string? FirstNameMy { get; set; }
[MaxLength(50)]
public string? LastNameMy { get; set; }
[Required, EmailAddress, MaxLength(256)]
public string Email { get; set; } = string.Empty;
[Required]
[MinLength(8, ErrorMessage = ResultMessages.PasswordMinLengthRule)]
[RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z0-9]).+$", ErrorMessage = ResultMessages.PasswordComplexityRule)]
public string Password { get; set; } = string.Empty;
[MaxLength(20)]
public string? Phone { get; set; }
[Required]
public long RoleId { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var englishComplete = !string.IsNullOrWhiteSpace(FirstName) && !string.IsNullOrWhiteSpace(LastName);
var burmeseComplete = !string.IsNullOrWhiteSpace(FirstNameMy) && !string.IsNullOrWhiteSpace(LastNameMy);
if (!englishComplete && !burmeseComplete)
{
yield return new ValidationResult("At least one complete name is required.", new[] { nameof(FirstName), nameof(LastName), nameof(FirstNameMy), nameof(LastNameMy) });
}
}
}
}
|