internal bool hasRelationship(DTOVaultedKeep vaultedKeep) { string sql = "SELECT* FROM vaultKeeps WHERE keepId = @keepId AND vaultId = @vaultId"; var found = _db.QueryFirstOrDefault <DTOVaultedKeep>(sql, vaultedKeep); return(found != null); }
internal DTOVaultedKeep Create(DTOVaultedKeep DTOVK) { if (_repo.hasRelationship(DTOVK)) { throw new Exception("you already have that keep in this vault"); } return(_repo.Create(DTOVK)); }
public DTOVaultedKeep Get(int Id) { DTOVaultedKeep found = _repo.GetById(Id); if (found == null) { throw new Exception("Keep cannot be placed in vault"); } return(found); }
public ActionResult <DTOVaultedKeep> Post([FromBody] DTOVaultedKeep newDTOVK) { try { newDTOVK.UserId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; return(Ok(_vks.Create(newDTOVK))); } catch (Exception e) { return(BadRequest(e.Message)); } }
internal DTOVaultedKeep Create(DTOVaultedKeep vaultedKeep) { string sql = @" INSERT INTO vaultKeeps (vaultId, keepId, userId) VALUES (@VaultId, @keepId, @userId); SELECT LAST_INSERT_ID(); "; vaultedKeep.KeepId = _db.ExecuteScalar <int>(sql, vaultedKeep); return(vaultedKeep); }