Esempio n. 1
0
        public EmpregadoModel(string Nome, DateTime DataNascimento, DateTime DataIngresso)
        {
            if (Nome == null)
            {
                throw new ArgumentNullException(EXCEPTION_MENSAGEM_NOME_NULL);
            }
            if (Nome.Trim() == "")
            {
                throw new ArgumentException(EXCEPTION_MENSAGEM_NOME_VAZIO);
            }
            if (new DateTime(DataNascimento.Year, DataNascimento.Month, DataNascimento.Day) > new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day))
            {
                throw new ArgumentException(EXCEPTION_MENSAGEM_DATA_NASCIMENTO_MAIOR_DATA_ATUAL);
            }
            try
            {
                if (DataHoraHelper.DiferencaEmAnos(DataNascimento) < 18)
                {
                    throw new ArgumentException(EXCEPTION_MENSAGEM_DATA_NASCIMENTO_MAIOR_IDADE);
                }
            }
            catch (ArgumentOutOfRangeException Ex)
            {
                throw new ArgumentException(EXCEPTION_MENSAGEM_DATA_NASCIMENTO_INVALIDA);
            }
            if (new DateTime(DataIngresso.Year, DataIngresso.Month, DataIngresso.Day) > new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day))
            {
                throw new ArgumentException(EXCEPTION_MENSAGEM_DATA_INGRESSO_MAIOR_DATA_ATUAL);
            }

            nome           = Nome;
            dataNascimento = DataNascimento;
            dataIngresso   = DataIngresso;
        }
Esempio n. 2
0
 public int GetTempoDeTrabalho()
 {
     try
     {
         return(DataHoraHelper.DiferencaEmAnos(dataIngresso));
     }
     catch (ArgumentOutOfRangeException Ex)
     {
         return(0);
     }
 }
Esempio n. 3
0
 public int GetIdade()
 {
     try
     {
         return(DataHoraHelper.DiferencaEmAnos(dataNascimento));
     }
     catch (ArgumentOutOfRangeException Ex)
     {
         return(0);
     }
 }
Esempio n. 4
0
 public void TestDiferencaEmAnosDataInvalida()
 {
     DataHoraHelper.DiferencaEmAnos(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1));
 }
Esempio n. 5
0
        public void TestDiferencaEmAnos()
        {
            double valor = DataHoraHelper.DiferencaEmAnos(new DateTime(DateTime.Now.Year - 30, DateTime.Now.Month, DateTime.Now.Day));

            Assert.AreEqual(30, valor);
        }