public bool Adicionar(ExameViewModel exameViewModel) { exameViewModel.Renovado = false; var exame = Mapper.Map <ExameViewModel, Exame>(exameViewModel); var examespRenovar = _exameService.Find(e => (e.FuncionarioId == exame.FuncionarioId) && (e.TipoExameId == exame.TipoExameId) && (e.Renovado == false) && (e.Delete == false)).FirstOrDefault(); BeginTransaction(); if (examespRenovar != null) { examespRenovar.Renovado = true; _exameService.Atualizar(examespRenovar); } _exameService.Adicionar(exame); Commit(); return(true); }
public string Excluir(int id) { bool existente = _tipoExameService.Find(e => e.TipoExameId == id && (e.Delete == false)).Any(); bool exameUtiliza = _exameService.Find(c => c.TipoExameId == id && c.Delete == false).Any(); if (existente && !exameUtiliza) { BeginTransaction(); var tipoExame = _tipoExameService.ObterPorId(id); tipoExame.Delete = true; _tipoExameService.Atualizar(tipoExame); Commit(); return(""); } return("Exclusão negada! Existem exames com esse tipo"); }