public async Task <IActionResult> Upsert(int?id) { IEnumerable <PatientDetail> pdList = await _pdRepo.GetAllAsync(SD.PatientDetailsAPIPath + "all/", HttpContext.Session.GetString("JWToken")); TempVM objVM = new TempVM() { PatientList = pdList.Select(i => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem { Text = i.Name + i.Lastname, Value = i.UserId.ToString() }), Temp = new Temp() }; if (id == null) { // for Insert/Create return(View(objVM)); } // For Update objVM.Temp = await _tRepo.GetAsync(SD.TemperaturesLogEntryAPIPath, id.GetValueOrDefault(), HttpContext.Session.GetString("JWToken")); if (objVM.Temp == null) { return(NotFound()); } return(View(objVM)); }
public async Task <IActionResult> Upsert(TempVM obj) { if (ModelState.IsValid) { if (obj.Temp.Id == 0) { await _tRepo.CreateAsync(SD.TemperaturesLogEntryAPIPath, obj.Temp, HttpContext.Session.GetString("JWToken")); } //else //{ // await _pdRepo.UpdateAsync(SD.PatientDetailsAPIPath + obj.UserId, obj); //} return(RedirectToAction(nameof(Index))); } else { return(View(obj)); } }