public int Guardar(string descripcion) {//se recomienda no usar try { int id = getIdSiguiente(); using (TECAv8Entities ent = new TECAv8Entities()) { Estado estado = new Estado() { IdEstado = id, Descripcion = descripcion }; ent.AddToEstado(estado); ent.SaveChanges(); return(id);//devuelve el id de ese estado guardado } } catch (Exception e) { Console.WriteLine("Error: " + e); return(0); } }
//recibe un objeto estado, busca segun descripcion, si NO existe lo guarda //al final retorna un objeto estado con el idEstado y descripcion deseados public clsEstado GuardarNuevoEstado(clsEstado oEstadoEntrante) { clsEstado oEstadoSaliente = new clsEstado(); try { int x = getIdSegunDescripcion(oEstadoEntrante.descripcion); if (x == 0) { int id = getIdSiguiente(); using (TECAv8Entities ent = new TECAv8Entities()) { Estado estado = new Estado() { IdEstado = oEstadoEntrante.idEstado, Descripcion = oEstadoEntrante.descripcion }; ent.AddToEstado(estado); ent.SaveChanges(); oEstadoSaliente = oEstadoEntrante; return(oEstadoSaliente);//devuelve el id de ese estado guardado } } else { oEstadoEntrante.idEstado = getIdSegunDescripcion(oEstadoEntrante.descripcion); oEstadoSaliente = oEstadoEntrante; return(oEstadoSaliente); } } catch (Exception e) { Console.WriteLine("Error: " + e); return(oEstadoSaliente); } }
public clsEstado GuardarSimple(clsEstado oEntrante) { clsEstado oSaliente = new clsEstado(); try { oSaliente = Consultar(oEntrante); if (oSaliente.idEstado == 0) { int id = getIdSiguiente(); using (TECAv8Entities ent = new TECAv8Entities()) { Estado estado = new Estado() { IdEstado = id, Descripcion = oEntrante.descripcion }; ent.AddToEstado(estado); ent.SaveChanges(); oSaliente.idEstado = id; oSaliente.descripcion = oEntrante.descripcion; return oSaliente;//devuelve el id de ese estado guardado } } else { oSaliente = oEntrante; return oSaliente; } } catch (Exception e) { Console.WriteLine("Error: " + e); return oSaliente; } }
//recibe un objeto estado, busca segun descripcion, si NO existe lo guarda //al final retorna un objeto estado con el idEstado y descripcion deseados public clsEstado GuardarNuevoEstado(clsEstado oEstadoEntrante) { clsEstado oEstadoSaliente = new clsEstado(); try { int x = getIdSegunDescripcion(oEstadoEntrante.descripcion); if (x == 0) { int id = getIdSiguiente(); using (TECAv8Entities ent = new TECAv8Entities()) { Estado estado = new Estado() { IdEstado = oEstadoEntrante.idEstado, Descripcion = oEstadoEntrante.descripcion }; ent.AddToEstado(estado); ent.SaveChanges(); oEstadoSaliente = oEstadoEntrante; return oEstadoSaliente;//devuelve el id de ese estado guardado } } else { oEstadoEntrante.idEstado = getIdSegunDescripcion(oEstadoEntrante.descripcion); oEstadoSaliente = oEstadoEntrante; return oEstadoSaliente; } } catch (Exception e) { Console.WriteLine("Error: " + e); return oEstadoSaliente; } }
public int Guardar(string descripcion) { //se recomienda no usar try { int id = getIdSiguiente(); using (TECAv8Entities ent = new TECAv8Entities()) { Estado estado = new Estado() { IdEstado = id, Descripcion = descripcion }; ent.AddToEstado(estado); ent.SaveChanges(); return id;//devuelve el id de ese estado guardado } } catch (Exception e) { Console.WriteLine("Error: " + e); return 0; } }