public async Task <IActionResult> Upsert(int?id) { ViewBag.residentId = TempData["id"]; IEnumerable <Resident> residentList = await _reRepo.GetAllAsync(SD.ResidentAPIPath, HttpContext.Session.GetString("JWToken")); MedicationViewModel objVM = new MedicationViewModel() { ResidentList = residentList.Select(i => new SelectListItem() { Text = i.FirstName + " " + i.LastName, Value = i.Id.ToString() }), Medication = new Medication() }; if (id == null) { // This will be true for Insert / Create return(View(objVM)); } // Flow will come here for Update objVM.Medication = await _meRepo.GetAsync(SD.MedicationAPIPath, id.GetValueOrDefault(), HttpContext.Session.GetString("JWToken")); if (objVM.Medication == null) { return(NotFound()); } return(View(objVM)); }
public async Task <IActionResult> GetAll(ResidentQuery queryFilter) { var residents = await _residentRepository.GetAllAsync(queryFilter); var result = _mapper.Map <IEnumerable <ResidentViewModel> >(residents); return(Ok(result)); }
public async Task <ActionResult> Details() { var username = User.FindFirstValue(ClaimTypes.Name); var residents = await _reRepo.GetAllAsync(SD.ResidentAPIPath, HttpContext.Session.GetString("JWToken")); foreach (var item in residents) { if (item.PrimaryContact.Email.Equals(username)) { var data = await _reRepo.GetAsync(SD.ResidentAPIPath, item.Id, HttpContext.Session.GetString("JWToken")); data.DateOfBirthString = data.DateOfBirth.ToString().Split(" ")[0]; return(View(data)); } } return(View()); }
public async Task <IActionResult> UpsertResidentAccount(int?id) { User user = await _accRepo.GetAsync(SD.AccountAPIPath, id.GetValueOrDefault(), HttpContext.Session.GetString("JWToken")); IEnumerable <Resident> residents = await _reRepo.GetAllAsync(SD.ResidentAPIPath, HttpContext.Session.GetString("JWToken")); Resident resident = null; UpdateUserViewModel uuvm = null; foreach (var item in residents) { if (item.PrimaryContact.Email.Equals(user.Username)) { resident = item; } } if (user != null) { if (resident != null) { uuvm = new UpdateUserViewModel() { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Username = user.Username, Role = user.Role, RolesEnum = (Roles)Enum.Parse(typeof(Roles), user.Role), ResidentId = resident.Id, Resident = resident }; } else { uuvm = new UpdateUserViewModel() { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Username = user.Username, Role = user.Role, RolesEnum = (Roles)Enum.Parse(typeof(Roles), user.Role), Resident = new Resident() }; } IEnumerable <Resident> residentList = await _reRepo.GetAllAsync(SD.ResidentAPIPath, HttpContext.Session.GetString("JWToken")); AccountViewModel objVM = new AccountViewModel() { ResidentList = residentList.Select(i => new SelectListItem() { Text = i.FirstName + " " + i.LastName, Value = i.Id.ToString() }), User = uuvm }; // This will be true for Insert / Create return(View(objVM)); } return(View()); }