/// <summary> /// Delete OrderProduct from the database /// </summary> /// <param name="orderProduct"></param> /// <param name="db"></param> public static void RemoveOrderProduct(OrderProductModel orderProduct, string db) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db))) { var p = new DynamicParameters(); p.Add("@Id", orderProduct.Id); connection.Execute("dbo.spOrderProduct_Delete", p, commandType: CommandType.StoredProcedure); } }
/// <summary> /// Add orderProduct to the database /// return it with the new Id /// </summary> /// <param name="OrderProduct"></param> /// <param name="Order"></param> /// <param name="db"></param> /// <returns></returns> public static OrderProductModel AddOrderProductToTheDatabase(OrderProductModel OrderProduct, OrderModel Order, string db) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db))) { var p = new DynamicParameters(); p.Add("@OrderId", Order.Id); p.Add("@ProductId", OrderProduct.Product.Id); p.Add("@SalePrice", OrderProduct.SalePrice); p.Add("@Quantity", OrderProduct.Quantity); p.Add("@Discount", OrderProduct.Discount); p.Add("@Profit", OrderProduct.Profit); p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); connection.Execute("dbo.spOrderProduct_Create", p, commandType: CommandType.StoredProcedure); OrderProduct.Id = p.Get <int>("@Id"); } return(OrderProduct); }