Esempio n. 1
0
        public void UpdateMedication(int Id)
        {
            using (var db = new DiabetesRegistryEntities1())
            {
                RegistrationMedication med = db.RegistrationMedications.Find(Id);
                if (med == null)
                {
                    ModelState.AddModelError("Error", String.Format("Item with id {0} was not found", Id));
                    return;
                }

                TryUpdateModel(med);

                if (ModelState.IsValid)
                {
                    try
                    {
                        db.SaveChanges();
                        lsvMedication.EditIndex = -1;
                        ErrorLabel.Text         = String.Empty;
                    }
                    catch (Exception exp)
                    {
                        ErrorLabel.Text = exp.Message;
                    }
                }
            }
        }
Esempio n. 2
0
        public void SaveMedication()
        {
            ClearErrorLabels();
            using (var db = new DiabetesRegistryEntities1())
            {
                var med = new RegistrationMedication();
                //todo add code for getting the item added

                TryUpdateModel(med);
                med.RegistrationType = 1; //1 for child 2 for adult
                med.RegistrationId   = int.Parse(recordId.Value);

                if (ModelState.IsValid)
                {
                    try
                    {
                        db.RegistrationMedications.Add(med);
                        //db.SaveChanges(); NOT yet since we don't have the ID of the record
                        ErrorLabel.Text = String.Empty;
                    }
                    catch (Exception exp)
                    {
                        ErrorLabel.Text = exp.Message;
                    }
                }
                else
                {
                    //TODO add code for showing model errors
                    lblErrorsSection5.Text = "Section contains errors";
                }
            }
        }