PriceQtyModel PriceQtyFactory() { var result = new PriceQtyModel { PriceID = "A", Qty = 1, Harga = 5, Diskon = 2 }; return(result); }
public void Insert(PriceQtyModel priceQty) { var sSql = @" INSERT INTO PriceQty ( PriceID, Qty, Harga, Diskon ) VALUES ( @PriceID, @Qty, @Harga, @Diskon) "; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand(sSql, conn)) { cmd.AddParam("@PriceID", priceQty.PriceID); cmd.AddParam("@Qty", priceQty.Qty); cmd.AddParam("@Harga", priceQty.Harga); cmd.AddParam("@Diskon", priceQty.Diskon); conn.Open(); cmd.ExecuteNonQuery(); } }
public IEnumerable <PriceQtyModel> ListData(string priceID) { List <PriceQtyModel> result; var sSql = @" SELECT PriceID, Qty, Harga, Diskon FROM PriceQty WHERE PriceID = @PriceID "; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand(sSql, conn)) { cmd.AddParam("@PriceID", priceID); conn.Open(); using (var dr = cmd.ExecuteReader()) { if (!dr.HasRows) { return(null); } result = new List <PriceQtyModel>(); while (dr.Read()) { var item = new PriceQtyModel { PriceID = dr["PriceID"].ToString(), Qty = Convert.ToInt16(dr["Qty"]), Harga = Convert.ToDecimal(dr["Harga"]), Diskon = Convert.ToDecimal(dr["Diskon"]) }; result.Add(item); } } } return(result); }