public Vault GetVaultById(int id, string userId) { Vault selectedVault = _repo.GetOne(id); if (selectedVault.CreatorId != userId && selectedVault.isPrivate == true) { throw new Exception("Private Vault"); } return(_repo.GetVaultById(id)); }
[HttpGet("{id}")] //NOTE "Can Get Vault By Id" public ActionResult <Vault> Get(int id) { try { return(Ok(_repo.GetVaultById(id))); } catch (Exception e) { return(BadRequest(e.Message)); } }
internal Vault GetVaultById(int id, string userId) { Vault foundVault = _repo.GetVaultById(id); if (foundVault == null) { throw new Exception("This vault does not exist."); } if (foundVault.UserId != userId) { throw new Exception("This vault does not belong to you."); } return(foundVault); }
public IEnumerable <Vault> GetVault() { string uid = HttpContext.User.Identity.Name; return(_repo.GetVaultById(uid)); }