public DTOId Incluir(int idEvento, DTOSalaEstudo dto) { DTOId retorno = new DTOId(); ExecutarSeguramente(() => { var evento = Contexto.RepositorioEventos.ObterEventoPeloId(idEvento); var sala = new SalaEstudo(evento, dto.Nome); sala.DeveSerParNumeroTotalParticipantes = dto.DeveSerParNumeroTotalParticipantes; if (dto.IdadeMaxima != null && dto.IdadeMinima != null) { sala.FaixaEtaria = new FaixaEtaria(dto.IdadeMinima.Value, dto.IdadeMaxima.Value); } else if (dto.IdadeMaxima != null || dto.IdadeMinima != null) { throw new ExcecaoAplicacao("AppSalasEstudo", "Ao definir a faixa etária, deve-se informar a idade mínima e máxima"); } Contexto.RepositorioSalasEstudo.Incluir(sala); retorno.Id = sala.Id; }); return(retorno); }
public DTOSalaEstudo ObterPorId(int idEvento, int id) { DTOSalaEstudo dto = null; ExecutarSeguramente(() => { var sala = Contexto.RepositorioSalasEstudo.ObterPorId(idEvento, id); if (sala != null) { dto = sala.Converter(); } }); return(dto); }
public void Atualizar(int idEvento, int id, DTOSalaEstudo dto) { ExecutarSeguramente(() => { var sala = ObterSalaOuExcecaoSeNaoEncontrar(idEvento, id); sala.Nome = dto.Nome; sala.DeveSerParNumeroTotalParticipantes = dto.DeveSerParNumeroTotalParticipantes; if (dto.IdadeMaxima != null && dto.IdadeMinima != null) { sala.FaixaEtaria = new FaixaEtaria(dto.IdadeMinima.Value, dto.IdadeMaxima.Value); } else if (dto.IdadeMaxima != null || dto.IdadeMinima != null) { throw new ExcecaoAplicacao("AppSalasEstudo", "Ao definir a faixa etária, deve-se informar a idade mínima e máxima"); } Contexto.RepositorioSalasEstudo.Atualizar(sala); }); }