public static void Atualizar(int id, string nome, string genitor, string genitora, string RG, string CPF, int qtdeFilhos, bool possuiMenor, string anotacoes) { if (genitora == null || genitora.Length == 0) { throw new NegocioException(NegocioExcCode.DETENTOGENITORAOBRIGATORIA, ""); } using (ObservatorioEntities context = new ObservatorioEntities()) { var detento_ = from Detento d in context.Detentos where d.Id == id select d; if (detento_.Count() > 0) { Detento d = detento_.First(); d.Nome = nome; d.Genitor = genitor; d.Genitora = genitora; d.RG = RG; d.CPF = CPF; d.QtdeFilhos = qtdeFilhos; d.PossuiMenor = possuiMenor; d.Anotacoes = anotacoes; context.SaveChanges(); } } }
/// <summary> /// Consulta um detento pelo seu Id. /// </summary> /// <param name="id"></param> /// <returns></returns> public static Detento Consultar(int id) { Detento detento = null; using (ObservatorioEntities context = new ObservatorioEntities()) { var detento_ = from Detento d in context.Detentos where d.Id == id select d; if (detento_.Count() > 0) { detento = detento_.First(); } else { throw new NegocioException(NegocioExcCode.DETENTOIDNAOENCONTRADO, id.ToString()); } } return(detento); }
/// <summary> /// Insere um novo detento. /// </summary> /// <param name="nome"></param> public static void Inserir(string nome, string genitor, string genitora, string RG, string CPF, int qtdeFilhos, bool possuiMenor, string anotacoes) { if (genitora == null || genitora.Length == 0) { throw new NegocioException(NegocioExcCode.DETENTOGENITORAOBRIGATORIA, ""); } using (ObservatorioEntities context = new ObservatorioEntities()) { Detento d = new Detento(); d.Nome = nome; d.Genitor = genitor; d.Genitora = genitora; d.RG = RG; d.CPF = CPF; d.QtdeFilhos = qtdeFilhos; d.PossuiMenor = possuiMenor; d.Anotacoes = anotacoes; context.Detentos.Add(d); context.SaveChanges(); } }