public async Task <HttpStatusCodeResult> EditAccess(EditAccessViewModel model) { try { await _associationService.EditRolesAsync(model.PageAssociationId, model.SelectedRoleList); return(new HttpStatusCodeResult(HttpStatusCode.NoContent)); } catch (Exception) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public async Task <ActionResult> EditAccess(int pageAssociationId) { var pageAssociation = await _associationService.GetAsync(pageAssociationId); var model = new EditAccessViewModel { PageAssociationId = pageAssociationId, RoleList = await _roleService.GetAsync(), SelectedRoleList = pageAssociation.PageAssociationRoles.Select(x => x.Role.RoleName).ToList() }; return(View("_EditAccess", model)); }
public IActionResult EditAccess(string?transID) { if (HttpContext.Session.GetString(Globals.currentPSPubK) == null || HttpContext.Session.GetString(Globals.currentPAPubK) == null) { return(RedirectToAction("Login")); } else { ViewBag.UserName = HttpContext.Session.GetString(Globals.currentUserName); ViewBag.UserID = HttpContext.Session.GetString(Globals.currentUserID); var viewModel = new EditAccessViewModel(); if (transID != null && transID != "") { var result = _bigChainDbService.GetMetaDataAndAssetFromTransactionId <string, object>(transID); viewModel.reportType = result.data.Type; } return(View(viewModel)); } }
public JsonResult RevokeAccessFromUser(EditAccessViewModel editAccessViewModel) { if (editAccessViewModel.UserType == null || editAccessViewModel.UserType == "") { return(Json(new { message = "Please select a user type." })); } // Searches for a patient with the specified PHN AssetType type = editAccessViewModel.UserType == "Doctor" ? AssetType.Doctor : editAccessViewModel.UserType == "Pharmacist" ? AssetType.Pharmacist : AssetType.MLT; Assets <UserCredAssetData> userAsset = _bigChainDbService.GetUserAssetFromTypeID(type, editAccessViewModel.UserID); if (userAsset == null) { return(Json(new { message = ("We could not find a " + editAccessViewModel.UserType + " with ID: " + editAccessViewModel.UserID) })); } string patientSignPublicKey = HttpContext.Session.GetString(Globals.currentPSPubK); string patientSignPrivateKey = HttpContext.Session.GetString(Globals.currentPSPriK); string doctorSignPublicKey = userAsset.data.Data.SignPublicKey; string userName = userAsset.data.Data.FirstName + " " + userAsset.data.Data.LastName; if (editAccessViewModel.TransID != null && editAccessViewModel.TransID != "") { var result = _bigChainDbService.GetMetaDataAndAssetFromTransactionId <string, object>(editAccessViewModel.TransID); MetaDataSaved <object> metadata = result.metadata; if (metadata.AccessList.Keys.Contains(doctorSignPublicKey)) { metadata.AccessList.Remove(doctorSignPublicKey); var newTransID = _bigChainDbService.SendTransferTransactionToDataBase(result.id, metadata, patientSignPrivateKey, patientSignPublicKey, result.transID); return(Json(new { message = (userName + " (" + editAccessViewModel.UserID + ") was removed from the record."), newtransid = newTransID })); } else { return(Json(new { message = (userName + " (" + editAccessViewModel.UserID + ") was already removed from the record.") })); } } // Choose the types of records we want to get List <AssetType> typeList = new List <AssetType>(); if (type == AssetType.Doctor) { typeList.AddRange(new List <AssetType> { AssetType.DoctorNote, AssetType.Prescription, AssetType.TestRequisition }); } else if (type == AssetType.Pharmacist) { typeList.AddRange(new List <AssetType> { AssetType.Prescription }); } else { typeList.AddRange(new List <AssetType> { AssetType.TestRequisition }); } var recordList = _bigChainDbService.GetAllTypeRecordsFromPPublicKey <string> (typeList.ToArray(), patientSignPublicKey); int counter = 0; foreach (var record in recordList) { MetaDataSaved <object> metadata = record.metadata; if (metadata.AccessList.Keys.Contains(doctorSignPublicKey)) { metadata.AccessList.Remove(doctorSignPublicKey); _bigChainDbService.SendTransferTransactionToDataBase(record.id, metadata, patientSignPrivateKey, patientSignPublicKey, record.transID); counter++; } } return(Json(new { message = (userName + " (" + editAccessViewModel.UserID + ") was removed from " + counter.ToString() + " records.") })); }