public void addToCart(UserModel user, DrugModel drug, int quantity) { updateQuantity(drug.ProductCode, quantity); drug.Quantity = quantity; double total = quantity * drug.Price; var doc = returnCart(user); if (doc == null) { doc = new CartModel(); //If cart doesnt exist, create new } var drugForChange = doc.DrugList.Find(d => d.ProductCode == drug.ProductCode); if (drugForChange == null) { doc.DrugList.Add(drug); doc.Quantity += quantity; } else { doc.Quantity += quantity; drugForChange.Quantity += quantity; } doc.Total += total; db.UpsertDocument("Carts", doc.Id, doc); }
public FormInformation(UserModel u, DrugModel d) { InitializeComponent(); drug = d; user = u; label1.Text = drug.Name; tbInfo.Text = drug.formatString(); }
private void btnConfirm_Click(object sender, EventArgs e) { DrugModel drug = new DrugModel(); for (int i = 0; i < dgvDrugList.RowCount - 1; i++) { if (i < listOfDrugs.Count) { drug.Id = listOfDrugs[i].Id; } else { drug.Id = new Guid(); } drug.ProductCode = Convert.ToInt32(dgvDrugList.Rows[i].Cells[0].Value); drug.Name = dgvDrugList.Rows[i].Cells[1].Value.ToString(); drug.Manufacturer = dgvDrugList.Rows[i].Cells[2].Value.ToString(); drug.Type = dgvDrugList.Rows[i].Cells[3].Value.ToString(); drug.Quantity = Convert.ToInt32(dgvDrugList.Rows[i].Cells[4].Value); drug.Price = Convert.ToInt32(dgvDrugList.Rows[i].Cells[5].Value); InstructionModel instruction = new InstructionModel(); instruction.Dose = dgvDrugList.Rows[i].Cells[6].Value.ToString(); string[] symptoms = dgvDrugList.Rows[i].Cells[7].Value.ToString().Split(' '); instruction.Symptoms = symptoms; string[] sideEffects = dgvDrugList.Rows[i].Cells[8].Value.ToString().Split(' '); instruction.SideEffects = sideEffects; instruction.Warning = dgvDrugList.Rows[i].Cells[9].Value.ToString(); instruction.Usage = dgvDrugList.Rows[i].Cells[10].Value.ToString(); drug.Instruction = instruction; FarmacyManager.Instance.upsertDrug(drug); this.Close(); } }
private void btnDelete_Click(object sender, EventArgs e) { DrugModel drug = new DrugModel(); var selectedRow = dgvDrugList.SelectedRows; for (int i = 0; i < selectedRow.Count; i++) { if (selectedRow[i].Index < listOfDrugs.Count) { drug.Id = listOfDrugs[selectedRow[i].Index].Id; drug.Name = selectedRow[i].Cells[1].Value.ToString(); drug.Manufacturer = selectedRow[i].Cells[2].Value.ToString(); drug.Type = selectedRow[i].Cells[3].Value.ToString(); drug.Quantity = Convert.ToInt32(selectedRow[i].Cells[4].Value); drug.Price = Convert.ToInt32(selectedRow[i].Cells[5].Value); InstructionModel instruction = new InstructionModel(); instruction.Dose = selectedRow[i].Cells[6].Value.ToString(); string[] symptoms = selectedRow[i].Cells[7].Value.ToString().Split(' '); instruction.Symptoms = symptoms; string[] sideEffects = selectedRow[i].Cells[8].Value.ToString().Split(' '); instruction.SideEffects = sideEffects; instruction.Warning = selectedRow[i].Cells[9].Value.ToString(); instruction.Usage = selectedRow[i].Cells[10].Value.ToString(); drug.Instruction = instruction; FarmacyManager.Instance.deleteDrug(drug); dgvDrugList.Rows.Clear(); fillList(); } } }
public void deleteDrug(DrugModel drug) { db.DeleteDocument <DrugModel>("Drugs", drug.Id); }
public void upsertDrug(DrugModel drug) { db.UpsertDocument <DrugModel>("Drugs", drug.Id, drug); }