Example #1
0
        protected void btnAddLabTest_Click(object sender, EventArgs e)
        {
            if (ddlLabTest.Items.Count == 0)
            {
                SetActive("tab2");  return;
            }
            ;
            if (ddlLabTest.SelectedValue == "0")
            {
                SetActive("tab2"); return;
            }
            ;

            // Save lab test
            var labtest = GetLabTest(Convert.ToInt32(ddlLabTest.SelectedValue));

            var conlab = new ConditionLabTest
            {
                Condition = _condition,
                LabTest   = labtest
            };

            UnitOfWork.Repository <ConditionLabTest>().Save(conlab);
            UnitOfWork.Complete();

            RenderGrids();
            SetActive("tab2");
        }
Example #2
0
        /// <summary>
        ///  Handle the updating of lab tests for an existing condition
        /// </summary>
        /// <param name="conditionForUpdate">The payload containing the list of lab tests</param>
        /// <param name="conditionFromRepo">The condition entity that is being updated</param>
        /// <returns></returns>
        private void AddOrUpdateConditionLabTests(ConditionForUpdateDto conditionForUpdate, Condition conditionFromRepo)
        {
            // Determine what has been removed
            ArrayList deleteCollection = new ArrayList();

            foreach (var conditionLabTest in conditionFromRepo.ConditionLabTests)
            {
                if (!conditionForUpdate.ConditionLabTests.Contains(conditionLabTest.LabTest.Id))
                {
                    deleteCollection.Add(conditionLabTest);
                }
            }

            // Process deletes
            foreach (var conditionLabTest in deleteCollection)
            {
                _conditionLabTestRepository.Delete(conditionLabTest);
            }

            // Determine what needs to be added
            foreach (var labTestId in conditionForUpdate.ConditionLabTests)
            {
                if (!conditionFromRepo.ConditionLabTests.Any(c => c.LabTest.Id == labTestId))
                {
                    var newConditionLabTest = new ConditionLabTest()
                    {
                        Condition = conditionFromRepo, LabTest = _labTestRepository.Get(f => f.Id == labTestId)
                    };
                    _conditionLabTestRepository.Save(newConditionLabTest);
                }
            }
        }