117 lines
3.4 KiB
C#
117 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BLL
|
|
{
|
|
public class BLLEmpresaConfig
|
|
{
|
|
private readonly DALEmpresaConfig _dal;
|
|
|
|
public BLLEmpresaConfig( string connectionString)
|
|
{
|
|
_dal = new DALEmpresaConfig(connectionString);
|
|
}//metodo construtor
|
|
public bool Inserir(ModeloEmpresaConfig config)
|
|
{
|
|
ValidarInserir(config);
|
|
bool result = _dal.Inserir(config);
|
|
if (result)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}//Inserir
|
|
public bool Alterar(ModeloEmpresaConfig config)
|
|
{
|
|
ValidarAlterar(config);
|
|
bool result = _dal.Atualizar(config);
|
|
if (result)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}//Alterar
|
|
public bool Excluir(int Cod)
|
|
{
|
|
bool result = _dal.Excluir(Cod);
|
|
if (result)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}//Excluir
|
|
public List<ModeloEmpresaConfig> LocalizarTodas()
|
|
{
|
|
return _dal.LocalizarTodas();
|
|
}//LocalizarTodas
|
|
public ModeloEmpresaConfig ObterPorEmpresa(int idEmpresa)
|
|
{
|
|
return _dal.ObterPorEmpresa(idEmpresa);
|
|
}//ObterPorEmpresa
|
|
public int ObterEmpresaAtivaId()
|
|
{
|
|
return _dal.ObterEmpresaAtivaId();
|
|
}//Obter ID empresa ativa
|
|
|
|
#region VALIDAÇÕES
|
|
private void ValidarInserir(ModeloEmpresaConfig config)
|
|
{
|
|
|
|
if (config.IdEmpresa <= 0)
|
|
throw new Exception("Empresa inválida.");
|
|
|
|
if (string.IsNullOrWhiteSpace(config.NomeSistema))
|
|
throw new Exception("Nome do sistema é obrigatório.");
|
|
|
|
if (config.DiasGarantiaPadrao < 0)
|
|
throw new Exception("Dias de garantia inválido.");
|
|
|
|
if (!string.IsNullOrEmpty(config.CorPrimaria) && !config.CorPrimaria.StartsWith("#"))
|
|
throw new Exception("Cor primária inválida. Use formato HEX (#FFFFFF).");
|
|
|
|
if (!string.IsNullOrEmpty(config.CorSecundaria) && !config.CorSecundaria.StartsWith("#"))
|
|
throw new Exception("Cor secundária inválida.");
|
|
|
|
}//inserir
|
|
|
|
private void ValidarAlterar(ModeloEmpresaConfig config)
|
|
{
|
|
if (config.IdEmpresaConfig <= 0)
|
|
throw new Exception("Código da configuração invalida");
|
|
|
|
if (config.IdEmpresa <= 0)
|
|
throw new Exception("Empresa inválida.");
|
|
|
|
if (string.IsNullOrWhiteSpace(config.NomeSistema))
|
|
throw new Exception("Nome do sistema é obrigatório.");
|
|
|
|
if (config.DiasGarantiaPadrao < 0)
|
|
throw new Exception("Dias de garantia inválido.");
|
|
|
|
if (!string.IsNullOrEmpty(config.CorPrimaria) && !config.CorPrimaria.StartsWith("#"))
|
|
throw new Exception("Cor primária inválida. Use formato HEX (#FFFFFF).");
|
|
|
|
if (!string.IsNullOrEmpty(config.CorSecundaria) && !config.CorSecundaria.StartsWith("#"))
|
|
throw new Exception("Cor secundária inválida.");
|
|
|
|
}//inserir
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|