//Obtener detalle de pipa public Pipa detail(int id) { Pipa pipa = pipa_repository.detail(id); pipa.tanques = pipa_repository.getAllTanquesByIdPipa(pipa.id); return(pipa); }
//Create Pipa con sus tanques public TransactionResult create(PipaVo pipa_vo) { //Pipa pipa = PipaAdapter.voToObject(pipa_vo); //return pipa_repository.create(pipa); Pipa pipa = PipaAdapter.voToObject(pipa_vo); int id = pipa_repository.create(pipa); if (id > 0) { foreach (TanqueVo dvo in pipa_vo.tanques) { dvo.pipa_id = id; var tr2 = TransactionResult.CREATED; tr2 = pipa_repository.createTanque(TanqueAdapter.voToObject(dvo)); if (tr2 != TransactionResult.CREATED) { return(tr2); } } return(TransactionResult.CREATED); } return(TransactionResult.ERROR); }
/// <summary> /// Create new object on the db /// </summary> /// <param name="empleado"></param> /// <returns></returns> public int create(Pipa pipa) { SqlConnection connection = null; using (connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Coz_Combustibles_DB"].ConnectionString)) { try { connection.Open(); SqlCommand command = new SqlCommand("sp_createPipa", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("nombre", Validations.defaultString(pipa.nombre))); command.Parameters.Add(new SqlParameter("no_economico", Validations.defaultString(pipa.no_economico))); command.Parameters.Add(new SqlParameter("placas", Validations.defaultString(pipa.placas))); SqlDataAdapter data_adapter = new SqlDataAdapter(command); DataSet data_set = new DataSet(); data_adapter.Fill(data_set); DataRow row = data_set.Tables[0].Rows[0]; return(int.Parse(row[0].ToString())); //command.ExecuteNonQuery(); //return TransactionResult.CREATED; } catch (SqlException ex) { if (connection != null) { connection.Close(); } if (ex.Number == 2627) { return(0); } return(0); } catch { if (connection != null) { connection.Close(); } return(0); } } }
public HttpResponseMessage detail(int id) { Pipa pipa = pipa_service.detail(id); if (pipa != null) { IDictionary <string, Pipa> data = new Dictionary <string, Pipa>(); data.Add("data", pipa); return(Request.CreateResponse(HttpStatusCode.OK, data)); } else { IDictionary <string, string> data = new Dictionary <string, string>(); data.Add("message", "Object not found."); return(Request.CreateResponse(HttpStatusCode.BadRequest, data)); } }
public TransactionResult update(Pipa pipa) { SqlConnection connection = null; using (connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Coz_Combustibles_DB"].ConnectionString)) { try { connection.Open(); SqlCommand command = new SqlCommand("sp_updatePipa", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("nombre", Validations.defaultString(pipa.nombre))); command.Parameters.Add(new SqlParameter("no_economico", Validations.defaultString(pipa.no_economico))); command.Parameters.Add(new SqlParameter("placas", Validations.defaultString(pipa.placas))); command.Parameters.Add(new SqlParameter("id", pipa.id)); command.ExecuteNonQuery(); return(TransactionResult.OK); } catch (SqlException ex) { if (connection != null) { connection.Close(); } if (ex.Number == 2627) { return(TransactionResult.EXISTS); } return(TransactionResult.NOT_PERMITTED); } catch { if (connection != null) { connection.Close(); } return(TransactionResult.ERROR); } } }
public static PipaVo objectToVo(Pipa obj) { return(new PipaVo { }); }