public void Update(LabTestDetailsViewModel obj) { //throw new NotImplementedException(); //LabTestDetailsViewModel test = new LabTestDetailsViewModel(obj);//GetById(obj.LabTest.Id); TblLabTests test = Context.TblLabTests .Include(t => t.TblLabTestsIndicatorsValues) .Include(t => t.TblLabTestsSpecimen) .FirstOrDefault(t => t.Id == obj.LabTest.Id); if (test != null) { test.Interpretation = obj.LabTest.Interpretation; test.TestingDate = obj.LabTest.TestingDate; test.TestingTime = obj.LabTest.TestingTime; test.ReportingDate = obj.LabTest.ReportingDate; test.ReportingTime = obj.LabTest.ReportingTime; test.UpdateBy = obj.LabTest.UpdateBy; test.Approved = obj.LabTest.Approved; if (test.Approved == null) { test.Approved = false; } //test.Update(obj); //do i really need it. for (int k = 0; k < test.TblLabTestsIndicatorsValues.Count; k++) { TblLabTestsIndicatorsValues i = test.TblLabTestsIndicatorsValues.ElementAt(k); i.IndicatorName = obj.Indicators.ElementAt(k).IndicatorName; i.IndicatorValue = obj.Indicators.ElementAt(k).IndicatorValue; } for (int k = 0; k < test.TblLabTestsSpecimen.Count; k++) { TblLabTestsSpecimen i = test.TblLabTestsSpecimen.ElementAt(k); i.SpecimenName = obj.Specimen.ElementAt(k).SpecimenName; i.Checked = obj.Specimen.ElementAt(k).Checked; i.SpecimenOther = obj.Specimen.ElementAt(k).SpecimenOther; } obj.LabTest = test; Save(obj); } else if (test != null && test.Method != obj.LabTest.Method) { throw new Exception("Method already set. Cannot be changed."); } }
public LabTestDetailsViewModel(TblBiodata _BioData, IMethodRepos _methods, ISpecimenRepos _specimen) //main to create { //perfect BioData = _BioData; //Method = _method; methods = _methods; //Indicators = new List<TblLabTestsIndicatorsValues>(); Specimen = new List <TblLabTestsSpecimen>(); LabTest = new TblLabTests(); LabTest.Approved = false; LabTest.Biodata = _BioData.Id; //LabTest.Method = _method.Id; /*foreach(var i in _method.TlkpTestIndicators) * { * TblLabTestsIndicatorsValues v = new TblLabTestsIndicatorsValues(); * v.Indicator = i.Id; * v.Method = _method.Id; * LabTest.TblLabTestsIndicatorsValues.Add(v); * * Indicators.Add(v); * * * }*/ foreach (var t in _specimen.GetAll()) { TblLabTestsSpecimen s = new TblLabTestsSpecimen(); s.Specimen = t.Id; s.SpecimenName = t.Type; LabTest.TblLabTestsSpecimen.Add(s); Specimen.Add(s); } }