public bool Registrar(FormularioRegistrarNotificacion formulario) { try { Notificacion notificacion = formulario.Notificacion; IEnumerable <Segmento> segmentos = formulario.Segmentos; notificacion.FechaInicio = DateTime.Now; if (repositorio.Insertar(notificacion)) { RepositorioSegmento repoSegmento = new RepositorioSegmento(); RepositorioCargo repoCargo = new RepositorioCargo(); int id = repositorio.PorUltimoId(); foreach (Segmento segmento in segmentos) { segmento.Notificacion = id; if (repoCargo.PorId(segmento.Cargo) is Cargo cargo) { repoSegmento.Insertar(segmento); } } return(true); } return(false); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } }
public bool Eliminar(Notificacion notificacion) { try { RepositorioNotificacion repoNotificacion = new RepositorioNotificacion(); RepositorioSegmento repoSegmento = new RepositorioSegmento(); int id = notificacion.Id; if (repoSegmento.EliminarPorNotificacion(notificacion)) { repoNotificacion.Eliminar(notificacion); return(true); } return(false); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } }
public SegmentoController() { repositorio = new RepositorioSegmento(); }