public void InsertRequest(string p_id, Request r) { Prescription er = (Prescription)r; if (er.Medicines.Count == 0) { throw new ApplicationException(ErrorMessages.Messages["REQ_P_medicines"]); } IDatabase db = new MSSqlDatabase(); db.Connect(); db.BeginTransaction(); DbCommand command = db.CreateCommand(sqlINSERT); PrepareCommand(db, command, er, p_id); er.Id = db.ExecuteScalar(command); int added = this.InsertMedicines(er, db); db.EndTransaction(); if (added != er.Medicines.Count) { db.Rollback(); } db.Close(); }
public void UpdateRequest(Request r) { Prescription er = (Prescription)r; IDatabase db = new MSSqlDatabase(); db.Connect(); db.BeginTransaction(); DbCommand command = db.CreateCommand(sqlUPDATE); command.Parameters.Add(db.CreateParameter("@date", "datetime")); command.Parameters["@date"].Value = er.Created; command.Parameters.Add(db.CreateParameter("@id", "int")); command.Parameters["@id"].Value = er.Id; db.ExecuteNonQuery(command); this.DeleteMedicines(er); int added = this.InsertMedicines(er, db); db.EndTransaction(); if (added != er.Medicines.Count) { db.Rollback(); } db.Close(); }