Example #1
0
        public static async Task Validate(string owner, string name = "")
        {
            try
            {
                var nameIsEmpty = name.Length == 0;
                if (nameIsEmpty)
                {
                    return;
                }
                ;

                var isInRange   = name.Length >= MinLength && name.Length <= MaxLength;
                var nameIsTaken = await AccountDAO.CheckIfAccountNameForUserIsTaken(owner, name);

                if (!isInRange)
                {
                    throw new ValidationException("Nome", $"Nome da conta deve ter entre {MinLength} e {MaxLength} caracteres.");
                }
                if (nameIsTaken)
                {
                    throw new ValidationException("Nome", "Você já cadastrou uma conta com esse nome, use outro.");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }