public VaultKeep AddVaultKeep([FromBody] AddVaultKeepModel addVaultKeep) { if (ModelState.IsValid) { VaultKeep vaultKeep = _db.AddVaultKeep(addVaultKeep); if (vaultKeep != null) { return(vaultKeep); } } return(null); }
public VaultKeep AddVaultKeep(AddVaultKeepModel addVaultKeep) { try { Guid g = Guid.NewGuid(); string id = g.ToString(); VaultKeep vaultKeep = new VaultKeep() { Id = id, VaultId = addVaultKeep.VaultId, KeepId = addVaultKeep.KeepId, userId = addVaultKeep.userId }; var success = _db.Execute(@" INSERT INTO vaultkeeps( id, vaultId, keepId, userId ) VALUES ( @Id, @VaultId, @KeepId, @userId )", vaultKeep); if (success < 1) { throw new Exception("VAULT KEEP ALREADY EXISTS"); } return(vaultKeep); } catch (MySqlException e) { Console.WriteLine("ERROR: " + e.Message); return(null); } }