Esempio n. 1
0
        public static EmpresasController GetInstance()
        {
            if (_instance == null)
            {
                _instance = new EmpresasController();
            }

            return(_instance);
        }
        public void AddProjeto(Projeto projeto, string empresaId)
        {
            if (string.IsNullOrEmpty(projeto.Nome))
            {
                throw new ApplicationException("Projeto sem nome");
            }

            var empresa = EmpresasController.GetInstance().Empresas.FirstOrDefault(x => x.Id == empresaId);

            if (empresa == null)
            {
                throw new ApplicationException($"Empresa com ID = '{empresaId}' não foi encontrada");
            }

            empresa.Projetos.Add(projeto);
            Projetos.Add(projeto);
        }
        public void AddFuncionario(Funcionario funcionario, string empresaId)
        {
            if (string.IsNullOrEmpty(funcionario.Nome))
            {
                throw new ApplicationException("Funcionário sem nome");
            }

            var empresa = EmpresasController.GetInstance().Empresas.FirstOrDefault(x => x.Id == empresaId);

            if (empresa == null)
            {
                throw new ApplicationException($"Empresa com ID = '{empresaId}' não foi encontrada");
            }

            empresa.Funcionarios.Add(funcionario);
            Funcionarios.Add(funcionario);
        }