Example #1
0
 public bool Add(Drug model)
 {
     try
     {
         entities.Drugs.Add(model);
         entities.SaveChanges();
         return true;
     }
     catch (Exception x)
     {
         throw x;
     }
 }
 public JsonResult Save(Drug drug)
 {
     try
     {
         if (drug.BrandId > 0)
             new DrugData().Update(drug);
         else
             new DrugData().Add(drug);
     }
     catch (Exception x)
     {
     }
     return Json(drug, JsonRequestBehavior.AllowGet);
 }
Example #3
0
 public bool Update(Drug model)
 {
     try
     {
         Drug drug = entities.Drugs.Where(x => x.BrandId == model.BrandId).SingleOrDefault();
         if (drug != null)
         {
             entities.Entry(drug).CurrentValues.SetValues(model);
             entities.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception x)
     {
         throw x;
     }
 }
Example #4
0
        private void btnAddDrug_Click(object sender, EventArgs e)
        {
            string brandname = txtBrandName.Text.Trim();

            if (brandname == "")
            {
                MessageBox.Show("Enter Brand Name");
                return;
            }
            else
            {
                Drug drug = new Drug() { 
                    BrandName = brandname, 
                    Company = txtCompany.Text.Trim(),
                    DrugContent = txtContents.Text.Trim(),
                    Formulation = txtFormulation.Text.Trim(),
                    Instructions = txtInstructions.Text.Trim(),
                    CreatedOn = DateTime.Now 
                };
                bool result = new DrugData().Add(drug);
                if (result)
                {
                    txtBrandName.Text = "";
                    txtImagingName.Text = "";
                    txtCompany.Text = "";
                    txtContents.Text = "";
                    txtFormulation.Text = "";
                    txtInstructions.Text = "";
                    MessageBox.Show("Drug added successfully");
                }
                else
                {
                    MessageBox.Show("Cannot add drug : contact Admin");
                }
            }

        }