public ActionResult DeleteConfirmed(int id) { TMedication tMedication = db.TMedications.Find(id); db.TMedications.Remove(tMedication); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "intMedicationID,strMedicationName,strMedicationDesc,dblCost,dblPrice,strNotes,intQuantity,intMethodID")] TMedication tMedication) { if (ModelState.IsValid) { db.Entry(tMedication).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tMedication)); }
public ActionResult Create([Bind(Include = "intMedicationID,strMedicationName,strMedicationDesc,dblCost,dblPrice,strNotes,intQuantity,intMethodID")] TMedication tMedication) { if (ModelState.IsValid) { db.TMedications.Add(tMedication); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tMedication)); }
// GET: TMedications/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TMedication tMedication = db.TMedications.Find(id); if (tMedication == null) { return(HttpNotFound()); } return(View(tMedication)); }
// GET: TMedications/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TMedication tMedication = db.TMedications.Find(id); if (tMedication == null) { return(HttpNotFound()); } ViewBag.intMethodID = new SelectList(db.TMethods, "intMethodID", "strMethod"); return(View(tMedication)); }
public ActionResult AddOrder(int id) { TMedication medication = db.TMedications.Where(x => x.intMedicationID == id).FirstOrDefault(); OrderMedication orderMedication = new OrderMedication() { dtmDateOfOrder = DateTime.Now, intMedicationId = medication.intMedicationID, strMedicationName = medication.strMedicationName, dblUnitCost = medication.dblCost, intCurrentQuantity = medication.intQuantity, intOrderQuantity = 0, dblTotal = 0, strNotes = "" }; ViewBag.intMedicationId = new SelectList(db.TMedications, "intMedicationID", "strMedicationName"); return(View(orderMedication)); }
public ActionResult AddOrder(OrderMedication order) { TMedication medication = db.TMedications.Where(x => x.intMedicationID == order.intMedicationId).FirstOrDefault(); SqlParameter[] param = new SqlParameter[] { new SqlParameter("@intMedicationID", medication.intMedicationID), new SqlParameter("@strMedicationName", medication.strMedicationName), new SqlParameter("@strMedicationDesc", medication.strMedicationDesc), new SqlParameter("@dblCost", medication.dblCost), new SqlParameter("@dblPrice", medication.dblPrice), new SqlParameter("@strNotes", medication.strNotes), new SqlParameter("@intQuantity", medication.intQuantity + order.intOrderQuantity), new SqlParameter("@intMethodID", medication.intMethodID), }; db.uspAddMedicationOrder(order.dtmDateOfOrder, medication.intMedicationID, medication.strMedicationName, medication.dblCost, order.intOrderQuantity, medication.dblCost * order.intOrderQuantity, order.strNotes); db.Database.ExecuteSqlCommand("uspUpdateMedication @intMedicationID, @strMedicationName, @strMedicationDesc,@dblCost, @dblPrice,@strNotes,@intQuantity, @intMethodID ", param); return(RedirectToAction("Index")); }
public ActionResult DeletePetMedication(int medicationId) { TVisitMedication visitMedication = db.TVisitMedications.Where(x => x.intVisitMedicationID == medicationId).FirstOrDefault(); TMedication medicationInfo = db.TMedications.Where(x => x.intMedicationID == medicationId).FirstOrDefault(); SqlParameter[] param = new SqlParameter[] { new SqlParameter("@intMedicationID", medicationInfo.intMedicationID), new SqlParameter("@strMedicationName", medicationInfo.strMedicationName), new SqlParameter("@strMedicationDesc", medicationInfo.strMedicationDesc), new SqlParameter("@dblCost", medicationInfo.dblCost), new SqlParameter("@dblPrice", medicationInfo.dblPrice), new SqlParameter("@strNotes", medicationInfo.strNotes), new SqlParameter("@intQuantity", medicationInfo.intQuantity + visitMedication.intQuantity), new SqlParameter("@intMethodID", medicationInfo.intMethodID) }; db.Database.ExecuteSqlCommand("uspUpdateMedication @intMedicationID, @strMedicationName, @strMedicationDesc,@dblCost, @dblPrice,@strNotes,@intQuantity, @intMethodID ", param); db.TVisitMedications.Remove(visitMedication); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddPetMedication([Bind(Include = "intVisitMedicationID, intVisitID, intMedicationID, dtmDatePrescribed, intQuantity, strMedicationNotes")] TVisitMedication visitMedication) { int intMedicationId = (int)Session["intMedicationID"]; int intPetId = (int)Session["intPetID"]; int intVisitId = (int)Session["intVisitId"]; int updatedQuantity = 0; if (ModelState.IsValid) { TMedication medication = db.TMedications.Where(x => x.intMedicationID == intMedicationId).FirstOrDefault(); int currentQuantity = db.TMedications.Where(x => x.intMedicationID == intMedicationId).Select(z => z.intQuantity).FirstOrDefault(); //Precursory check for medications if (currentQuantity >= visitMedication.intQuantity) { updatedQuantity = currentQuantity - visitMedication.intQuantity; } else { visitMedication.intQuantity = 0; updatedQuantity = currentQuantity; ViewBag.Name = db.TPets.Where(x => x.intPetID == intPetId).Select(z => z.strPetName).FirstOrDefault(); ViewBag.intMedicationID = new SelectList(db.TMedications, "intMedicationID", "strMedicationName", visitMedication.intMedicationID); return(View(visitMedication)); } // Insert Visit Medication var id = db.TVisitMedications.Where(x => x.intVisitID == intVisitId && x.intMedicationID == intMedicationId).Select(z => z.intVisitMedicationID).FirstOrDefault(); if (id == 0) { TVisitMedication newVisitMedication = new TVisitMedication() { intVisitID = visitMedication.intVisitID, intMedicationID = intMedicationId, dtmDatePrescribed = visitMedication.dtmDatePrescribed, intQuantity = visitMedication.intQuantity, strMedicationNotes = visitMedication.strMedicationNotes }; db.TVisitMedications.Add(newVisitMedication); db.SaveChanges(); } else { int currentVisitMedicationQuantity = db.TVisitMedications.Where(x => x.intVisitMedicationID == id).Select(z => z.intQuantity).FirstOrDefault(); TVisitMedication updatedVisitMedication = new TVisitMedication() { intVisitMedicationID = id, intVisitID = visitMedication.intVisitID, intMedicationID = intMedicationId, dtmDatePrescribed = visitMedication.dtmDatePrescribed, intQuantity = currentVisitMedicationQuantity + visitMedication.intQuantity, strMedicationNotes = visitMedication.strMedicationNotes }; db.Entry(updatedVisitMedication).State = EntityState.Modified; db.SaveChanges(); }; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@intMedicationID", intMedicationId), new SqlParameter("@strMedicationName", medication.strMedicationName), new SqlParameter("@strMedicationDesc", medication.strMedicationDesc), new SqlParameter("@dblCost", medication.dblCost), new SqlParameter("@dblPrice", medication.dblPrice), new SqlParameter("@strNotes", medication.strNotes), new SqlParameter("@intQuantity", updatedQuantity), new SqlParameter("@intMethodID", medication.intMethodID), }; db.Database.ExecuteSqlCommand("uspUpdateMedication @intMedicationID, @strMedicationName, @strMedicationDesc,@dblCost, @dblPrice,@strNotes,@intQuantity, @intMethodID ", param); // Redirect to the visit medications page return(RedirectToAction("Index")); } ViewBag.Name = db.TPets.Where(x => x.intPetID == intPetId).Select(z => z.strPetName).FirstOrDefault(); ViewBag.intMedicationID = new SelectList(db.TMedications, "intMedicationID", "strMedicationName", visitMedication.intMedicationID); return(View(visitMedication)); }
public ActionResult EditMedication(TVisitMedication visitMedication) { int intPetId = (int)Session["intPetID"]; int intVisitId = (int)Session["intVisitId"]; if (ModelState.IsValid) { int oldQuantity = db.TVisitMedications.Where(x => x.intVisitMedicationID == visitMedication.intVisitMedicationID).Select(z => z.intQuantity).FirstOrDefault(); int medicationId = db.TVisitMedications.Where(x => x.intVisitMedicationID == visitMedication.intVisitMedicationID).Select(z => z.intMedicationID).FirstOrDefault(); TMedication medicationInfo = db.TMedications.Where(x => x.intMedicationID == medicationId).FirstOrDefault(); if (oldQuantity > visitMedication.intQuantity) { int medQuantity = oldQuantity - visitMedication.intQuantity; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@intMedicationID", medicationInfo.intMedicationID), new SqlParameter("@strMedicationName", medicationInfo.strMedicationName), new SqlParameter("@strMedicationDesc", medicationInfo.strMedicationDesc), new SqlParameter("@dblCost", medicationInfo.dblCost), new SqlParameter("@dblPrice", medicationInfo.dblPrice), new SqlParameter("@strNotes", medicationInfo.strNotes), new SqlParameter("@intQuantity", medicationInfo.intQuantity + medQuantity), new SqlParameter("@intMethodID", medicationInfo.intMethodID), }; db.Database.ExecuteSqlCommand("uspUpdateMedication @intMedicationID, @strMedicationName, @strMedicationDesc,@dblCost, @dblPrice,@strNotes,@intQuantity, @intMethodID ", param); db.uspUpdateVisitMedication(visitMedication.intVisitMedicationID, visitMedication.intQuantity, visitMedication.strMedicationNotes); //db.Database.ExecuteSqlCommand("uspUpdateVisitMedication @intVisitMedicationID, @intQuantity", visitMedication.intVisitMedicationID, visitMedication.intQuantity); } else if (medicationInfo.intQuantity >= (visitMedication.intQuantity - oldQuantity) && visitMedication.intQuantity > oldQuantity) { int subQuantity = visitMedication.intQuantity - oldQuantity; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@intMedicationID", medicationInfo.intMedicationID), new SqlParameter("@strMedicationName", medicationInfo.strMedicationName), new SqlParameter("@strMedicationDesc", medicationInfo.strMedicationDesc), new SqlParameter("@dblCost", medicationInfo.dblCost), new SqlParameter("@dblPrice", medicationInfo.dblPrice), new SqlParameter("@strNotes", medicationInfo.strNotes), new SqlParameter("@intQuantity", medicationInfo.intQuantity - subQuantity), new SqlParameter("@intMethodID", medicationInfo.intMethodID) }; db.Database.ExecuteSqlCommand("uspUpdateMedication @intMedicationID, @strMedicationName, @strMedicationDesc,@dblCost, @dblPrice,@strNotes,@intQuantity, @intMethodID ", param); db.uspUpdateVisitMedication(visitMedication.intVisitMedicationID, visitMedication.intQuantity, visitMedication.strMedicationNotes); //db.Database.ExecuteSqlCommand("uspUpdateVisitMedication @intVisitMedicationID, @intQuantity", visitMedication.intVisitMedicationID, visitMedication.intQuantity); } else { //TO DO: Need some error handling db.uspUpdateVisitMedication(visitMedication.intVisitMedicationID, oldQuantity, visitMedication.strMedicationNotes); //db.Database.ExecuteSqlCommand("uspUpdateVisitMedication @intVisitMedicationID, @intQuantity", visitMedication.intVisitMedicationID, oldQuantity); } return(RedirectToAction("Index")); } ViewBag.Name = db.TPets.Where(x => x.intPetID == intPetId).Select(z => z.strPetName).FirstOrDefault(); ViewBag.intMedicationID = new SelectList(db.TMedications, "intMedicationID", "strMedicationName", visitMedication.intMedicationID); return(View(visitMedication)); }