public void Post([FromBody] DextroseConcentration dexCon) { if (ModelState.IsValid) { _dbContext.DextroseConcentrations.Add(dexCon); _dbContext.SaveChanges(); } }
public ActionResult Index() { int siteId = DbUtils.GetSiteidIdForUser(User.Identity.Name); var studyList = DbUtils.GetRandomizedStudiesForSite(siteId); studyList.Insert(0, new IDandStudyID { ID = 0, StudyID = "Select Study" }); ViewBag.StudyList = new SelectList(studyList, "ID", "StudyID"); ViewBag.StudyDay = ""; var dc1 = CalorieCalc.GetDextroseConcentrations(); var dc = new DextroseConcentration { ID = 0, Concentration = " Dextrose % ", Kcal_ml = 0 }; dc1.Insert(0, dc); ViewBag.DexCons1 = new SelectList(dc1, "Kcal_ml", "Concentration"); ViewBag.DexCons2 = new SelectList(dc1, "Kcal_ml", "Concentration"); ViewBag.DexCons3 = new SelectList(dc1, "Kcal_ml", "Concentration"); ViewBag.DexCons4 = new SelectList(dc1, "Kcal_ml", "Concentration"); List <IDandName> sl = DbUtils.GetLookupItems("FormulaList"); if (sl.Count == 0) { throw new Exception("There was an error retrieving the FormulaList from the database"); } sl.Insert(0, new IDandName { ID = 0, Name = "Select" }); ViewBag.FormulaList = new SelectList(sl, "ID", "Name"); List <IDandName> sl2 = DbUtils.GetLookupItems("AdditiveList"); if (sl2.Count == 0) { throw new Exception("There was an error retrieving the Additives from the database"); } sl2.Insert(0, new IDandName { ID = 0, Name = "Select" }); ViewBag.AdditiveList = new SelectList(sl2, "ID", "Name"); List <IDandName> sl3 = DbUtils.GetLookupItems("Units"); if (sl3.Count == 0) { throw new Exception("There was an error retrieving the Units from the database"); } sl3.Insert(0, new IDandName { ID = 0, Name = "Select" }); ViewBag.Units = new SelectList(sl3, "ID", "Name"); return(View()); }
public ActionResult Edit(CalStudyInfo csi) { //DateTime date = DateTime.Parse( csi.CalcDate); ViewBag.Mode = "Edit"; ViewBag.Weight = csi.Weight.ToString(); ViewBag.CalcDate = csi.CalcDate; ViewBag.CalStudyID = csi.Id; ViewBag.Hours = csi.Hours; int studyDay = CalorieCalc.GetStudyDay(csi.StudyId, DateTime.Parse(csi.CalcDate)); ViewBag.StudyDay = studyDay.ToString(); int siteId = DbUtils.GetSiteidIdForUser(User.Identity.Name); //todo remove for production //if (siteId == 0) // siteId = 1; var studyList = DbUtils.GetRandomizedStudiesForSite(siteId); studyList.Insert(0, new IDandStudyID { ID = 0, StudyID = "Select Study" }); ViewBag.StudyList = new SelectList(studyList, "ID", "StudyID", csi.StudyId); var dc1 = CalorieCalc.GetDextroseConcentrations(); var dc = new DextroseConcentration { ID = 0, Concentration = " Dextrose % ", Kcal_ml = 0 }; dc1.Insert(0, dc); ViewBag.DexCons1 = new SelectList(dc1, "Kcal_ml", "Concentration"); ViewBag.DexCons2 = new SelectList(dc1, "Kcal_ml", "Concentration"); ViewBag.DexCons3 = new SelectList(dc1, "Kcal_ml", "Concentration"); ViewBag.DexCons4 = new SelectList(dc1, "Kcal_ml", "Concentration"); List <IDandName> sl = DbUtils.GetLookupItems("FormulaList"); if (sl.Count == 0) { throw new Exception("There was an error retrieving the FormulaList from the database"); } sl.Insert(0, new IDandName { ID = 0, Name = "Select" }); ViewBag.FormulaList = new SelectList(sl, "ID", "Name"); List <IDandName> sl2 = DbUtils.GetLookupItems("AdditiveList"); if (sl2.Count == 0) { throw new Exception("There was an error retrieving the Additives from the database"); } sl2.Insert(0, new IDandName { ID = 0, Name = "Select" }); ViewBag.AdditiveList = new SelectList(sl2, "ID", "Name"); List <IDandName> sl3 = DbUtils.GetLookupItems("Units"); if (sl3.Count == 0) { throw new Exception("There was an error retrieving the Units from the database"); } sl3.Insert(0, new IDandName { ID = 0, Name = "Select" }); ViewBag.Units = new SelectList(sl3, "ID", "Name"); return(View("Index")); }