public async Task <ActionResult <HospitalProfile[]> > GetAllProfiles() { var result = await _repository.GetAllProfiles(); if (result == null) { ModelState.AddErrorMessage("Unable to get all profiles"); return(BadRequest(ModelState)); } return(Ok(result)); }
public async Task <ActionResult <Patient[]> > GetAllPatientsAdmin() { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userPatientListAdmin = await _repository.GetAllPatientsAdmin(); if (userPatientListAdmin == null) { ModelState.AddErrorMessage("Unable to get data"); return(BadRequest(ModelState)); } return(Ok(userPatientListAdmin)); }
public async Task <ActionResult <Patient> > UpdatePatient(Patient updatedPatient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _repository.UpdatePatient(updatedPatient); if (result == null) { ModelState.AddErrorMessage("Unable to update patient"); return(BadRequest(ModelState)); } return(Ok(result)); }
public async Task <ActionResult> DeleteProfile(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool deleted = await _repository.DeleteProfile(id); if (!deleted) { ModelState.AddErrorMessage("Unable to delete profile"); return(BadRequest(ModelState)); } return(Ok()); }
public async Task <ActionResult <Patient> > CreatePatient(PatientVM newPatientVM) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newPatient = await _repository.CreatePatient(newPatientVM); if (newPatient == null) { ModelState.AddErrorMessage("Unable to create Patient"); return(BadRequest(ModelState)); } return(Ok(newPatient)); }
public async Task <ActionResult <Patient> > DeletePatientAdmin(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userDeleted = await _repository.DeletePatientAdmin(id); if (!userDeleted) { ModelState.AddErrorMessage("Unable to delete patient"); return(BadRequest(ModelState)); } return(Ok()); }
public async Task <ActionResult <HospitalProfile> > CreateProfile(HospitalProfileVM newProfileVm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdProfile = await _repository.CreateProfile(newProfileVm); if (createdProfile == null) { ModelState.AddErrorMessage("Unable to create profile"); return(BadRequest(ModelState)); } return(Ok(createdProfile)); }
public async Task <IActionResult> AddUser(RegisterUserVM userVm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _userManager.FindByEmailAsync(userVm.Email); if (user == null) { var applicationUser = new ApplicationUser(); applicationUser.Email = userVm.Email; applicationUser.UserName = userVm.UserName; var result = await _userManager.CreateAsync(applicationUser, "Test123"); //Todo: change to real password if (result.Succeeded) { user = await _userManager.FindByIdAsync(applicationUser.Id); if (userVm.AdminType == AdminTypeEnum.Global.ToString()) { if (await IsLoggedInUserGlobalAdmin()) { var roleResultGlobal = await _userManager.AddToRoleAsync(user, userVm.AdminType); if (!roleResultGlobal.Succeeded) { return(BadRequest($"Error adding {userVm.AdminType} admin role to user")); } } else { await _userManager.DeleteAsync(user); return(RedirectToAction("AccessDenied", "Authorization")); } } var roleResult = await _userManager.AddToRoleAsync(user, userVm.AdminType); if (!roleResult.Succeeded) { return(BadRequest("Error adding role to user")); } var claimResult = await _userManager.AddClaimsAsync(user, new List <Claim> { new Claim(JwtClaimTypes.Email, user.Email), new Claim("usertype", userVm.UserType), }); if (!claimResult.Succeeded) { return(BadRequest("Error adding usertype and section to user")); } //Todo: Confirmation mail } else { foreach (var error in result.Errors) { ModelState.AddErrorMessage(error.Description); } return(BadRequest(ModelState)); } } return(RedirectToAction("Index")); }