public ActionResult SeeMedReport() { string user = User.Identity.Name; //getting the current logged in center Center currentCenter = cg.GetCenter(user); List <CenterMedicineLinker> currentLinkers = cg.GetCenterMedicineLinker(currentCenter.Id); MedAmountDictionary med = mg.GetMedicineAmount(currentLinkers); return(View(med)); }
//returns a MedAmountDictionary class with the medicine name as key and quantity as value public MedAmountDictionary GetMedicineAmount(List <CenterMedicineLinker> currentLinkers) { MedAmountDictionary medAmount = new MedAmountDictionary(); connection = new SqlConnection(connectionString); foreach (CenterMedicineLinker linker in currentLinkers) { string query = "SELECT * FROM medicine WHERE id = @med_id"; SqlCommand command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@med_id", linker.MedicineId); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { try { medAmount.medicineAmount[reader["name"].ToString()] = medAmount.medicineAmount[reader["name"].ToString()] + linker.Qty; } catch (Exception) { medAmount.medicineAmount[reader["name"].ToString()] = linker.Qty; } } reader.Close(); connection.Close(); } return(medAmount); }