public void Save(LabTestDetailsViewModel obj) { //throw new NotImplementedException(); Context.SaveChanges(); Context.Entry(obj.LabTest).Reload(); }
public IActionResult Create(int?id) { if (id == null) { return(NotFound()); } var token = HttpContext.Session.GetString("biodata_details_token"); if (string.IsNullOrEmpty(token)) { return(RedirectToAction(nameof(Index), "Biodata")); } TblBiodata _Biodata = biodata.GetById(id); LabTestDetailsViewModel _labTest = new LabTestDetailsViewModel(_Biodata, methods, specimen); ViewData["Results"] = results; ViewData["Method"] = new SelectList(methods.GetAll(), "Id", "Methodname"); /* ViewData["Biodata"] = new SelectList(_context.TblBiodata, "Id", "Fullname"); * ViewData["Method"] = new SelectList(_context.TlkpTestMethods, "Id", "InsertBy");*/ return(View(_labTest)); }
public async Task <IActionResult> Edit(int id, LabTestDetailsViewModel test) { if (id != test.LabTest.Id) { return(NotFound()); } var errors = ModelState.Values; foreach (var e in errors) { if (e.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid) { ; } } if (ModelState.IsValid) { try { test.LabTest.UpdateBy = User.Identity.Name; tests.Update(test); /*_context.Update(tblLabTests); * await _context.SaveChangesAsync();*/ } catch (DbUpdateConcurrencyException) { if (!TblLabTestsExists(test.LabTest.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Results"] = results; ViewData["Method"] = new SelectList(methods.GetAll(), "Id", "Methodname"); TblBiodata _Biodata = biodata.GetById(test.BioData.Id); test.BioData = _Biodata; return(View(test)); }
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 async Task <IActionResult> Create(LabTestDetailsViewModel _labTest)//[Bind("Id,Biodata,Method,Interpretation,TestingDate,TestingTime,ReportingDate,ReportingTime,InsertTime,InsertBy,UpdateTime,UpdateBy")] TblLabTests tblLabTests) { //var errors = ModelState.Values; //foreach (var e in errors) //{ // if (e.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid) // ; //} if (ModelState.IsValid) { _labTest.LabTest.TblLabTestsIndicatorsValues = _labTest.Indicators; _labTest.LabTest.TblLabTestsSpecimen = _labTest.Specimen; _labTest.LabTest.InsertBy = _labTest.LabTest.UpdateBy = User.Identity.Name; tests.Create(_labTest); //_context.Add(tblLabTests); //await _context.SaveChangesAsync(); HttpContext.Session.SetString("biodata_details_token", ""); return(RedirectToAction(nameof(Index))); } ViewData["Results"] = results; ViewData["Method"] = new SelectList(methods.GetAll(), "Id", "Methodname", _labTest.LabTest.Method); /*ViewData["Biodata"] = new SelectList(_context.TblBiodata, "Id", "Fullname", tblLabTests.Biodata); * ViewData["Method"] = new SelectList(_context.TlkpTestMethods, "Id", "InsertBy", tblLabTests.Method);*/ TblBiodata _Biodata = biodata.GetById(_labTest.BioData.Id); _labTest.BioData = _Biodata; var _indicators = indicators.GetAll(); foreach (var i in _labTest.Indicators) { i.IndicatorName = _indicators.FirstOrDefault(x => x.Id == i.Indicator).IndicatorName; } //_labTest.Indicators = return(View(_labTest)); }
public void Create(LabTestDetailsViewModel obj) { //throw new NotImplementedException(); //LabTestDetailsViewModel tmp = new LabTestDetailsViewModel(obj); //not really needed TblLabTests test = obj.LabTest; if (test.Method == 0) { throw new Exception("Select Method."); } test.Approved = false; Context.TblLabTests.Add(test); obj.LabTest = test; Save(obj); }
public void Delete(int id, string username) { //throw new NotImplementedException(); LabTestDetailsViewModel t = GetById(id); if (t == null) { return; } var cmd = Context.Database.GetDbConnection().CreateCommand(); cmd.CommandText = "[dbo].[sp_delete_test] @testid, @username"; var param1 = cmd.CreateParameter(); param1.ParameterName = "@testid"; param1.Value = id; cmd.Parameters.Add(param1); var param2 = cmd.CreateParameter(); param2.ParameterName = "@username"; param2.Value = username; cmd.Parameters.Add(param2); try { Context.Database.GetDbConnection().Open(); // Run the sproc var reader = cmd.ExecuteReader(); } catch { } finally { Context.Database.GetDbConnection().Close(); } // Context.TblLabTests.Remove(t.LabTest); //Context.SaveChanges(); }